json-schema-library 7.4.6 → 7.4.8
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/README.md +61 -59
- package/dist/jsonSchemaLibrary.js +1 -1
- package/dist/module/lib/step.js +0 -1
- package/dist/module/lib/validation/format.js +1 -1
- package/lib/step.ts +0 -1
- package/lib/validation/format.ts +1 -1
- package/package.json +1 -1
- package/test-result-spec4.json +0 -12753
- package/test-result-spec7.json +0 -20247
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<p
|
|
1
|
+
<p style="text-align:center"><img src="./docs/json-schema-library.png" width="256" alt="json-schema-library"></p>
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
**Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation**
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
> lessens the pain to build custom tools around json-schema.
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
<p
|
|
12
|
+
<p style="text-align:center">
|
|
13
13
|
<a href="#draft-methods">draft methods</a> | <a href="#draft-extensions">draft extensions</a> | <a href="#draft-customization">draft customization</a> | <a href="#breaking-changes">breaking changes</a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
@@ -26,7 +26,7 @@ This library currently supports draft4, draft6 and draft7 features [@see benchma
|
|
|
26
26
|
|
|
27
27
|
**usage**
|
|
28
28
|
|
|
29
|
-
`json-schema-library` exposes a `Draft` for most json-schema drafts. Each `Draft` can be instantiated and offers a common set of actions working on the specified json-schema version.
|
|
29
|
+
`json-schema-library` exposes a `Draft` for most json-schema drafts. Each `Draft` can be instantiated and offers a common set of actions working on the specified json-schema version. Example:
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import { Draft04, Draft06, Draft07, Draft, JSONError } from "json-schema-library";
|
|
@@ -58,25 +58,25 @@ What follows is a description of the main draft methods.
|
|
|
58
58
|
|
|
59
59
|
### validate
|
|
60
60
|
|
|
61
|
-
`validate` is a complete _json-schema validator_ for your input data. Calling _validate_ will return a list of validation errors for the passed data
|
|
61
|
+
`validate` is a complete _json-schema validator_ for your input data. Calling _validate_ will return a list of validation errors for the passed data.
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
64
|
const jsonSchema = new Draft07(myJsonSchema);
|
|
65
65
|
const errors: JSONError[] = jsonSchema.validate(myData);
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
Additionally, you can validate a
|
|
68
|
+
Additionally, you can validate a sub-schema and its data. Doing this, the intial schema will be used as rootSchema (for example, to resolve `$ref` from _definitions_).
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
71
|
const jsonSchema = new Draft07(myJsonSchema);
|
|
72
72
|
const errors: JSONError[] = jsonSchema.validate("my-string", { type: "number" });
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
>
|
|
75
|
+
> To prevent some errors when using helper methods with an independent sub-schema, please use `compileSchema` if it is not retrieved from a draft-method directly (which was compiled by passing it to Draft). Specifically, if the schema contains a $ref you need to use `compileSchema`. More details in [compileSchema](#compileSchema).
|
|
76
76
|
|
|
77
77
|
<details><summary>About type JSONError</summary>
|
|
78
78
|
|
|
79
|
-
In `json-schema-library` all errors are in the format of a `JSONError
|
|
79
|
+
In `json-schema-library` all errors are in the format of a `JSONError`:
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
82
|
type JSONError = {
|
|
@@ -88,7 +88,7 @@ type JSONError = {
|
|
|
88
88
|
};
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
In almost all cases, a _json-pointer_ is given on _error.data.pointer_, which points to the source within data where the error occured.
|
|
92
92
|
|
|
93
93
|
For more details on how to work with errors, refer to section [custom errors](#custom-errors).
|
|
94
94
|
|
|
@@ -155,7 +155,7 @@ expect(errors).to.deep.equal([
|
|
|
155
155
|
|
|
156
156
|
### isValid
|
|
157
157
|
|
|
158
|
-
`isValid` will return
|
|
158
|
+
`isValid` will return `true` if the given json-data is valid against the json-schema.
|
|
159
159
|
|
|
160
160
|
```ts
|
|
161
161
|
const jsonSchema = new Draft07(myJsonSchema);
|
|
@@ -165,9 +165,9 @@ const isValid: boolean = jsonSchema.isValid(myData);
|
|
|
165
165
|
|
|
166
166
|
### validateAsync
|
|
167
167
|
|
|
168
|
-
>
|
|
168
|
+
> This method is not yet exposed by a draft directly as the API of this is yet unsatisfactory. Nonetheless, this function is in production and can be used reliably.
|
|
169
169
|
|
|
170
|
-
Optional support for onError helper, which is invoked for each error (after being resolved)
|
|
170
|
+
Optional support for `onError` helper, which is invoked for each error (after being resolved):
|
|
171
171
|
|
|
172
172
|
```ts
|
|
173
173
|
import { Draft07, JSONError, validateAsync } from "json-schema-library";
|
|
@@ -181,21 +181,21 @@ validateAsync(draft, "", { onError: (err: JSONError) => {}, schema: draft.getSch
|
|
|
181
181
|
|
|
182
182
|
### getTemplate
|
|
183
183
|
|
|
184
|
-
`getTemplate` creates input data from a json-schema that is valid to the schema. Where possible the json-schema
|
|
184
|
+
`getTemplate` 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 user to build up the json-data.
|
|
185
185
|
|
|
186
186
|
```ts
|
|
187
187
|
const jsonSchema = new Draft07(myJsonSchema);
|
|
188
188
|
const myData = jsonSchema.getTemplate();
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
Additionally, you can pass input data. `getTemplate` will then complement any missing values from the schema, while keeping the initial values
|
|
191
|
+
Additionally, you can pass input data. `getTemplate` will then complement any missing values from the schema, while keeping the initial values.
|
|
192
192
|
|
|
193
193
|
```ts
|
|
194
194
|
const jsonSchema = new Draft07(myJsonSchema);
|
|
195
195
|
const myData = jsonSchema.getTemplate({ name: "input-data" });
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
-
**Note
|
|
198
|
+
**Note:** If you are using references in your schema, `getTemplate` will only resolve the first _$ref_ in each path, ensuring no inifinte data structures are created. In case the limit of **1** _$ref_ resolution is too low, you can modify the value globally one by adjusting the json-schema-library settings:
|
|
199
199
|
|
|
200
200
|
```ts
|
|
201
201
|
import { settings } from "json-schema-library";
|
|
@@ -316,7 +316,7 @@ expect(calls).to.deep.equal([
|
|
|
316
316
|
|
|
317
317
|
### eachSchema
|
|
318
318
|
|
|
319
|
-
`eachSchema` emits each sub
|
|
319
|
+
`eachSchema` emits each sub-schema definition to a callback.
|
|
320
320
|
|
|
321
321
|
```ts
|
|
322
322
|
const jsonSchema = new Draft07(mySchema);
|
|
@@ -365,7 +365,7 @@ expect(calls).to.deep.equal([
|
|
|
365
365
|
|
|
366
366
|
### getSchema
|
|
367
367
|
|
|
368
|
-
`getSchema` retrieves the json-schema of a specific location in data. The location in data is given by a _json-pointer_. In many cases the schema can be retrieved without passing the actual data, but in situations where the schema is dynamic
|
|
368
|
+
`getSchema` retrieves the json-schema of a specific location in data. The location in data is given by a _json-pointer_. In many cases the schema can be retrieved without passing the actual data, but in situations where the schema is dynamic (e.g., in _oneOf_, _dependencies_, etc.), the data is required or will return a _JSONError_ if the location cannot be found.
|
|
369
369
|
|
|
370
370
|
```ts
|
|
371
371
|
const jsonSchema = new Draft07(mySchema);
|
|
@@ -388,11 +388,11 @@ const mySchema = {
|
|
|
388
388
|
{
|
|
389
389
|
type: "object",
|
|
390
390
|
required: ["name"],
|
|
391
|
-
properties: {
|
|
392
|
-
name: {
|
|
393
|
-
type: "string",
|
|
394
|
-
title: "name of item"
|
|
395
|
-
}
|
|
391
|
+
properties: {
|
|
392
|
+
name: {
|
|
393
|
+
type: "string",
|
|
394
|
+
title: "name of item"
|
|
395
|
+
}
|
|
396
396
|
}
|
|
397
397
|
},
|
|
398
398
|
{
|
|
@@ -433,16 +433,18 @@ expect(schemaOfItem).to.deep.equal({
|
|
|
433
433
|
|
|
434
434
|
<details><summary>About JSONPointer</summary>
|
|
435
435
|
|
|
436
|
-
**[JSON-Pointer](https://tools.ietf.org/html/rfc6901)** defines a string syntax for identifying a specific value within a JSON document and is [supported by JSON-Schema](https://json-schema.org/understanding-json-schema/structuring.html). Given a JSON document, it behaves similar to a [lodash path](https://lodash.com/docs/4.17.5#get) (`a[0].b.c`), which follows JS-syntax, but instead uses `/` separators
|
|
436
|
+
**[JSON-Pointer](https://tools.ietf.org/html/rfc6901)** defines a string syntax for identifying a specific value within a JSON document and is [supported by JSON-Schema](https://json-schema.org/understanding-json-schema/structuring.html). Given a JSON document, it behaves similar to a [lodash path](https://lodash.com/docs/4.17.5#get) (`a[0].b.c`), which follows JS-syntax, but instead uses `/` separators (e.g., `a/0/b/c`). In the end, you describe a path into the JSON data to a specific point.
|
|
437
437
|
|
|
438
438
|
</details>
|
|
439
439
|
|
|
440
440
|
|
|
441
441
|
### getChildSchemaSelection
|
|
442
442
|
|
|
443
|
-
`getChildSchemaSelection` returns a list of available sub
|
|
443
|
+
`getChildSchemaSelection` returns a list of available sub-schemas for the given property. In many cases, a single schema will be returned. For _oneOf_-schemas, a list of possible options is returned.
|
|
444
|
+
|
|
445
|
+
This helper always returns a list of schemas.
|
|
444
446
|
|
|
445
|
-
**Note
|
|
447
|
+
**Note:** This helper currenly supports a subset of json-schema for multiple results, mainly _oneOf_-definitions
|
|
446
448
|
|
|
447
449
|
```ts
|
|
448
450
|
const jsonSchema = new Draft07(mySchema);
|
|
@@ -475,7 +477,7 @@ expect(schemas).to.deep.equal([
|
|
|
475
477
|
])
|
|
476
478
|
```
|
|
477
479
|
|
|
478
|
-
</details>
|
|
480
|
+
</details>
|
|
479
481
|
|
|
480
482
|
|
|
481
483
|
|
|
@@ -519,11 +521,11 @@ expect(res).to.deep.eq({ type: "number" });
|
|
|
519
521
|
|
|
520
522
|
### addRemoteSchema
|
|
521
523
|
|
|
522
|
-
`addRemoteSchema` lets you add additional schemas that can be referenced by an
|
|
524
|
+
`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.
|
|
523
525
|
|
|
524
526
|
```ts
|
|
525
|
-
const jsonSchema = new Draft07({
|
|
526
|
-
$ref: "http://json-schema.org/draft-07/schema#definitions/nonNegativeInteger"
|
|
527
|
+
const jsonSchema = new Draft07({
|
|
528
|
+
$ref: "http://json-schema.org/draft-07/schema#definitions/nonNegativeInteger"
|
|
527
529
|
});
|
|
528
530
|
jsonSchema.addRemoteSchema("http://json-schema.org/draft-07/schema", draft07Schema);
|
|
529
531
|
```
|
|
@@ -563,7 +565,7 @@ const schema: JSONSchema = jsonSchema.createSchemaOf({ title: "initial value" })
|
|
|
563
565
|
|
|
564
566
|
### compileSchema
|
|
565
567
|
|
|
566
|
-
`compileSchema` adds _$ref_ resolution support to a json-schema. Internally, each draft compiles a passed schema on its own, but when passing additional schemas to individual functions, `compileSchema` has to be called manually for json-schemas containing $
|
|
568
|
+
`compileSchema` adds _$ref_ resolution support to a json-schema. Internally, each draft compiles a passed schema on its own, but when passing additional schemas to individual functions, `compileSchema` has to be called manually for json-schemas containing _$ref_-references.
|
|
567
569
|
|
|
568
570
|
```ts
|
|
569
571
|
const jsonSchema = new Draft07(mySchema);
|
|
@@ -571,7 +573,7 @@ const compiledSchema = jsonSchema.compileSchema({ $ref: "/$defs/table" });
|
|
|
571
573
|
const tableSchema = compiledSchema.getRef();
|
|
572
574
|
```
|
|
573
575
|
|
|
574
|
-
**Note
|
|
576
|
+
**Note:** that `draft.compileSchema` compiles a schema under the current rootSchema. That is, definitions from root schema will be copied to the local schema, to enable _$ref_ resolutions.
|
|
575
577
|
|
|
576
578
|
|
|
577
579
|
## Draft extensions
|
|
@@ -587,9 +589,9 @@ expression, the example will be printed in the error message.
|
|
|
587
589
|
|
|
588
590
|
### oneOfProperty
|
|
589
591
|
|
|
590
|
-
For `oneOf` resolution json-schema states that
|
|
592
|
+
For `oneOf` resolution, json-schema states that data is valid if it validates against exactly one of those sub-schemas. In some scenarios this is unwanted behaviour, as the actual `oneOf` schema is known and only validation errors of this exact sub-schema should be returned.
|
|
591
593
|
|
|
592
|
-
For an explicit `oneOf` resolution the json-schema may be extended by a property `oneOfProperty`. This will always associate an entry with a matching value (instead of schema validation) and return only this schema or validation errors, depending on the current task
|
|
594
|
+
For an explicit `oneOf` resolution, the json-schema may be extended by a property `oneOfProperty`. This will always associate an entry with a matching value (instead of schema validation) and return only this schema or validation errors, depending on the current task. For example:
|
|
593
595
|
|
|
594
596
|
```ts
|
|
595
597
|
const schema = {
|
|
@@ -613,9 +615,9 @@ const schema = {
|
|
|
613
615
|
const resolvedSchema = jsonSchema.resolveOneOf({ id: "2", title: "not a number" }, schema);
|
|
614
616
|
|
|
615
617
|
// will always return (even if invalid)
|
|
616
|
-
expect(resolvedSchema).to.deep.eq({
|
|
617
|
-
type: "object",
|
|
618
|
-
properties: { id: { const: "2" }, title: { type: "number" } }
|
|
618
|
+
expect(resolvedSchema).to.deep.eq({
|
|
619
|
+
type: "object",
|
|
620
|
+
properties: { id: { const: "2" }, title: { type: "number" } }
|
|
619
621
|
});
|
|
620
622
|
```
|
|
621
623
|
|
|
@@ -625,7 +627,7 @@ expect(resolvedSchema).to.deep.eq({
|
|
|
625
627
|
[custom resolvers](#custom-resolvers) | [custom validators](#custom-validators) | [custom errors](#custom-errors)
|
|
626
628
|
|
|
627
629
|
|
|
628
|
-
Each `Draft` in `json-schema-library` is build around a [DraftConfig](./lib/draft/index.ts#19). A `DraftConfig` holds all _functions_ and _configurations_ for each json-schema drafts. The `DraftConfig` is your main way to alter or extend behaviour for `json-schema-library`. You can either create your own _draftConfig_ or adjust any existing _draftConfig_. For the current drafts (4-7), each _draftConfig_ is exposed along with its actual _class_
|
|
630
|
+
Each `Draft` in `json-schema-library` is build around a [DraftConfig](./lib/draft/index.ts#19). A `DraftConfig` holds all _functions_ and _configurations_ for each json-schema drafts. The `DraftConfig` is your main way to alter or extend behaviour for `json-schema-library`. You can either create your own _draftConfig_ or adjust any existing _draftConfig_. For the current drafts (4-7), each _draftConfig_ is exposed along with its actual _class_. For example:
|
|
629
631
|
|
|
630
632
|
```ts
|
|
631
633
|
import { Draft, Draft07, draft07Config } from 'json-schema-library';
|
|
@@ -636,9 +638,9 @@ new Draft07(mySchema, {});
|
|
|
636
638
|
new Draft07(mySchema);
|
|
637
639
|
```
|
|
638
640
|
|
|
639
|
-
|
|
641
|
+
All draft configurations for specific `Draft` classes accept a partial configuration that lets you overwrite default behaviour:
|
|
640
642
|
|
|
641
|
-
> replace the strict resolveOneOf behaviour to use fuzzy search instead:
|
|
643
|
+
> replace the strict `resolveOneOf` behaviour to use fuzzy search instead:
|
|
642
644
|
|
|
643
645
|
```ts
|
|
644
646
|
import { Draft07, draft07Config, resolveOneOfFuzzy } from 'json-schema-library';
|
|
@@ -650,12 +652,12 @@ new Draft({ ...draft07Config, resolveOneOf: resolveOneOfFuzzy }, mySchema);
|
|
|
650
652
|
|
|
651
653
|
### custom resolvers
|
|
652
654
|
|
|
653
|
-
A _resolver_ is a simple method implementing a specific feature of json-schema to retrieve a sub
|
|
655
|
+
A _resolver_ is a simple method implementing a specific feature of json-schema to retrieve a sub-schema. Implementing the signature of each resolver you can create and pass your own resolvers.
|
|
654
656
|
|
|
655
657
|
|
|
656
658
|
#### `resolveRef` with merge
|
|
657
659
|
|
|
658
|
-
The default json-schema behaviour for `$ref` resolution is to replace the schema where a `$ref` is defined. In some scenarios you what to add context
|
|
660
|
+
The default json-schema behaviour for `$ref` resolution is to replace the schema where a `$ref` is defined. In some scenarios you what to add context-specific information (e.g., a specific _title_). For this, a modified `$ref`-resolver is exposed by `json-schema-library`:
|
|
659
661
|
|
|
660
662
|
```ts
|
|
661
663
|
import { Draft07, draft07Config, resolveRefMerge } from 'json-schema-library';
|
|
@@ -664,7 +666,7 @@ const jsonSchema = new Draft07(mySchema, { resolveRef: resolveRefMerge });
|
|
|
664
666
|
|
|
665
667
|
`resolveRefMerge` performs a shallow merge (first level of properties), adding the local schemas properties last.
|
|
666
668
|
|
|
667
|
-
**
|
|
669
|
+
**Caution:** With this resolver, it is possible to overwrite json-schema behavioural properties. Treat with care.
|
|
668
670
|
|
|
669
671
|
<details><summary>Example</summary>
|
|
670
672
|
|
|
@@ -700,7 +702,7 @@ expect(subHeaderSchema).to.eq({
|
|
|
700
702
|
|
|
701
703
|
#### `resolveOneOf` fuzzy search
|
|
702
704
|
|
|
703
|
-
The default json-schema behaviour for `oneOf` resolution is to validate all contained _oneOf_-schemas and return the one schema that validates against the given input data. If no item validates completely an error returned, containing all validation errors of all schemas. When you are interested in the actual error (
|
|
705
|
+
The default json-schema behaviour for `oneOf` resolution is to validate all contained _oneOf_-schemas and return the one schema that validates against the given input data. If no item validates completely an error returned, containing all validation errors of all schemas. When you are interested in the actual error (rather than simply determining “Is the data is valid or not?”), this is behaviour is not very helpful as the result is hard to read.
|
|
704
706
|
|
|
705
707
|
`json-schema-library` exposes a method `resolveOneOfFuzzy`, which will return a single schema in cases where no valid schema could be resolved. `resolveOneOfFuzzy` uses a simple scoring mechanism to return the best fitting schema for the given input data. Thus, `resolveOneOfFuzzy` may return schemas that do not validate a given input data.
|
|
706
708
|
|
|
@@ -712,15 +714,15 @@ const jsonSchema = new Draft07(mySchema, { resolveOneOf: resolveOneOfFuzzy });
|
|
|
712
714
|
|
|
713
715
|
### custom validators
|
|
714
716
|
|
|
715
|
-
All json-schema validation is done using validator functions for _keywords_ and _formats_.
|
|
717
|
+
All json-schema validation is done using validator functions for _keywords_ and _formats_.
|
|
716
718
|
|
|
717
|
-
**keyword validators** are called for each keyword defined on a json-schema,
|
|
719
|
+
**keyword validators** are called for each keyword defined on a json-schema. For example, the following schema will run two keyword-validators (one for `items` and one of `minItems`) which are defined in `draft.validateKeyword.items` and `draft.validateKeyword.minItems`.
|
|
718
720
|
|
|
719
721
|
```ts
|
|
720
722
|
{ type: "object", items: {}, minItems: 1 }
|
|
721
723
|
```
|
|
722
724
|
|
|
723
|
-
Since valid json-schema keywords vary by their `type` an additional mapping registers, which keyword should be tested per schema-type. This mapping is defined in `draft.typeKeywords
|
|
725
|
+
Since valid json-schema keywords vary by their `type` an additional mapping registers, which keyword should be tested per schema-type. This mapping is defined in `draft.typeKeywords`:
|
|
724
726
|
|
|
725
727
|
```ts
|
|
726
728
|
import { draft07Config } from "json-schema-library";
|
|
@@ -732,7 +734,7 @@ console.log(draft07Config.typeKeywords.array);
|
|
|
732
734
|
|
|
733
735
|
> The keyword **format** is also registered in `draft.validateKeyword.format`, but each actual format validation is defined as follows:
|
|
734
736
|
|
|
735
|
-
**format validators** are called on each
|
|
737
|
+
**format validators** are called on each occurrence of a property format in a json-schema. In the next example, the schema will run the _email_-validator given in `draft.validateFormat.email`:
|
|
736
738
|
|
|
737
739
|
```ts
|
|
738
740
|
{ type: "string", format: "email" }
|
|
@@ -740,9 +742,9 @@ console.log(draft07Config.typeKeywords.array);
|
|
|
740
742
|
|
|
741
743
|
#### add custom keyword validator
|
|
742
744
|
|
|
743
|
-
To add or overwrite a keyword validator you
|
|
745
|
+
To add or overwrite a keyword validator, you must add a validator function on your draft config in `validateKeyword`.
|
|
744
746
|
|
|
745
|
-
|
|
747
|
+
Using specific Draft configuration, where draft configuration objects will be merged:
|
|
746
748
|
|
|
747
749
|
```ts
|
|
748
750
|
import { Draft07, JSONValidator } from "json-schema-library";
|
|
@@ -759,7 +761,7 @@ const jsonSchema = new Draft07(mySchema, {
|
|
|
759
761
|
});
|
|
760
762
|
```
|
|
761
763
|
|
|
762
|
-
|
|
764
|
+
**Example:** Manually extending draft configuration:
|
|
763
765
|
|
|
764
766
|
```ts
|
|
765
767
|
import { Draft, draft07Config, JSONValidator } from "json-schema-library";
|
|
@@ -785,7 +787,7 @@ const jsonSchema = new Draft(myDraftConfiguration, mySchema);
|
|
|
785
787
|
|
|
786
788
|
#### add custom format validator
|
|
787
789
|
|
|
788
|
-
To add or overwrite a format validator you
|
|
790
|
+
To add or overwrite a format validator you must add a validator function on your draft config in `validateFormat`.
|
|
789
791
|
|
|
790
792
|
```ts
|
|
791
793
|
import { Draft07, JSONValidator } from "json-schema-library";
|
|
@@ -818,10 +820,10 @@ Each error message in `config.strings` receives the `data`-property of an error.
|
|
|
818
820
|
import { render } from "json-schema-library";
|
|
819
821
|
|
|
820
822
|
render(
|
|
821
|
-
"Expected given value `{{value}}` in `{{pointer}}` to be one of `{{values}}`",
|
|
823
|
+
"Expected given value `{{value}}` in `{{pointer}}` to be one of `{{values}}`",
|
|
822
824
|
{ pointer: "[A]", value: "[B]" }
|
|
823
825
|
);
|
|
824
|
-
// "Expected given value `[B]` in `[A]` to be one of ``"
|
|
826
|
+
// "Expected given value `[B]` in `[A]` to be one of ``"
|
|
825
827
|
```
|
|
826
828
|
|
|
827
829
|
|
|
@@ -864,16 +866,16 @@ const error: JSONError = createError("EnumError", { data: { pointer: "#/location
|
|
|
864
866
|
|
|
865
867
|
### v7.0.0
|
|
866
868
|
|
|
867
|
-
|
|
869
|
+
With version `v7.0.0`, library export and Draft API has changed heavily. The API is now more consistent across draft-versions and offers a simple and consistent configuration interface for existing and custom drafts. In addition, most standalone functions are no longer exposed separately, but under its current _draftConfigs_ and mainly on each draft-instance. This will help to reduce confusion when consuming this API.
|
|
868
870
|
|
|
869
|
-
The above documentation reflects all
|
|
871
|
+
The above documentation reflects all these changes. Just reach out if you have troubles migrating to the latest version.
|
|
870
872
|
|
|
871
|
-
<details><summary>Details
|
|
873
|
+
<details><summary>Details of breaking changes</summary>
|
|
872
874
|
|
|
873
875
|
- replaced `Core` interface by new `Draft` interface
|
|
874
876
|
- changed export of `Interface` to `Draft`
|
|
875
877
|
- renamed `addSchema` to `addRemoteSchema`
|
|
876
|
-
- changed
|
|
878
|
+
- changed API of `compileSchema` to have an additional schema-parameter for rootSchema reference
|
|
877
879
|
- changed `compileSchema` and `addRemoteSchema` to work on instance state, instead of global state
|
|
878
880
|
- `addRemoteSchema`, `compileSchema` now requires draft instance as first parameter
|
|
879
881
|
- 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
|
|
@@ -884,14 +886,14 @@ The above documentation reflects all those changes. Just reach out if you have t
|
|
|
884
886
|
|
|
885
887
|
### v6.0.0
|
|
886
888
|
|
|
887
|
-
|
|
889
|
+
With version `v6.0.0` supported json schema drafts are exported directly as `Draft04`, `Draft06`, `Draft07`. Example use: `import { Draft07 } from "json-schema-library"`.
|
|
888
890
|
|
|
889
891
|
|
|
890
892
|
### v5.0.0
|
|
891
893
|
|
|
892
|
-
|
|
894
|
+
With version `v5.0.0` the API has changed to es6 modules, where there is no `default` export, only named exports. Additionally all code has been rewritten in TypeScript. When directly accessing files, switch to `dist/module/*.js`-files for plain js-modules.
|
|
893
895
|
|
|
894
896
|
|
|
895
897
|
### v4.0.0
|
|
896
898
|
|
|
897
|
-
|
|
899
|
+
With version `v4.0.0` the API has changed in order to use the defined (root) schema in draft as default where possible. This means most methods have a changed signature, where `data` is passed before an optional `schema` argument.
|