1.0.15 • Published 10 months ago

@codeperate/entity-schema-to-json-schema v1.0.15

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

Here is a basic

README.md

for your project:

# JSON Schema Builder

A TypeScript library for building and manipulating JSON schemas.

## Installation

To install the library, run:

```bash
npm install @codeperate/json-schema-builder
```

Usage

Here is an example of how to use the schemaBuilder:

import { schemaBuilder } from '@codeperate/json-schema-builder';

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'integer' },
    email: { type: 'string' },
    address: {
      type: 'object',
      properties: {
        street: { type: 'string' },
        city: { type: 'string' },
      },
      required: ['street', 'city'],
    },
  },
  required: ['name', 'age', 'email', 'address'],
};

const updatedSchema = schemaBuilder(schema).pick(['name', 'email']).schema;
console.log(updatedSchema);

API

schemaBuilder(schema: JSONSchema)

Creates a new SchemaBuilder instance.

Methods

  • pick(props: (keyof T)[] | RegExp, options?: { removeRequired?: boolean }): SchemaBuilder<T>
  • omit(props: (keyof T)[] | RegExp, options?: { removeRequired?: boolean }): SchemaBuilder<T>
  • set<K extends keyof JSONSchema>(key: K, value: JSONSchema[K] | ((curVal: JSONSchema[K]) => JSONSchema[K])): SchemaBuilder<T>
  • setProps<K extends keyof T, V extends JSONSchema>(key: K, value: V | ((curVal: JSONSchema) => V)): SchemaBuilder<Omit<T, K> & { [key in K]: FromSchema<V> }>
  • setPropsRaw<K extends keyof T, V = any>(key: K, value: JSONSchema | ((curVal: JSONSchema) => JSONSchema)): SchemaBuilder<Omit<T, K> & { [key in K]: V }>
  • optional(props: (keyof T)[]): SchemaBuilder<T>
  • required(props: (keyof T)[]): SchemaBuilder<T>
  • clone(): SchemaBuilder<T>
  • toArray(): SchemaBuilder<Array<T>>
  • noRef(options?: { removeRequired?: boolean }): SchemaBuilder<T>

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago