Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
sagold committed Apr 14, 2024
1 parent 93da964 commit 8e7a4ad
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,21 @@ expect(schemas).to.deep.equal([{ type: "string" }, { type: "number" }]);

`step` retrieves the json-schema of a child property or index. Using `step` it is possible to incrementally go through the data, retrieving the schema for each next item.

@todo talk about `schemaNode`

```ts
const jsonSchema = new Draft2019(mySchema);
const draft = new Draft2019(mySchema);
const localSchema = { type: "object", properties: { title: { type: "string" } } };
const localData = { title: "value" };
const schemaOfTitle = jsonSchema.step("title", localSchema, localData);
const { schema } = draft.step(draft.createNode(localSchema), "title", localData);
```

<details><summary>Example</summary>

```ts
import { Draft2019, JsonSchema } from "json-schema-library";

const jsonSchema = new Draft2019(mySchema);
const draft = new Draft2019(mySchema);
const localSchema: JsonSchema = {
oneOf: [
{
Expand All @@ -572,9 +574,9 @@ const localSchema: JsonSchema = {
]
};
const localData = { title: 4 };
const schemaOfTitle = jsonSchema.step("title", localSchema, localData);
const { schema } = draft.step(draft.createNode(localSchema), "title", localData);

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

</details>
Expand Down

0 comments on commit 8e7a4ad

Please sign in to comment.