json-schema-library 10.0.0 → 10.1.0
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 +36 -31
- package/dist/jsonSchemaLibrary.js +1 -1
- package/dist/module/src/draft2019-09/keywords/additionalItems.js +7 -10
- package/dist/module/src/draft2019-09/keywords/items.js +4 -3
- package/dist/module/src/draft2019-09/methods/getChildSelection.js +3 -4
- package/dist/module/src/draft2019-09/methods/getData.js +4 -5
- package/dist/module/src/mergeNode.js +0 -1
- package/dist/module/src/methods/toSchemaNodes.js +0 -1
- package/dist/src/SchemaNode.d.ts +33 -2
- package/package.json +1 -1
- package/src/SchemaNode.ts +33 -2
- package/src/draft2019-09/keywords/additionalItems.ts +7 -10
- package/src/draft2019-09/keywords/items.ts +3 -3
- package/src/draft2019-09/methods/getChildSchemaSelection.test.ts +2 -0
- package/src/draft2019-09/methods/getChildSelection.ts +3 -4
- package/src/draft2019-09/methods/getData.test.ts +1 -0
- package/src/draft2019-09/methods/getData.ts +4 -5
- package/src/mergeNode.ts +0 -1
- package/src/methods/toSchemaNodes.ts +0 -1
package/README.md
CHANGED
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
|
-
> ⚠️ This **documentation** refers to the upcoming release **version 10**, which can be installed by `npm install json-schema-library@10.0.0-rc13`. For the latest release please refer to the **[documentation of version 9.3.5](https://github.com/sagold/json-schema-library/tree/v9.3.5)**. If you are on v10-rc refer to [documentation of version 10.0.0-rc8 or lower](https://github.com/sagold/json-schema-library/tree/v10.0.0-rc8)
|
|
20
|
-
|
|
21
19
|
**Quick start**
|
|
22
20
|
|
|
23
21
|
`npm install json-schema-library`
|
|
@@ -1057,9 +1055,10 @@ const myDraft = extendDraft(draft2020, {
|
|
|
1057
1055
|
});
|
|
1058
1056
|
```
|
|
1059
1057
|
|
|
1060
|
-
|
|
1061
1058
|
### Overwrite a format validator
|
|
1059
|
+
|
|
1062
1060
|
The built-in format validators may not always align with your specific requirements. For instance, you might need to validate the output of an `<input type="time" />`, which produces values in formats like `HH:MM` or `HH:MM:SS`. In such cases, you can customize or overwrite the format validators to suit your needs using `extendDraft`
|
|
1061
|
+
|
|
1063
1062
|
<details>
|
|
1064
1063
|
<summary>Example of overwriting a format validator</summary>
|
|
1065
1064
|
|
|
@@ -1069,7 +1068,7 @@ import { extendDraft, draft2020 } from "json-schema-library";
|
|
|
1069
1068
|
/**
|
|
1070
1069
|
* A Regexp that extends http://tools.ietf.org/html/rfc3339#section-5.6 spec.
|
|
1071
1070
|
* The specification requires seconds and timezones to be a valid date format.
|
|
1072
|
-
*
|
|
1071
|
+
*
|
|
1073
1072
|
* matchTimeSecondsAndTimeOptional matches:
|
|
1074
1073
|
* - HH:MM:SSz
|
|
1075
1074
|
* - HH:MM:SS(+/-)HH:MM
|
|
@@ -1078,41 +1077,42 @@ import { extendDraft, draft2020 } from "json-schema-library";
|
|
|
1078
1077
|
* - HH:MM(+/-)HH:MM
|
|
1079
1078
|
* - HH:MM
|
|
1080
1079
|
*/
|
|
1081
|
-
const matchTimeSecondsAndTimeOptional =
|
|
1080
|
+
const matchTimeSecondsAndTimeOptional =
|
|
1082
1081
|
/^(?<time>(?:([0-1]\d|2[0-3]):[0-5]\d(:(?<second>[0-5]\d|60))?))(?:\.\d+)?(?<offset>(?:z|[+-]([0-1]\d|2[0-3])(?::?[0-5]\d)?)?)$/i;
|
|
1083
|
-
|
|
1084
1082
|
|
|
1085
1083
|
const customTimeFormatDraft = extendDraft(draft2020, {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
// Use the Custom Regex to validate the date and time.
|
|
1095
|
-
const matches = data.match(matchTimeSecondsAndTimeOptional);
|
|
1096
|
-
if (!matches) {
|
|
1097
|
-
return node.createError("format-date-time-error", { value: data, pointer, schema });
|
|
1098
|
-
}
|
|
1084
|
+
formats: {
|
|
1085
|
+
// This example extends the default time formatter which validates against RFC3339
|
|
1086
|
+
time: ({ node, pointer, data }) => {
|
|
1087
|
+
const { schema } = node;
|
|
1088
|
+
if (typeof data !== "string" || data === "") {
|
|
1089
|
+
return undefined;
|
|
1090
|
+
}
|
|
1099
1091
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1092
|
+
// Use the Custom Regex to validate the date and time.
|
|
1093
|
+
const matches = data.match(matchTimeSecondsAndTimeOptional);
|
|
1094
|
+
if (!matches) {
|
|
1095
|
+
return node.createError("format-date-time-error", { value: data, pointer, schema });
|
|
1096
|
+
}
|
|
1104
1097
|
|
|
1105
|
-
|
|
1106
|
-
|
|
1098
|
+
// leap second
|
|
1099
|
+
if (matches.groups.second === "60") {
|
|
1100
|
+
// Omitted the code here for brevity.
|
|
1101
|
+
}
|
|
1107
1102
|
|
|
1108
|
-
|
|
1103
|
+
return undefined;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1109
1106
|
});
|
|
1110
1107
|
|
|
1111
|
-
const { errors, valid } = compileSchema(
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1108
|
+
const { errors, valid } = compileSchema(
|
|
1109
|
+
{
|
|
1110
|
+
type: "string",
|
|
1111
|
+
format: "time",
|
|
1112
|
+
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
1113
|
+
},
|
|
1114
|
+
{ drafts: [customTimeFormatDraft] }
|
|
1115
|
+
).validate("15:31:12");
|
|
1116
1116
|
|
|
1117
1117
|
console.assert(valid, errors.at(0)?.message);
|
|
1118
1118
|
```
|
|
@@ -1294,6 +1294,11 @@ assert.deepEqual(errors[0].message, "Custom error 2");
|
|
|
1294
1294
|
|
|
1295
1295
|
## Breaking Changes
|
|
1296
1296
|
|
|
1297
|
+
### v10.1.0
|
|
1298
|
+
|
|
1299
|
+
- replaced `node.additionalItems` by `node.items` for drafts below 2020-12
|
|
1300
|
+
- fixed `additionalItems` behaviour to be ignored when `schema.items` is not an array
|
|
1301
|
+
|
|
1297
1302
|
### v10.0.0
|
|
1298
1303
|
|
|
1299
1304
|
> 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.
|