schematized
Advanced tools
Comparing version 1.8.3 to 1.8.4
@@ -0,1 +1,8 @@ | ||
## [1.8.4](https://github.com/ryparker/schematized/compare/v1.8.3...v1.8.4) (2020-08-13) | ||
### Bug Fixes | ||
* **objects, patternproperties:** objects with only patternProps will no longer have undefined props ([71d0e5d](https://github.com/ryparker/schematized/commit/71d0e5d8f099dcdfeed00ea44eff592f52ac6b82)) | ||
## [1.8.3](https://github.com/ryparker/schematized/compare/v1.8.2...v1.8.3) (2020-08-12) | ||
@@ -2,0 +9,0 @@ |
export declare class SchemaNode { | ||
activeStrategies: any; | ||
activeStrategies: any[]; | ||
strategies: typeof import("./strategies/boolean").BooleanStrategy[]; | ||
constructor(); | ||
addSchema(schema: Record<string, any>): this; | ||
@@ -6,0 +5,0 @@ addObject(object: Record<string, unknown>): this; |
@@ -11,4 +11,4 @@ "use strict"; | ||
constructor() { | ||
this.activeStrategies = []; | ||
this.strategies = strategies_1.BASIC_SCHEMA_STRATEGIES; | ||
this.activeStrategies = []; | ||
} | ||
@@ -15,0 +15,0 @@ addSchema(schema) { |
@@ -35,7 +35,4 @@ "use strict"; | ||
this.PatternPropertiesStrategy.addObject(object); | ||
for (const [key, value] of Object.entries(object)) { | ||
if (this.PatternPropertiesStrategy.findPattern(key)) { | ||
delete object[key]; | ||
continue; | ||
} | ||
const objectWithoutPatterns = lodash_1.default.omit(object, this.PatternPropertiesStrategy.matchingPropertyKeys); | ||
for (const [key, value] of Object.entries(objectWithoutPatterns)) { | ||
if (!this.properties[key]) | ||
@@ -45,3 +42,4 @@ this.properties[key] = new schema_node_1.SchemaNode(); | ||
} | ||
this.requiredStrategy.addObject(object); | ||
if (!this.disabled.includes('required')) | ||
this.requiredStrategy.addObject(object); | ||
if (!this.disabled.includes('maxProperties')) | ||
@@ -70,3 +68,6 @@ this.maxPropertiesStrategy.addObject(object); | ||
if (this.properties) { | ||
schema.properties = this.propertiesToSchema(this.properties); | ||
const schemaProperties = this.propertiesToSchema(this.properties); | ||
if (!lodash_1.default.isEmpty(schemaProperties)) { | ||
schema.properties = schemaProperties; | ||
} | ||
} | ||
@@ -91,8 +92,9 @@ schema = { | ||
for (const [key, value] of lodash_1.default.toPairs(properties)) { | ||
if (typeof value.toSchema !== 'function') { | ||
const schema = value.toSchema(); | ||
if (!schema) { | ||
continue; | ||
} | ||
schemaProperties[key] = value.toSchema(); | ||
schemaProperties[key] = schema; | ||
} | ||
return lodash_1.default.isEmpty(schemaProperties) ? undefined : schemaProperties; | ||
return schemaProperties; | ||
} | ||
@@ -99,0 +101,0 @@ addSchemaProperties(properties) { |
export declare class PatternProperties { | ||
keywords: Set<string>; | ||
patternProperties: {}; | ||
matchingPropertyKeys: any[]; | ||
addObject(object: Record<string, unknown>): void; | ||
addSchema(schema: Record<string, any>): void; | ||
toSchema(): { | ||
patternProperties?: undefined; | ||
} | { | ||
patternProperties: {}; | ||
@@ -8,0 +11,0 @@ }; |
@@ -13,2 +13,3 @@ "use strict"; | ||
this.patternProperties = {}; | ||
this.matchingPropertyKeys = []; | ||
} | ||
@@ -22,2 +23,3 @@ addObject(object) { | ||
if (pattern) { | ||
this.matchingPropertyKeys.push(key); | ||
this.patternProperties[pattern].addObject(value); | ||
@@ -28,11 +30,13 @@ } | ||
addSchema(schema) { | ||
if (schema.patternProperties) { | ||
for (const [key, value] of Object.entries(schema.patternProperties)) { | ||
if (value) { | ||
if (!this.patternProperties[key]) { | ||
this.patternProperties[key] = new schema_node_1.SchemaNode(); | ||
} | ||
this.patternProperties[key].addSchema(value); | ||
} | ||
if (!schema.patternProperties) { | ||
return; | ||
} | ||
for (const [key, value] of Object.entries(schema.patternProperties)) { | ||
if (!value) { | ||
continue; | ||
} | ||
if (!this.patternProperties[key]) { | ||
this.patternProperties[key] = new schema_node_1.SchemaNode(); | ||
} | ||
this.patternProperties[key].addSchema(value); | ||
} | ||
@@ -42,3 +46,3 @@ } | ||
if (lodash_1.default.isEmpty(this.patternProperties)) { | ||
return undefined; | ||
return {}; | ||
} | ||
@@ -51,4 +55,3 @@ return { | ||
for (const pattern of Object.keys(this.patternProperties)) { | ||
const re = new RegExp(pattern); | ||
if (re.test(prop)) { | ||
if (new RegExp(pattern).test(prop)) { | ||
return pattern; | ||
@@ -66,2 +69,6 @@ } | ||
for (const [key, value] of Object.entries(properties)) { | ||
if (!(value instanceof schema_node_1.SchemaNode)) { | ||
console.error('Pattern property was not initialized properly. Expected value to be instance of SchemaNode, received:', value); | ||
continue; | ||
} | ||
schemaProperties[key] = value.toSchema(); | ||
@@ -68,0 +75,0 @@ } |
{ | ||
"name": "schematized", | ||
"description": "Turn objects into JSON schemas! The more examples you provide, the better your schema will be.", | ||
"version": "1.8.3", | ||
"version": "1.8.4", | ||
"files": [ | ||
@@ -6,0 +6,0 @@ "dist" |
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
81116
1124