@@ -168,14 +168,14 @@ Please note that these benchmarks refer to validation only. _json-schema-library
168
168
169
169
## SchemaNode methods
170
170
171
- [ ** addRemoteSchema** ] ( #addremote ) ·
171
+ [ ** addRemoteSchema** ] ( #addremoteschema ) ·
172
172
[ ** compileSchema** ] ( #compileSchema-1 ) ·
173
173
[ ** createSchema** ] ( #createSchema ) ·
174
174
[ ** getChildSelection** ] ( #getchildselection ) ·
175
175
[ ** getData** ] ( #getdata ) ·
176
176
[ ** getNode** ] ( #getnode ) ·
177
- [ ** getNodeChild** ] ( #getchild ) ·
178
- [ ** getNodeRef** ] ( #getref ) ·
177
+ [ ** getNodeChild** ] ( #getnodechild ) ·
178
+ [ ** getNodeRef** ] ( #getnoderef ) ·
179
179
[ ** getNodeRoot** ] ( #getnoderoot ) ·
180
180
[ ** reduceNode** ] ( #reducenode ) ·
181
181
[ ** toDataNodes** ] ( #todatanodes ) ·
@@ -226,7 +226,7 @@ To access the remote schema, add a $ref within your local schema and the remote
226
226
schemaNode .validate ({ character: " AB" }); // maxLength error
227
227
schemaNode .getData ({}); // { character: "A" } - default value resolved
228
228
// returns remote schema (from compiled local schema):
229
- schemaNode .getNodeRef (" https://sagold.com/remote" );
229
+ const { node, error } = schemaNode .getNodeRef (" https://sagold.com/remote" );
230
230
```
231
231
232
232
** Note** the support for $ref resolution has additional complexities, if you add nested $ids to you schema. Here, json-schema-library has only partial support ([ @see integration test result] ( https://github.com/sagold/json-schema-library/actions/runs/4037856805/jobs/6941448741 ) ). Thus, it is recommended to omit the features of changing scopes by nested $ids. For more details, see [ json-schema.org: Structuring a complex schema] ( https://json-schema.org/understanding-json-schema/structuring.html#base-uri ) .
@@ -278,7 +278,7 @@ schemaNode.addRemoteSchema("https://sagold.com/remote", {
278
278
schemaNode .validate (" AB" ); // maxLength error
279
279
schemaNode .getData (" A" ); // "A" - default value resolved
280
280
// returns remote schema (from compiled local schema):
281
- schemaNode .getNodeRef (" https://sagold.com/remote#/$defs/character" );
281
+ const { node, error } = schemaNode .getNodeRef (" https://sagold.com/remote#/$defs/character" );
282
282
```
283
283
284
284
** Note** JSON Pointer are not restricted to ` $defs ` (definitions), but can reference any subschema. For example:
@@ -355,6 +355,8 @@ const childNodes: JsonSchema[] = jsonSchema.getChildSelection("content");
355
355
expect (childNodes .map ((n ) => n .schema )).to .deep .equal ([{ type: " string" }, { type: " number" }]);
356
356
```
357
357
358
+ </details >
359
+
358
360
### getData
359
361
360
362
` getData ` creates input data from a JSON Schema that is valid to the schema. Where possible, the JSON Schema ` default ` property will be used to initially setup input data. Otherwise, the first values encountered (enum values, initial values, etc.) are used to build up the json-data.
@@ -645,8 +647,8 @@ if (error) {
645
647
``` ts
646
648
const mySchema = { type: " object" , properties: { title: { type: " string" } } };
647
649
const root = compileSchema (mySchema );
648
- const node = root .getNodeChild (" title" , { title: " value" });
649
- if (! isSchemaNode ( node ) ) return ;
650
+ const { node } = root .getNodeChild (" title" , { title: " value" });
651
+ if (node == null ) return ;
650
652
console .log (node .schema );
651
653
```
652
654
@@ -669,11 +671,13 @@ const localSchema: JsonSchema = {
669
671
]
670
672
};
671
673
672
- const schema = root .getNodeChild (" title" , { title: 4 })?.schema ;
674
+ const schema = root .getNodeChild (" title" , { title: 4 }). node ?.schema ;
673
675
674
676
expect (schema ).to .deep .eq ({ type: " number" });
675
677
```
676
678
679
+ </details >
680
+
677
681
### getNodeRef
678
682
679
683
` getNodeRef ` retrieves the SchemaNode of a ` $ref ` string.
@@ -692,10 +696,10 @@ root.getNodeRef("https://remote.com/schema"); // remoteSchema
692
696
693
697
``` ts
694
698
const root = compileSchema (mySchema );
695
- const { node : childNode } = root .getNode (" /image/title" );
699
+ const { node } = root .getNode (" /image/title" );
696
700
697
- if (childNode ) {
698
- assert (childNode .getNodeRoot () === root ); // success
701
+ if (node ) {
702
+ assert (node .getNodeRoot () === root ); // success
699
703
}
700
704
```
701
705
@@ -708,7 +712,7 @@ This utility helps walking down the schema-tree with a set of data and it helps
708
712
complete json-schema for a specific data-value.
709
713
710
714
``` ts
711
- const reducedNode = compileSchema ({
715
+ const { node : reducedNode } = compileSchema ({
712
716
properties: {
713
717
trigger: { type: " boolean" }
714
718
}
0 commit comments