@@ -163,7 +163,7 @@ Please note that these benchmarks refer to validation only. _json-schema-library
163
163
164
164
## SchemaNode methods
165
165
166
- [ ** validate** ] ( #validate ) · [ ** validateAsync** ] ( #validateasync ) · [ ** getData** ] ( #getData ) · [ ** getSchema** ] ( #getschema ) · [ ** getChild** ] ( #getchild ) · [ ** reduce ** ] ( #reduce ) · [ ** toDataNodes** ] ( #todatanodes ) · [ ** toSchemaNodes** ] ( #toschemanodes ) · [ ** addRemote** ] ( #addremote ) · [ ** compileSchema** ] ( #compileSchema-1 ) · [ createSchema] ( #createSchema ) · [ getChildSchemaSelection] ( #getchildschemaselection )
166
+ [ ** validate** ] ( #validate ) · [ ** validateAsync** ] ( #validateasync ) · [ ** getData** ] ( #getdata ) · [ ** getSchema** ] ( #getschema ) · [ ** getChild** ] ( #getchild ) · [ ** reduceSchema ** ] ( #reduceschema ) · [ ** toDataNodes** ] ( #todatanodes ) · [ ** toSchemaNodes** ] ( #toschemanodes ) · [ ** addRemote** ] ( #addremote ) · [ ** compileSchema** ] ( #compileSchema-1 ) · [ createSchema] ( #createSchema ) · [ getChildSchemaSelection] ( #getchildschemaselection )
167
167
168
168
### validate
169
169
@@ -548,9 +548,38 @@ expect(schema).to.deep.eq({ type: "number" });
548
548
549
549
</details >
550
550
551
- ### reduce
551
+ ### reduceSchema
552
552
553
- ` reduce ` compiles dynamic schema-keywords of a SchemaNode according to the given data.
553
+ ` reduceSchema ` compiles dynamic JSON schema keywords of a SchemaNode according to the given data.
554
+ This utility helps walking down the schema-tree with a set of data and it helps getting a mostly
555
+ complete json-schema for a specific data-value.
556
+
557
+ ``` ts
558
+ const reducedNode = compileSchema ({
559
+ properties: {
560
+ trigger: { type: " boolean" }
561
+ }
562
+ dependentSchemas : {
563
+ trigger: {
564
+ required: [" title" ],
565
+ properties: {
566
+ title: { type: " string" }
567
+ }
568
+ }
569
+ }
570
+ }).reduceSchema ({ trigger: true });
571
+
572
+ expect (reducedNode .schema ).to .deep .eq ({
573
+ required: [" title" ],
574
+ properties: {
575
+ trigger: { type: " boolean" },
576
+ title: { type: " string" }
577
+ }
578
+ });
579
+ ```
580
+
581
+ ⚠️ Please be aware that certain schema-definitions are lost when resolving or merging sub-schemas.
582
+ This mainly refers to validation-properties, but also some ambigiuous schema might get overriden.
554
583
555
584
### toDataNodes
556
585
@@ -1052,8 +1081,17 @@ expect(resolvedNode?.schema).to.deep.eq({
1052
1081
1053
1082
## Breaking Changes
1054
1083
1055
- - ` each(data, callback) ` has been replaced by ` const nodes = toDataNodes(data) `
1056
- - ` eachSchema(callback) ` has been replaced by ` const nodes = toSchemaNodes() `
1084
+ - ` compileSchema ` is a standalone function which replaces ` Draft ` -Class
1085
+ - all return values for JSON Schema are ` SchemaNode ` that contain a schema-property
1086
+ - ` draft.getTemplate(inputData) ` has been ** renamed** to ` node.getData(inputData) `
1087
+ - ` draft.each(data, callback) ` has been ** replaced** by ` const nodes = node.toDataNodes(data) `
1088
+ - ` draft.eachSchema(callback) ` has been ** replaced** by ` const nodes = node.toSchemaNodes() `
1089
+ - ` draft.isValid(data) ` has been ** replaced** by ` node.validate(data).valid `
1090
+ - ` draft.getSchema(options) ` has been ** changed** to ` node.getSchema(pointer, data, options) `
1091
+ - ` draft.step(property, data) ` has been ** renamed** to ` node.getChild(property, data) `
1092
+ - ` draft.addRemoteSchema(schema) ` has been ** renamed** to ` node.addRemote(schema) `
1093
+ - ` draft.createSchemaOf(schema) ` has been ** renamed** to ` node.createSchema(schema) `
1094
+ - draft customization has completely changed
1057
1095
1058
1096
### v10.0.0
1059
1097
0 commit comments