schematized
Advanced tools
Comparing version 1.5.1 to 1.6.0
@@ -9,2 +9,4 @@ import { SchemaNode } from '../../schema-node'; | ||
private readonly additionalPropertiesStrategy; | ||
private readonly maxPropertiesStrategy; | ||
private readonly minPropertiesStrategy; | ||
constructor(schemaNode: any); | ||
@@ -11,0 +13,0 @@ matchObject(object: any): boolean; |
@@ -8,2 +8,4 @@ "use strict"; | ||
const additional_properties_1 = require("./additional-properties"); | ||
const max_properties_1 = require("./max-properties"); | ||
const min_properties_1 = require("./min-properties"); | ||
const pattern_properties_1 = require("./pattern-properties"); | ||
@@ -22,2 +24,4 @@ const required_1 = require("./required"); | ||
this.additionalPropertiesStrategy = new additional_properties_1.AdditionalProperties(); | ||
this.maxPropertiesStrategy = new max_properties_1.MaxProperties(); | ||
this.minPropertiesStrategy = new min_properties_1.MinProperties(); | ||
} | ||
@@ -31,10 +35,15 @@ matchObject(object) { | ||
addObject(object) { | ||
this.PatternPropertiesStrategy.addObject(object); | ||
for (const [key, value] of Object.entries(object)) { | ||
if (!this.properties[key]) { | ||
if (this.PatternPropertiesStrategy.findPattern(key)) { | ||
delete object[key]; | ||
continue; | ||
} | ||
if (!this.properties[key]) | ||
this.properties[key] = new schema_node_1.SchemaNode(); | ||
} | ||
this.properties[key].addObject(value); | ||
} | ||
this.PatternPropertiesStrategy.addObject(object); | ||
this.requiredStrategy.addObject(object); | ||
this.maxPropertiesStrategy.addObject(object); | ||
this.minPropertiesStrategy.addObject(object); | ||
} | ||
@@ -57,2 +66,4 @@ addSchema(schema) { | ||
this.additionalPropertiesStrategy.addSchema(schema); | ||
this.maxPropertiesStrategy.addSchema(schema); | ||
this.minPropertiesStrategy.addSchema(schema); | ||
} | ||
@@ -68,2 +79,6 @@ toSchema() { | ||
schema = { ...schema, ...this.additionalPropertiesStrategy.toSchema() }; | ||
if (!schema.patternProperties) | ||
schema = { ...schema, ...this.maxPropertiesStrategy.toSchema() }; | ||
if (!schema.patternProperties) | ||
schema = { ...schema, ...this.minPropertiesStrategy.toSchema() }; | ||
return schema; | ||
@@ -76,3 +91,3 @@ } | ||
} | ||
return schemaProperties; | ||
return lodash_1.default.isEmpty(schemaProperties) ? undefined : schemaProperties; | ||
} | ||
@@ -79,0 +94,0 @@ } |
@@ -9,4 +9,4 @@ export declare class PatternProperties { | ||
}; | ||
findPattern(prop: string): string; | ||
private propertiesToSchema; | ||
private findPattern; | ||
} |
@@ -45,2 +45,11 @@ "use strict"; | ||
} | ||
findPattern(prop) { | ||
for (const pattern of Object.keys(this.patternProperties)) { | ||
const re = new RegExp(pattern); | ||
if (re.test(prop)) { | ||
return pattern; | ||
} | ||
} | ||
return null; | ||
} | ||
propertiesToSchema(properties) { | ||
@@ -53,12 +62,4 @@ const schemaProperties = {}; | ||
} | ||
findPattern(prop) { | ||
for (const pattern of Object.keys(this.patternProperties)) { | ||
if (pattern.includes(prop)) { | ||
return pattern; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
exports.PatternProperties = PatternProperties; | ||
//# sourceMappingURL=pattern-properties.js.map |
@@ -7,2 +7,3 @@ import { Format } from './format'; | ||
type: string; | ||
disabled: string[]; | ||
maxLengthStrategy: MaxLength; | ||
@@ -9,0 +10,0 @@ minLengthStrategy: MinLength; |
@@ -16,2 +16,3 @@ "use strict"; | ||
this.type = 'string'; | ||
this.disabled = []; | ||
this.maxLengthStrategy = new max_length_1.MaxLength(); | ||
@@ -26,8 +27,13 @@ this.minLengthStrategy = new min_length_1.MinLength(); | ||
super.addObject(string); | ||
this.maxLengthStrategy.addObject(string); | ||
this.minLengthStrategy.addObject(string); | ||
this.formatStrategy.addObject(string); | ||
if (!this.disabled.includes('maxLength')) | ||
this.maxLengthStrategy.addObject(string); | ||
if (!this.disabled.includes('minLength')) | ||
this.minLengthStrategy.addObject(string); | ||
if (!this.disabled.includes('format')) | ||
this.formatStrategy.addObject(string); | ||
} | ||
addSchema(schema) { | ||
super.addSchema(schema); | ||
if (schema.disabled) | ||
this.disabled.push(...schema.disabled); | ||
this.maxLengthStrategy.addSchema(schema); | ||
@@ -34,0 +40,0 @@ this.minLengthStrategy.addSchema(schema); |
{ | ||
"name": "schematized", | ||
"description": "Turn objects into JSON schemas! The more examples you provide, the better your schema will be.", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"files": [ | ||
@@ -20,22 +20,2 @@ "dist/" | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.15" | ||
}, | ||
"devDependencies": { | ||
"@ava/typescript": "^1.1.1", | ||
"@types/lodash": "^4.14.155", | ||
"@types/node": "^14.0.13", | ||
"ajv": "^6.12.2", | ||
"ava": "^3.9.0", | ||
"commitizen": "^4.1.2", | ||
"cz-conventional-changelog": "3.2.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^17.0.8", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.5", | ||
"xo": "^0.32.0" | ||
}, | ||
"ava": { | ||
@@ -61,3 +41,4 @@ "failFast": false, | ||
"rules": { | ||
"@typescript-eslint/no-var-requires": 0 | ||
"@typescript-eslint/no-var-requires": 0, | ||
"@typescript-eslint/no-dynamic-delete": 0 | ||
} | ||
@@ -70,2 +51,22 @@ }, | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.15" | ||
}, | ||
"devDependencies": { | ||
"@ava/typescript": "^1.1.1", | ||
"@types/lodash": "^4.14.155", | ||
"@types/node": "^14.0.13", | ||
"ajv": "^6.12.2", | ||
"ava": "^3.9.0", | ||
"commitizen": "^4.1.2", | ||
"cz-conventional-changelog": "3.2.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^17.0.8", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.5", | ||
"xo": "^0.32.0" | ||
}, | ||
"keywords": [ | ||
@@ -72,0 +73,0 @@ "json", |
@@ -21,4 +21,4 @@ # Schematized | ||
- [Schema from the two examples and the schema](#schema-from-the-two-examples-and-the-schema) | ||
- [📖 API](#-api) | ||
- [✅ Supported Schema Features](#?-supported-schema-features) | ||
- [📖 API](#��-api) | ||
- [✅ Supported Schema Features](#�-supported-schema-features) | ||
- [Types](#types) | ||
@@ -270,4 +270,4 @@ - [Typeless](#typeless) | ||
| required | Yes | Yes | | ||
| maxProperties | Not yet | Not yet | | ||
| minProperties | Not yet | Not yet | | ||
| maxProperties | Yes | Yes | | ||
| minProperties | Yes | Yes | | ||
@@ -274,0 +274,0 @@ ### Array |
Sorry, the diff of this file is not supported yet
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
76919
1
72
1086