json-schema-library 11.0.2 → 11.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +199 -79
- package/README.md +5 -132
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.mts +7 -4
- package/dist/index.mjs +1 -1
- package/dist/jlib.js +2 -2
- package/index.ts +2 -2
- package/package.json +2 -1
- package/src/SchemaNode.ts +11 -5
- package/src/compileSchema.ts +5 -5
- package/src/types.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,123 +1,243 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### v11.0.3
|
|
4
|
+
|
|
5
|
+
- fixed type of main input-schema to support boolean
|
|
6
|
+
|
|
7
|
+
### v11.0.2
|
|
8
|
+
|
|
9
|
+
- fixed `getNode` to always return a reduced JSON schema
|
|
10
|
+
- fixed issues using reduce with `oneOfProperty`
|
|
11
|
+
|
|
12
|
+
### v11.0.1
|
|
13
|
+
|
|
14
|
+
- improved error reporting when using oneOfProperty-declarator
|
|
15
|
+
|
|
16
|
+
### v11.0.0
|
|
17
|
+
|
|
18
|
+
- introduced annotations
|
|
19
|
+
- added node.createAnnotation helper
|
|
20
|
+
- changed typing to strict
|
|
21
|
+
- added annotations-list to `validate()` result
|
|
22
|
+
- added keyword support for `deprecated: true` which returns a `deprecated-warning` annotation
|
|
23
|
+
|
|
24
|
+
**breaking changes**:
|
|
25
|
+
|
|
26
|
+
- Return type of validators is now `ValidationReturnType` instead of `ValidationResult`
|
|
27
|
+
- type `AnnotationData` replaces `ErroData`
|
|
28
|
+
|
|
29
|
+
### v10.5.0
|
|
30
|
+
|
|
31
|
+
- added support for ref resolution in getSchemaType
|
|
32
|
+
|
|
33
|
+
### v10.4.0
|
|
34
|
+
|
|
35
|
+
- introduced esm module export
|
|
36
|
+
- fixed typo in argument ~~disableRecusionLimit~~ disableRecursionLimit
|
|
37
|
+
- added settings to exports for global changes of settings
|
|
38
|
+
|
|
39
|
+
### v10.3.0
|
|
40
|
+
|
|
41
|
+
- introduce setting `REGEX_FLAGS` and schema-property `regexFlags` to customize regex flags to use evaluating regex
|
|
42
|
+
- fixed an issue resolving non-URI compatible $ref-targets containing `#/definitions`
|
|
43
|
+
|
|
44
|
+
### v10.2.0
|
|
45
|
+
|
|
46
|
+
- introduce getData setting `useTypeDefaults`
|
|
47
|
+
- introduce support to merge meta-properties using $ref-resolution
|
|
48
|
+
|
|
49
|
+
### v10.1.0
|
|
50
|
+
|
|
51
|
+
- replaced `node.additionalItems` by `node.items` for drafts below 2020-12
|
|
52
|
+
- fixed `additionalItems` behaviour to be ignored when `schema.items` is not an array
|
|
53
|
+
|
|
54
|
+
### v10.0.0
|
|
55
|
+
|
|
56
|
+
> This update involves some significant changes in how you work with the library, so please carefully review the migration guide and adjust your implementation accordingly.
|
|
57
|
+
|
|
58
|
+
In version v10.0.0, we've made significant changes to the library’s API, particularly in how we handle drafts and schemas. These changes are required to support features like `dynamicAnchor`, `unevaluatedItems`, and `oneOfIndex` and to integrate with the headless-json-editor. The previous approach of directly working with JSON schema objects lacked the flexibility needed for more advanced features and extensibility.
|
|
59
|
+
|
|
60
|
+
The new implementation revolves around compiling schemas into a **SchemaNode** tree. This change offers a more fitting, simpler, and extensible approach to working with JSON schemas.
|
|
61
|
+
|
|
62
|
+
#### Key Changes:
|
|
63
|
+
|
|
64
|
+
- **Compile Schema**: The `compileSchema` function now replaces the previous Draft-Class approach.
|
|
65
|
+
- **SchemaNode Representation**: All schemas are now represented as `SchemaNode`, which holds the schema and provides an easier way to work with them.
|
|
66
|
+
|
|
67
|
+
#### Breaking Changes:
|
|
68
|
+
|
|
69
|
+
**`compileSchema`** is now a standalone function and replaces the `Draft` class. All return values for JSON Schema are now `SchemaNode` objects that contain a `schema` property.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
// PREVIOUSLY
|
|
73
|
+
const draft = new Draft(schema);
|
|
74
|
+
|
|
75
|
+
// NOW
|
|
76
|
+
const node = compileSchema(schema);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Changed Methods**:
|
|
80
|
+
|
|
81
|
+
- `draft.createSchemaOf(schema)` → `node.createSchema(schema)`
|
|
82
|
+
- `draft.each(data, callback)` → `const nodes = node.toDataNodes(data)`
|
|
83
|
+
- `draft.eachSchema(callback)` → `const nodes = node.toSchemaNodes()`
|
|
84
|
+
- `draft.getChildSchemaSelection(property)` → `node.getChildSelection(property)`
|
|
85
|
+
- `draft.getNode(options)` → `node.getNode(pointer, data, options)`
|
|
86
|
+
- `draft.getTemplate(inputData)` → `node.getData(inputData)`
|
|
87
|
+
- `draft.isValid(data)` → `node.validate(data).valid`
|
|
88
|
+
- `draft.step(property, data)` → `node.getNodeChild(property, data)`
|
|
89
|
+
|
|
90
|
+
**Renamed Properties**: `templateDefaultOptions` → `getDataDefaultOptions`
|
|
91
|
+
|
|
92
|
+
**Draft Customization**: Customizing drafts has changed completely. The previous methods of extending drafts are no longer valid, and draft handling is now centered around `SchemaNode`.
|
|
93
|
+
|
|
94
|
+
**Removed Error Property `name`**: Error property `name` has been removed from `JsonError` in favor of `code`.
|
|
95
|
+
|
|
96
|
+
**Removed Configuration Option**: The `templateDefaultOptions` property has been removed from the global settings object. You should now configure it using the `compileSchema` options:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
compileSchema(schema, {
|
|
100
|
+
getDataDefaultOptions: {
|
|
101
|
+
addOptionalProps: false,
|
|
102
|
+
removeInvalidData: false,
|
|
103
|
+
extendDefaults: true
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Changed remote $id support** in `addRemoteSchema`. An `$id` has to be a valid url (previously any value was accepted)
|
|
4
109
|
|
|
5
110
|
### v9.0.0
|
|
6
111
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
112
|
+
**breaking changes**:
|
|
113
|
+
|
|
114
|
+
- _getSchema_ signature changed in favour of an options object. Instead of `draft.getNode(pointer, data)` arguments have to be passed as an object `draft.getNode({ pointer, data })`. This removes setting unwanted optional arguments and keeps the api more stable in the future (e.g. `withSchemaWarning` option)
|
|
115
|
+
- _JsonError_ now must expose `pointer`, `schema` and `value` consistently on data property
|
|
116
|
+
|
|
117
|
+
**updates**
|
|
118
|
+
|
|
119
|
+
- _getSchema_ consistently returns errors and can return errors for empty schema using `withSchemaWarning` option
|
|
10
120
|
|
|
11
121
|
### v8.0.0
|
|
12
122
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
123
|
+
With version `v8.0.0`, _getData_ was improved to better support optional properties and utilize existing core logic, making it more reliable. Breaking changes:
|
|
124
|
+
|
|
125
|
+
- Renamed `JSONError` to `JsonError` and `JSONSchema` to `JsonSchema`
|
|
126
|
+
- `getData` only adds required properties. Behaviour can be changed by [getData default options](#getData-default-options)
|
|
127
|
+
- Internal schema property `oneOfSchema` has been replaced by `schema.getOneOfOrigin()`
|
|
128
|
+
- Changed `unique-items-error` to point to error for duplicated item and changed data-properties
|
|
129
|
+
- Removed `SchemaService` as it was no longer used nor tested
|
|
130
|
+
|
|
131
|
+
<details><summary>Exposed new helper functions</summary>
|
|
132
|
+
|
|
133
|
+
- `mergeSchema` - Merges to two json schema
|
|
134
|
+
- `reduceNode` - Reduce schema by merging dynamic constructs into a static json schema omitting those properties
|
|
135
|
+
- `isDynamicSchema` - Returns true if the passed schema contains dynamic properties (_if_, _dependencies_, _allOf_, etc)
|
|
136
|
+
- `resolveDynamicSchema` - Resolves all dynamic schema definitions for the given input data and returns the resulting JSON Schema without any dynamic schema definitions.
|
|
137
|
+
|
|
138
|
+
</details>
|
|
19
139
|
|
|
20
140
|
### 7.0.0
|
|
21
141
|
|
|
22
|
-
-
|
|
142
|
+
- changed core interface to draft for simpler configuration using a configuration map
|
|
23
143
|
|
|
24
144
|
**Breaking Changes**
|
|
25
145
|
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
146
|
+
- replaced `Core` interface by new `Draft` interface
|
|
147
|
+
- changed export of `Interface` to `Draft`
|
|
148
|
+
- changed export of `Interface` to `Draft`
|
|
149
|
+
- renamed `addSchema` to `addRemoteSchema`
|
|
150
|
+
- changed api of `compileSchema` to have an additional schema-parameter for rootSchema reference
|
|
151
|
+
- changed `compileSchema` and `addRemoteSchema` to work on instance state, instead of global state
|
|
152
|
+
- `addRemoteSchema`, `compileSchema` now requires draft instance as first parameter
|
|
153
|
+
- removed direct export of following functions: `addValidator`, `compileSchema`, `createSchemaOf`, `each`, `eachSchema`, `getChildSchemaSelection`, `getSchema`, `getTemplate`, `isValid`, `step`, `validate`. They are still accessible under the draftConfigs of each draft-version
|
|
154
|
+
- changed draft version of `JsonEditor` to draft07
|
|
35
155
|
|
|
36
156
|
**Milestone**
|
|
37
157
|
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
158
|
+
- [✓] configurable and consistent draft api
|
|
159
|
+
- [✓] expose all function under their draft-version
|
|
160
|
+
- [✓] remove global states in remotes
|
|
41
161
|
|
|
42
162
|
### 6.1.0
|
|
43
163
|
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
164
|
+
- [✓] Feature -- add support for dependencies in _getSchema_ and _getTemplate_
|
|
165
|
+
- [✓] Feature -- added isJSONError type guard
|
|
166
|
+
- fixe and improve types
|
|
47
167
|
|
|
48
168
|
### version 4.0
|
|
49
169
|
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
170
|
+
- [✓] Fix -- latest benchmark tests
|
|
171
|
+
- [✓] Fix -- iterate schema (using typeDefs)
|
|
172
|
+
- [✓] Fix -- scopes per schema-instance
|
|
173
|
+
- [✓] Fix -- insane $ref resolution 'node' can be in 'root/node' or 'root/folder/node'
|
|
174
|
+
- [✓] Refactor -- remove duplication from resolveRef.strict and resolveRef.withOverwrite
|
|
175
|
+
- [✓] Change -- improve function apis (param order, rootSchema per default)
|
|
176
|
+
- [✓] Fix -- `getTemplate` to resolve $ref to infinity
|
|
57
177
|
|
|
58
178
|
**Breaking Changes**
|
|
59
179
|
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
180
|
+
- `iterateSchema` renamed to `eachSchema`
|
|
181
|
+
- `validate` and `isValid` changed signature from (schema, data, [pointer]) to (data, [schema], [pointer])
|
|
182
|
+
- `validateAsync` changed signature from (schema, data, [pointer], [onError]) to (data, [{ schema, pointer, onError }])
|
|
183
|
+
- `getTemplate` changed signature from (schema, data) to (data, [schema])
|
|
184
|
+
- `getSchema` changed signature from (schema, data, [pointer]) to (pointer, [data], [schema])
|
|
185
|
+
- `each` changed signature from (schema, data, [pointer]) to (data, [schema], [pointer])
|
|
186
|
+
- `resolveOneOf` changed signature from (schema, data, [pointer]) to (data, [schema], [pointer])
|
|
187
|
+
- `precompileSchema` renamed to `compileSchema`
|
|
68
188
|
|
|
69
189
|
**Milestone** consistent feature support
|
|
70
190
|
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
191
|
+
- [✓] no side-effects on added remote-schemas
|
|
192
|
+
- [✓] rootSchema should always be compiled
|
|
193
|
+
- [✓] Add missing support for allOf and anyOf type definitions in 'step' and 'getTemplate'
|
|
194
|
+
- [✓] Complete schema support in iterateSchema
|
|
75
195
|
|
|
76
196
|
## 2017
|
|
77
197
|
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
198
|
+
- [~] Features -- Improve validation maps to add & hook (!) custom entries (WIP, Add tests)
|
|
199
|
+
- [✓] Fix -- Return all errors in oneOf-validation
|
|
200
|
+
- [✓] Feature -- Error progress notification for async validation
|
|
201
|
+
- [✓] Refactor -- Keyword validators should only be called for defined keyword
|
|
202
|
+
- [✓] Feature -- getSchema of patternProperties
|
|
83
203
|
|
|
84
204
|
**Milestone** add remaining draft04 features
|
|
85
205
|
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
97
|
-
-
|
|
206
|
+
- [✓] remote references
|
|
207
|
+
- [✓] default format validations
|
|
208
|
+
- [✓] definitions
|
|
209
|
+
- [✓] dependencies
|
|
210
|
+
- [✓] Features -- allOf
|
|
211
|
+
- [✓] Features -- anyOf
|
|
212
|
+
- [✓] Features -- type-array
|
|
213
|
+
- [✓] Features -- patternProperties
|
|
214
|
+
- [✓] Features -- uniqueItems
|
|
215
|
+
- [✓] Features -- oneOf: fail for multiple matching oneof-schemas
|
|
216
|
+
- [✓] Features -- oneOf: for non-arrays
|
|
217
|
+
- [✓] Features -- required (array of properties). Currently every property is required by default
|
|
98
218
|
|
|
99
219
|
## 16/12
|
|
100
220
|
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
221
|
+
- [✓] Testing (validate real json files)
|
|
222
|
+
- [✓] Test + document core differences
|
|
223
|
+
- [✓] Add async validation
|
|
104
224
|
|
|
105
225
|
**Milestone** customizable default and form (json-editor) validation
|
|
106
226
|
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
-
|
|
227
|
+
- [✓] Sanitize Errors
|
|
228
|
+
- [✓] Features -- Add core: Form, fix core: Draft04 - by using separate functions
|
|
229
|
+
- [✓] Add getTemplate to core (resolveOneOf)
|
|
230
|
+
- [✓] Breaking -- Add sort of 'core' to customize validation, stepper, errors etc and reduce requried arguments
|
|
111
231
|
|
|
112
232
|
**Milestone** custom validator (form-validation, oneOfProperty)
|
|
113
233
|
|
|
114
|
-
-
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
234
|
+
- [✓] Features -- additionalProperties: Boolean | Schema
|
|
235
|
+
- [✓] Features -- additionalItems: Boolean | Schema
|
|
236
|
+
- [✓] Features -- Add support for type "integer"
|
|
237
|
+
- [✓] Features -- oneOf -> oneOfProperty ( + Documentation)
|
|
238
|
+
- [✓] Breaking -- change isValid to return boolean
|
|
239
|
+
- [✓] Breaking -- use `step` in isValid -- bad: circular dependencies with step -> guessOneOfSchema -> isValid --X-> step
|
|
240
|
+
- [✓] Features -- items: [] schema (order/defined indices)
|
|
241
|
+
- [✓] Features -- not
|
|
242
|
+
- [✓] Features -- return custom errors in data validation
|
|
243
|
+
- [✓] Basics
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
<div align="center">
|
|
14
|
-
<a href="#overview"><b>Overview</b></a> · <a href="#schemanode-methods"><b>Methods</b></a> · <a href="#draft-customization"><b>Customization</b></a> · <a href="#keyword-extensions"><b>Extensions</b></a> · <a href="
|
|
14
|
+
<a href="#overview"><b>Overview</b></a> · <a href="#schemanode-methods"><b>Methods</b></a> · <a href="#draft-customization"><b>Customization</b></a> · <a href="#keyword-extensions"><b>Extensions</b></a> · <a href="./CHANGELOG.md">Changelog</a>
|
|
15
15
|
</div>
|
|
16
16
|
|
|
17
17
|
---
|
|
@@ -658,6 +658,9 @@ const { node, error } = schemaNode.getNode("/name", { name: 123 }, { createSchem
|
|
|
658
658
|
console.log(node?.schema, error); // { type: "number" }, undefined
|
|
659
659
|
```
|
|
660
660
|
|
|
661
|
+
> [!NOTE]
|
|
662
|
+
> `getChild` will return the reduced node (using `reduceNode` internally) for the given input-data. This means, the resulting json-schema is a merge of all defined JSON schema. For more control use `getChildNode`, which will not further compile JSON schema
|
|
663
|
+
|
|
661
664
|
<details><summary>Example</summary>
|
|
662
665
|
|
|
663
666
|
```ts
|
|
@@ -747,7 +750,7 @@ if (error) {
|
|
|
747
750
|
|
|
748
751
|
### getNodeChild
|
|
749
752
|
|
|
750
|
-
`getNodeChild` retrieves the SchemaNode of a child property or index. Using `
|
|
753
|
+
`getNodeChild` retrieves the SchemaNode of a child property or index. Using `getNodeChild` it is possible to incrementally go through the data, retrieving the schema for each next item.
|
|
751
754
|
|
|
752
755
|
```ts
|
|
753
756
|
const mySchema = { type: "object", properties: { title: { type: "string" } } };
|
|
@@ -1461,133 +1464,3 @@ import settings from "json-schema-library";
|
|
|
1461
1464
|
|
|
1462
1465
|
settings.REGEX_FLAGS = "v";
|
|
1463
1466
|
```
|
|
1464
|
-
|
|
1465
|
-
## Breaking Changes
|
|
1466
|
-
|
|
1467
|
-
### v11.0.1
|
|
1468
|
-
|
|
1469
|
-
- improved error reporting when using oneOfProperty-declarator
|
|
1470
|
-
|
|
1471
|
-
### v11.0.0
|
|
1472
|
-
|
|
1473
|
-
- introduced annotations
|
|
1474
|
-
- added node.createAnnotation helper
|
|
1475
|
-
- changed typing to strict
|
|
1476
|
-
- added annotations-list to `validate()` result
|
|
1477
|
-
- added keyword support for `deprecated: true` which returns a `deprecated-warning` annotation
|
|
1478
|
-
|
|
1479
|
-
**breaking changes**:
|
|
1480
|
-
|
|
1481
|
-
- Return type of validators is now `ValidationReturnType` instead of `ValidationResult`
|
|
1482
|
-
- type `AnnotationData` replaces `ErroData`
|
|
1483
|
-
|
|
1484
|
-
### v10.5.0
|
|
1485
|
-
|
|
1486
|
-
- added support for ref resolution in getSchemaType
|
|
1487
|
-
|
|
1488
|
-
### v10.4.0
|
|
1489
|
-
|
|
1490
|
-
- introduced esm module export
|
|
1491
|
-
- fixed typo in argument ~~disableRecusionLimit~~ disableRecursionLimit
|
|
1492
|
-
- added settings to exports for global changes of settings
|
|
1493
|
-
|
|
1494
|
-
### v10.3.0
|
|
1495
|
-
|
|
1496
|
-
- introduce setting `REGEX_FLAGS` and schema-property `regexFlags` to customize regex flags to use evaluating regex
|
|
1497
|
-
- fixed an issue resolving non-URI compatible $ref-targets containing `#/definitions`
|
|
1498
|
-
|
|
1499
|
-
### v10.2.0
|
|
1500
|
-
|
|
1501
|
-
- introduce getData setting `useTypeDefaults`
|
|
1502
|
-
- introduce support to merge meta-properties using $ref-resolution
|
|
1503
|
-
|
|
1504
|
-
### v10.1.0
|
|
1505
|
-
|
|
1506
|
-
- replaced `node.additionalItems` by `node.items` for drafts below 2020-12
|
|
1507
|
-
- fixed `additionalItems` behaviour to be ignored when `schema.items` is not an array
|
|
1508
|
-
|
|
1509
|
-
### v10.0.0
|
|
1510
|
-
|
|
1511
|
-
> This update involves some significant changes in how you work with the library, so please carefully review the migration guide and adjust your implementation accordingly.
|
|
1512
|
-
|
|
1513
|
-
In version v10.0.0, we've made significant changes to the library’s API, particularly in how we handle drafts and schemas. These changes are required to support features like `dynamicAnchor`, `unevaluatedItems`, and `oneOfIndex` and to integrate with the headless-json-editor. The previous approach of directly working with JSON schema objects lacked the flexibility needed for more advanced features and extensibility.
|
|
1514
|
-
|
|
1515
|
-
The new implementation revolves around compiling schemas into a **SchemaNode** tree. This change offers a more fitting, simpler, and extensible approach to working with JSON schemas.
|
|
1516
|
-
|
|
1517
|
-
#### Key Changes:
|
|
1518
|
-
|
|
1519
|
-
- **Compile Schema**: The `compileSchema` function now replaces the previous Draft-Class approach.
|
|
1520
|
-
- **SchemaNode Representation**: All schemas are now represented as `SchemaNode`, which holds the schema and provides an easier way to work with them.
|
|
1521
|
-
|
|
1522
|
-
#### Breaking Changes:
|
|
1523
|
-
|
|
1524
|
-
**`compileSchema`** is now a standalone function and replaces the `Draft` class. All return values for JSON Schema are now `SchemaNode` objects that contain a `schema` property.
|
|
1525
|
-
|
|
1526
|
-
```ts
|
|
1527
|
-
// PREVIOUSLY
|
|
1528
|
-
const draft = new Draft(schema);
|
|
1529
|
-
|
|
1530
|
-
// NOW
|
|
1531
|
-
const node = compileSchema(schema);
|
|
1532
|
-
```
|
|
1533
|
-
|
|
1534
|
-
**Changed Methods**:
|
|
1535
|
-
|
|
1536
|
-
- `draft.createSchemaOf(schema)` → `node.createSchema(schema)`
|
|
1537
|
-
- `draft.each(data, callback)` → `const nodes = node.toDataNodes(data)`
|
|
1538
|
-
- `draft.eachSchema(callback)` → `const nodes = node.toSchemaNodes()`
|
|
1539
|
-
- `draft.getChildSchemaSelection(property)` → `node.getChildSelection(property)`
|
|
1540
|
-
- `draft.getNode(options)` → `node.getNode(pointer, data, options)`
|
|
1541
|
-
- `draft.getTemplate(inputData)` → `node.getData(inputData)`
|
|
1542
|
-
- `draft.isValid(data)` → `node.validate(data).valid`
|
|
1543
|
-
- `draft.step(property, data)` → `node.getNodeChild(property, data)`
|
|
1544
|
-
|
|
1545
|
-
**Renamed Properties**: `templateDefaultOptions` → `getDataDefaultOptions`
|
|
1546
|
-
|
|
1547
|
-
**Draft Customization**: Customizing drafts has changed completely. The previous methods of extending drafts are no longer valid, and draft handling is now centered around `SchemaNode`.
|
|
1548
|
-
|
|
1549
|
-
**Removed Error Property `name`**: Error property `name` has been removed from `JsonError` in favor of `code`.
|
|
1550
|
-
|
|
1551
|
-
**Removed Configuration Option**: The `templateDefaultOptions` property has been removed from the global settings object. You should now configure it using the `compileSchema` options:
|
|
1552
|
-
|
|
1553
|
-
```ts
|
|
1554
|
-
compileSchema(schema, {
|
|
1555
|
-
getDataDefaultOptions: {
|
|
1556
|
-
addOptionalProps: false,
|
|
1557
|
-
removeInvalidData: false,
|
|
1558
|
-
extendDefaults: true
|
|
1559
|
-
}
|
|
1560
|
-
});
|
|
1561
|
-
```
|
|
1562
|
-
|
|
1563
|
-
**Changed remote $id support** in `addRemoteSchema`. An `$id` has to be a valid url (previously any value was accepted)
|
|
1564
|
-
|
|
1565
|
-
### v9.0.0
|
|
1566
|
-
|
|
1567
|
-
**breaking changes**:
|
|
1568
|
-
|
|
1569
|
-
- _getSchema_ signature changed in favour of an options object. Instead of `draft.getNode(pointer, data)` arguments have to be passed as an object `draft.getNode({ pointer, data })`. This removes setting unwanted optional arguments and keeps the api more stable in the future (e.g. `withSchemaWarning` option)
|
|
1570
|
-
- _JsonError_ now must expose `pointer`, `schema` and `value` consistently on data property
|
|
1571
|
-
|
|
1572
|
-
**updates**
|
|
1573
|
-
|
|
1574
|
-
- _getSchema_ consistently returns errors and can return errors for empty schema using `withSchemaWarning` option
|
|
1575
|
-
|
|
1576
|
-
### v8.0.0
|
|
1577
|
-
|
|
1578
|
-
With version `v8.0.0`, _getData_ was improved to better support optional properties and utilize existing core logic, making it more reliable. Breaking changes:
|
|
1579
|
-
|
|
1580
|
-
- Renamed `JSONError` to `JsonError` and `JSONSchema` to `JsonSchema`
|
|
1581
|
-
- `getData` only adds required properties. Behaviour can be changed by [getData default options](#getData-default-options)
|
|
1582
|
-
- Internal schema property `oneOfSchema` has been replaced by `schema.getOneOfOrigin()`
|
|
1583
|
-
- Changed `unique-items-error` to point to error for duplicated item and changed data-properties
|
|
1584
|
-
- Removed `SchemaService` as it was no longer used nor tested
|
|
1585
|
-
|
|
1586
|
-
<details><summary>Exposed new helper functions</summary>
|
|
1587
|
-
|
|
1588
|
-
- `mergeSchema` - Merges to two json schema
|
|
1589
|
-
- `reduceNode` - Reduce schema by merging dynamic constructs into a static json schema omitting those properties
|
|
1590
|
-
- `isDynamicSchema` - Returns true if the passed schema contains dynamic properties (_if_, _dependencies_, _allOf_, etc)
|
|
1591
|
-
- `resolveDynamicSchema` - Resolves all dynamic schema definitions for the given input data and returns the resulting JSON Schema without any dynamic schema definitions.
|
|
1592
|
-
|
|
1593
|
-
</details>
|