Comparing version 0.0.3 to 0.0.4
export * from './types'; | ||
export { extendSchema, mergeSchemas, createSchema } from './schema-builder'; | ||
export { extendSchema, mergeSchemas, createSchema, createCompoundSchema } from './schema-builder'; | ||
export * from './schema-comparator'; |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSchema = exports.mergeSchemas = exports.extendSchema = void 0; | ||
exports.createCompoundSchema = exports.createSchema = exports.mergeSchemas = exports.extendSchema = void 0; | ||
__exportStar(require("./types"), exports); | ||
@@ -20,3 +20,4 @@ var schema_builder_1 = require("./schema-builder"); | ||
Object.defineProperty(exports, "createSchema", { enumerable: true, get: function () { return schema_builder_1.createSchema; } }); | ||
Object.defineProperty(exports, "createCompoundSchema", { enumerable: true, get: function () { return schema_builder_1.createCompoundSchema; } }); | ||
__exportStar(require("./schema-comparator"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -8,1 +8,2 @@ import { Schema, SchemaGenOptions } from './types'; | ||
export declare function extendSchema(schema: Schema, value: any, options?: SchemaGenOptions): Schema; | ||
export declare function createCompoundSchema(values: any[], options?: SchemaGenOptions): Schema; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extendSchema = exports.mergeSchemas = exports.createSchema = exports.wrapAnyOfSchema = exports.unwrapSchemas = exports.unwrapSchema = void 0; | ||
exports.createCompoundSchema = exports.extendSchema = exports.mergeSchemas = exports.createSchema = exports.wrapAnyOfSchema = exports.unwrapSchemas = exports.unwrapSchema = void 0; | ||
const types_1 = require("./types"); | ||
@@ -241,2 +241,7 @@ function createSchemaFor(value, options) { | ||
exports.extendSchema = extendSchema; | ||
function createCompoundSchema(values, options) { | ||
const schemas = values.map(value => createSchema(value, options)); | ||
return mergeSchemas(schemas, options); | ||
} | ||
exports.createCompoundSchema = createCompoundSchema; | ||
//# sourceMappingURL=schema-builder.js.map |
{ | ||
"name": "genson-js", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.js", |
# genson-js | ||
![Build](https://github.com/aspecto-io/genson-js/workflows/Build/badge.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![TypeScript](https://badgen.net/npm/types/env-var)](http://www.typescriptlang.org/) [![NPM version](https://img.shields.io/npm/v/genson-js.svg)](https://www.npmjs.com/package/genson-js) | ||
**genson-js** is a user-friendly **JSON Schema** generator built in TypeScript/JavaScript. | ||
@@ -12,3 +14,3 @@ | ||
#### Creating schemas | ||
### Creating schemas | ||
@@ -25,27 +27,30 @@ To infer a schema from existing object: | ||
}); | ||
``` | ||
// will create the following schema: | ||
// { | ||
// type: "object", | ||
// properties: { | ||
// userName: { | ||
// type: "string", | ||
// }, | ||
// languages: { | ||
// type: "array", | ||
// items: { | ||
// type: "string", | ||
// }, | ||
// }, | ||
// age: { | ||
// type: "integer", | ||
// }, | ||
// }, | ||
// required: ["userName", "languages", "age"], | ||
// }; | ||
The following schema will be created: | ||
```json | ||
{ | ||
type: "object", | ||
properties: { | ||
userName: { | ||
type: "string", | ||
}, | ||
languages: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
}, | ||
}, | ||
age: { | ||
type: "integer", | ||
}, | ||
}, | ||
required: ["userName", "languages", "age"], | ||
}; | ||
``` | ||
#### Merging schemas | ||
### Merging schemas | ||
You can merge 2 schemas, so that merged schema would be kind of a superset of the schemas that it was built from: | ||
You can merge 2 or more schemas, so that merged schema would be kind of a superset of the schemas that it was built from: | ||
@@ -61,4 +66,22 @@ ```ts | ||
#### Exending schemas | ||
### Create compound schema | ||
Shorthand for createSchema + mergeSchemas. | ||
Can take multiple inputs and create one compound schema: | ||
```ts | ||
import { createCompoundSchema } from 'genson-js'; | ||
const schema = createCompoundSchema([{ age: 19, name: 'John' }, { age: 23, admin: true }, { age: 35 }]); | ||
// Will create the following schema: | ||
// { | ||
// type: 'object', | ||
// properties: { admin: { type: 'boolean' }, age: { type: 'integer' }, name: { type: 'string' } }, | ||
// required: ['age'] | ||
// } | ||
``` | ||
### Exending schemas | ||
You can extend existing schema to match some value: | ||
@@ -69,3 +92,3 @@ | ||
const extended = extendSchema({ type: ValueType.Number }, 'string'); | ||
const extended = extendSchema({ type: ValueType.Number }, 'some string'); | ||
@@ -76,5 +99,5 @@ // will create extended schema like this: | ||
#### Comparing schemas | ||
### Comparing schemas | ||
You can extend compare 2 schemas for equality like this: | ||
You can compare 2 schemas for equality like this: | ||
@@ -88,8 +111,6 @@ ```ts | ||
#### Subset | ||
### Subset | ||
You can also check if one schema is a subset of another one like so: | ||
You can extend compare 2 schemas for equality like this: | ||
```ts | ||
@@ -104,3 +125,3 @@ import { isSubset } from 'genson-js'; | ||
``` | ||
You can find more example in the unit tests. | ||
<hr/> | ||
You can find more examples in the unit tests. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30736
380
121
1