schematized
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -87,10 +87,8 @@ "use strict"; | ||
// Incorporate typeless strategy if it exists | ||
// if ( | ||
// this.activeStrategies && | ||
// this.activeStrategies[this.activeStrategies.length - 1] instanceof | ||
// Typeless | ||
// ) { | ||
// const typeless = this.activeStrategies.pop(); | ||
// activeStrategy.addSchema(typeless.toSchema()); | ||
// } | ||
if (this.activeStrategies && | ||
this.activeStrategies[this.activeStrategies.length - 1] instanceof | ||
strategies_1.Typeless) { | ||
const typeless = this.activeStrategies.pop(); | ||
activeStrategy.addSchema(typeless.toSchema()); | ||
} | ||
this.activeStrategies.push(activeStrategy); | ||
@@ -101,10 +99,10 @@ return activeStrategy; | ||
// No match found, if typeless add to first strategy | ||
// const typelessInstance = new Typeless(schemaNode); | ||
// if (kind === 'schema' && typelessInstance.matchSchema(schemaOrObject)) { | ||
// if (this.activeStrategies.length === 0) { | ||
// this.activeStrategies.push(typelessInstance); | ||
// } | ||
// const activeStrategy = this.activeStrategies[0]; | ||
// return activeStrategy; | ||
// } | ||
const typelessInstance = new strategies_1.Typeless(schemaNode); | ||
if (kind === 'schema' && typelessInstance.matchSchema(schemaOrObject)) { | ||
if (this.activeStrategies.length === 0) { | ||
this.activeStrategies.push(typelessInstance); | ||
} | ||
const activeStrategy = this.activeStrategies[0]; | ||
return activeStrategy; | ||
} | ||
// If no match found, raise an error | ||
@@ -111,0 +109,0 @@ throw new Error(`Could not find matching schema type for ${kind}: ${JSON.stringify(schemaOrObject, null, 2)}`); |
import { Boolean } from './scalar'; | ||
export declare const BASIC_SCHEMA_STRATEGIES: (typeof Boolean)[]; | ||
export { Typeless } from './scalar'; |
@@ -18,2 +18,4 @@ "use strict"; | ||
]; | ||
var scalar_2 = require("./scalar"); | ||
Object.defineProperty(exports, "Typeless", { enumerable: true, get: function () { return scalar_2.Typeless; } }); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "schematized", | ||
"description": "Turn JS objects into JSON schemas that continue to improve as you provide examples.", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"files": [ | ||
@@ -32,2 +32,3 @@ "dist/" | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.0.5", | ||
@@ -34,0 +35,0 @@ "rimraf": "^3.0.2", |
@@ -55,3 +55,6 @@ # Schematized | ||
// Or combine data from another JSON Schema | ||
builder.addSchema(savedSchema) | ||
builder.addSchema({ | ||
title: '/user response', | ||
description: 'User data from server.' | ||
}) | ||
``` | ||
@@ -62,3 +65,25 @@ | ||
```JSON | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"type": "object", | ||
"properties": { | ||
"token": { | ||
"type": "string", | ||
"maxLength": 32, | ||
"minLength": 32 | ||
}, | ||
"role": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"maxLength": 5, | ||
"minLength": 5 | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"role", | ||
"token" | ||
] | ||
} | ||
``` | ||
@@ -69,9 +94,55 @@ | ||
```JSON | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"type": "object", | ||
"properties": { | ||
"token": { | ||
"type": "string", | ||
"maxLength": 39, | ||
"minLength": 32 | ||
}, | ||
"role": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"maxLength": 9, | ||
"minLength": 5 | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"role", | ||
"token" | ||
] | ||
} | ||
``` | ||
**Schema from the two examples and the previously saved schema**: | ||
**Schema from the two examples and the schema**: | ||
```JSON | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"title": "/user response", | ||
"description": "User data from server.", | ||
"type": "object", | ||
"properties": { | ||
"token": { | ||
"type": "string", | ||
"maxLength": 39, | ||
"minLength": 32 | ||
}, | ||
"role": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"maxLength": 9, | ||
"minLength": 5 | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"role", | ||
"token" | ||
] | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
57307
871
146
0
15