You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-50
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,16 @@ type CompileOptions = {
61
61
// if format-validations should create errors. Defaults to true
62
62
formatAssertion:boolean|"meta-schema";
63
63
// default options for all calls to node.getData()
64
-
getDataDefaultOptions?:TemplateOptions;
64
+
getDataDefaultOptions?: {
65
+
// Add all properties (required and optional) to the generated data
66
+
addOptionalProps?:boolean;
67
+
// Remove data that does not match input schema. Defaults to false
68
+
removeInvalidData?:boolean;
69
+
// Set to false to take default values as they are and not extend them. Defaults to true
70
+
extendDefaults?:boolean;
71
+
// Limits how often a $ref should be followed before aborting. Prevents infinite data-structure. Defaults to 1
72
+
recursionLimit?:number;
73
+
};
65
74
};
66
75
```
67
76
@@ -172,27 +181,27 @@ Please note that these benchmarks refer to validation only. _json-schema-library
172
181
173
182
## SchemaNode methods
174
183
175
-
[**addRemoteSchema**](#addremoteschema) ·
176
-
[**compileSchema**](#compileSchema-1) ·
177
-
[**createSchema**](#createSchema) ·
178
-
[**getChildSelection**](#getchildselection) ·
179
-
[**getData**](#getdata) ·
180
-
[**getNode**](#getnode) ·
181
-
[**getNodeChild**](#getnodechild) ·
182
-
[**getNodeRef**](#getnoderef) ·
183
-
[**getNodeRoot**](#getnoderoot) ·
184
-
[**reduceNode**](#reducenode) ·
185
-
[**toDataNodes**](#todatanodes) ·
186
-
[**toSchemaNodes**](#toschemanodes) ·
187
-
[**validate**](#validate)
184
+
[addRemoteSchema](#addremoteschema) ·
185
+
[compileSchema](#compileSchema-1) ·
186
+
[createSchema](#createSchema) ·
187
+
[getChildSelection](#getchildselection) ·
188
+
[getData](#getdata) ·
189
+
[getNode](#getnode) ·
190
+
[getNodeChild](#getnodechild) ·
191
+
[getNodeRef](#getnoderef) ·
192
+
[getNodeRoot](#getnoderoot) ·
193
+
[reduceNode](#reducenode) ·
194
+
[toDataNodes](#todatanodes) ·
195
+
[toSchemaNodes](#toschemanodes) ·
196
+
[validate](#validate)
188
197
189
198
</details>
190
199
191
200
### addRemoteSchema
192
201
193
202
`addRemoteSchema` lets you add additional schemas that can be referenced by an URL using `$ref`. Use this to combine multiple schemas without changing the actual schema.
194
203
195
-
Each schemas is referenced by their unique `$id` (since draft-06, previously `id`). Usually an `$id` is specified as an url, for example `https://mydomain.com/schema/schema-name` or with a file extension like `https://mydomain.com/schema/schema-name.json`.
204
+
Each schema is referenced by their unique `$id` (since draft-06, previously `id`). Usually an `$id` is specified as an url, for example `https://mydomain.com/schema/schema-name` or with a file extension like `https://mydomain.com/schema/schema-name.json`.
Per default _json-schema-library_ does not have async validators, so `errorsAsync` is always empty. If you add async validators, a list of `Promise<JsonError|undefined>` is return and you need to resolve and filter non-errors (undefined) yourself.
884
+
Per default _json-schema-library_ does not contain async validators, so `errorsAsync` is always empty. If you add async validators, a list of `Promise<JsonError|undefined>` is return and you need to resolve and filter non-errors (undefined) yourself.
879
885
880
886
> **Note**`isValid` only refers to errors. `errorsAsync` has to be evaluated separately
If you're working with complex schemas that use the `oneOf` keyword to validate multiple options, `oneOfFuzzyKeyword` offers an alternative approach. It scores the schemas to return the best match, even if none of the schemas fully validate the input data. This makes error messages more readable and helps identify the most appropriate schema when multiple options exist.
1057
-
1058
-
`oneOfFuzzyKeyword` helps when no schema fully validates the data but you want to prioritize schemas based on how well they fit the input. This makes it easier to interpret validation results for complex conditions.
1059
-
1060
-
</details>
1061
-
1062
1060
### Keyword
1063
1061
1064
-
`Keywords` hold the main logic for JSON Schema functionality. Each `Keyword` corresponds to a JSON Schema keyword like `properties`, `prefixItems`, `oneOf`, etc and offers implementations to `parse`, `validate`, `resolve` and `reduce`. Note that support for each implementation is optional, dependending on the feature requirements. The main properties of a `Keyword`:
1062
+
**Keywords** hold the main logic for JSON Schema functionality. Each `Keyword` corresponds to a JSON Schema keyword like `properties`, `prefixItems`, `oneOf`, etc and offers implementations to `parse`, `validate`, `resolve` and `reduce`. Note that support for each implementation is optional, dependending on the feature requirements. The main properties of a `Keyword`:
1065
1063
1066
1064
- a `Keyword` is only processed if the specified `keyword` is available as property on the JSON Schema
1067
1065
- an optional `order` property may be added as order of keyword execution is sometimes important (`additionalItems` last, `$ref` evaluation first)
@@ -1157,6 +1155,13 @@ function reduceType({ node, pointer, data }: JsonSchemaReducerParams): undefined
1157
1155
1158
1156
</details>
1159
1157
1158
+
Currently **keywords** are not exposed per default. You can still access any keyword implementation by retrieving them from a draft:
If you're working with complex schemas that use the `oneOf` keyword to validate multiple options, `oneOfFuzzyKeyword` offers an alternative approach. It scores the schemas to return the best match, even if none of the schemas fully validate the input data. This makes error messages more readable and helps identify the most appropriate schema when multiple options exist.
1204
+
1205
+
`oneOfFuzzyKeyword` helps when no schema fully validates the data but you want to prioritize schemas based on how well they fit the input. This makes it easier to interpret validation results for complex conditions.
1206
+
1207
+
`oneOfFuzzyKeyword` is exposed by _json-schema-library_ and can be used to extend any draft.
0 commit comments