Skip to content

Commit b265cb6

Browse files
committed
docs: fixes
1 parent c793fbd commit b265cb6

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ Please note that these benchmarks refer to validation only. _json-schema-library
168168

169169
## SchemaNode methods
170170

171-
[**addRemoteSchema**](#addremote) ·
171+
[**addRemoteSchema**](#addremoteschema) ·
172172
[**compileSchema**](#compileSchema-1) ·
173173
[**createSchema**](#createSchema) ·
174174
[**getChildSelection**](#getchildselection) ·
175175
[**getData**](#getdata) ·
176176
[**getNode**](#getnode) ·
177-
[**getNodeChild**](#getchild) ·
178-
[**getNodeRef**](#getref) ·
177+
[**getNodeChild**](#getnodechild) ·
178+
[**getNodeRef**](#getnoderef) ·
179179
[**getNodeRoot**](#getnoderoot) ·
180180
[**reduceNode**](#reducenode) ·
181181
[**toDataNodes**](#todatanodes) ·
@@ -226,7 +226,7 @@ To access the remote schema, add a $ref within your local schema and the remote
226226
schemaNode.validate({ character: "AB" }); // maxLength error
227227
schemaNode.getData({}); // { character: "A" } - default value resolved
228228
// returns remote schema (from compiled local schema):
229-
schemaNode.getNodeRef("https://sagold.com/remote");
229+
const { node, error } = schemaNode.getNodeRef("https://sagold.com/remote");
230230
```
231231

232232
**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", {
278278
schemaNode.validate("AB"); // maxLength error
279279
schemaNode.getData("A"); // "A" - default value resolved
280280
// 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");
282282
```
283283

284284
**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");
355355
expect(childNodes.map((n) => n.schema)).to.deep.equal([{ type: "string" }, { type: "number" }]);
356356
```
357357

358+
</details>
359+
358360
### getData
359361

360362
`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) {
645647
```ts
646648
const mySchema = { type: "object", properties: { title: { type: "string" } } };
647649
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;
650652
console.log(node.schema);
651653
```
652654

@@ -669,11 +671,13 @@ const localSchema: JsonSchema = {
669671
]
670672
};
671673

672-
const schema = root.getNodeChild("title", { title: 4 })?.schema;
674+
const schema = root.getNodeChild("title", { title: 4 }).node?.schema;
673675

674676
expect(schema).to.deep.eq({ type: "number" });
675677
```
676678

679+
</details>
680+
677681
### getNodeRef
678682

679683
`getNodeRef` retrieves the SchemaNode of a `$ref` string.
@@ -692,10 +696,10 @@ root.getNodeRef("https://remote.com/schema"); // remoteSchema
692696

693697
```ts
694698
const root = compileSchema(mySchema);
695-
const { node: childNode } = root.getNode("/image/title");
699+
const { node } = root.getNode("/image/title");
696700

697-
if (childNode) {
698-
assert(childNode.getNodeRoot() === root); // success
701+
if (node) {
702+
assert(node.getNodeRoot() === root); // success
699703
}
700704
```
701705

@@ -708,7 +712,7 @@ This utility helps walking down the schema-tree with a set of data and it helps
708712
complete json-schema for a specific data-value.
709713

710714
```ts
711-
const reducedNode = compileSchema({
715+
const { node: reducedNode } = compileSchema({
712716
properties: {
713717
trigger: { type: "boolean"}
714718
}

0 commit comments

Comments
 (0)