json-schema-library 11.1.0 → 11.2.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/.mocharc.js +1 -0
- package/CHANGELOG.md +6 -0
- package/README.md +21 -13
- package/bowtie/.editorconfig +21 -0
- package/bowtie/.prettierrc +6 -0
- package/bowtie/BOWTIE.md +54 -0
- package/bowtie/Dockerfile +6 -0
- package/bowtie/bowtie-api.ts +101 -0
- package/bowtie/bowtie.test.ts +76 -0
- package/bowtie/bowtie.ts +156 -0
- package/bowtie/package.json +11 -0
- package/bowtie/tsconfig.json +12 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -514
- package/dist/index.d.mts +6 -514
- package/dist/index.mjs +1 -1
- package/dist/jlib.js +2 -13
- package/dist/remotes/index.cjs +1 -0
- package/dist/remotes/index.d.cts +7 -0
- package/dist/remotes/index.d.mts +7 -0
- package/dist/remotes/index.mjs +1 -0
- package/dist/types-B2wwNWyo.d.cts +513 -0
- package/dist/types-BhTU1l2h.d.mts +513 -0
- package/index.ts +0 -3
- package/package.json +14 -8
- package/src/Draft.ts +1 -1
- package/src/Keyword.ts +2 -3
- package/src/SchemaNode.ts +9 -0
- package/src/compileSchema.ts +4 -1
- package/src/draft04/keywords/$ref.ts +22 -14
- package/src/draft04/keywords/exclusiveMaximum.ts +14 -0
- package/src/draft04/keywords/exclusiveMinimum.ts +14 -0
- package/src/draft04/validateSchema.test.ts +20 -0
- package/src/draft06/keywords/$ref.ts +15 -5
- package/src/draft2019-09/keywords/$ref.test.ts +3 -1
- package/src/draft2019-09/keywords/$ref.ts +40 -16
- package/src/draft2019-09/keywords/additionalItems.ts +33 -10
- package/src/draft2019-09/keywords/items.ts +32 -10
- package/src/draft2019-09/keywords/unevaluatedItems.ts +19 -6
- package/src/draft2019-09/methods/getData.ts +1 -1
- package/src/draft2019-09/validateSchema.test.ts +28 -0
- package/src/errors/errors.ts +4 -0
- package/src/formats/formats.ts +35 -28
- package/src/formats/hyperjump.d.ts +172 -0
- package/src/keywords/$ref.ts +47 -13
- package/src/keywords/properties.ts +1 -1
- package/src/keywords/propertyDependencies.ts +1 -1
- package/src/methods/getData.ts +1 -1
- package/src/validateNode.ts +4 -1
- package/tsconfig.json +11 -4
- package/tsconfig.test.json +9 -2
- package/tsdown.config.ts +1 -1
- package/Dockerfile +0 -6
- package/bowtie_jlib.js +0 -140
- package/remotes/draft04.json +0 -150
- package/remotes/draft06.json +0 -155
- package/remotes/draft07.json +0 -155
- package/remotes/draft2019-09.json +0 -42
- package/remotes/draft2019-09_meta_applicator.json +0 -53
- package/remotes/draft2019-09_meta_content.json +0 -14
- package/remotes/draft2019-09_meta_core.json +0 -54
- package/remotes/draft2019-09_meta_format.json +0 -11
- package/remotes/draft2019-09_meta_meta-data.json +0 -34
- package/remotes/draft2019-09_meta_validation.json +0 -95
- package/remotes/draft2020-12.json +0 -55
- package/remotes/draft2020-12_meta_applicator.json +0 -45
- package/remotes/draft2020-12_meta_content.json +0 -14
- package/remotes/draft2020-12_meta_core.json +0 -48
- package/remotes/draft2020-12_meta_format_annotation.json +0 -11
- package/remotes/draft2020-12_meta_format_assertion.json +0 -11
- package/remotes/draft2020-12_meta_meta_data.json +0 -34
- package/remotes/draft2020-12_meta_unevaluated.json +0 -12
- package/remotes/draft2020-12_meta_validation.json +0 -87
- package/remotes/index.ts +0 -48
package/src/formats/formats.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/* eslint-disable no-control-regex */
|
|
2
|
-
import {
|
|
2
|
+
import { isAsciiIdn, isUri, isIdnEmail, isIri, isIriReference, isIdn } from "@hyperjump/json-schema-formats";
|
|
3
3
|
import validUrl from "valid-url";
|
|
4
|
+
import { getTypeOf } from "../utils/getTypeOf";
|
|
4
5
|
import { JsonSchemaValidatorParams, ValidationReturnType } from "../Keyword";
|
|
5
|
-
import { parse as parseIdnEmail } from "smtp-address-parser";
|
|
6
6
|
import settings from "../settings";
|
|
7
7
|
|
|
8
8
|
const { REGEX_FLAGS } = settings;
|
|
9
9
|
const isValidIPV4 = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
|
|
10
10
|
const isValidIPV6 =
|
|
11
11
|
/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
|
|
12
|
-
const isValidHostname =
|
|
13
|
-
/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/;
|
|
14
12
|
const matchDate = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
15
13
|
const matchTime =
|
|
16
14
|
/^(?<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;
|
|
@@ -129,33 +127,30 @@ export const formats: Record<string, (options: JsonSchemaValidatorParams) => Val
|
|
|
129
127
|
return undefined;
|
|
130
128
|
},
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
* @draft 7
|
|
134
|
-
* [RFC6531] https://json-schema.org/draft-07/json-schema-validation.html#RFC6531
|
|
135
|
-
*/
|
|
136
|
-
"idn-email": ({ node, pointer, data }) => {
|
|
130
|
+
hostname: ({ node, pointer, data }) => {
|
|
137
131
|
const { schema } = node;
|
|
138
|
-
if (typeof data !== "string" || data
|
|
132
|
+
if (typeof data !== "string" || isAsciiIdn(data)) {
|
|
139
133
|
return undefined;
|
|
140
134
|
}
|
|
141
|
-
|
|
142
|
-
parseIdnEmail(data);
|
|
143
|
-
return undefined;
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
145
|
-
} catch (e) {
|
|
146
|
-
return node.createError("format-email-error", { value: data, pointer, schema });
|
|
147
|
-
}
|
|
135
|
+
return node.createError("format-hostname-error", { value: data, pointer, schema });
|
|
148
136
|
},
|
|
149
137
|
|
|
150
|
-
hostname: ({ node, pointer, data }) => {
|
|
151
|
-
|
|
152
|
-
if (typeof data !== "string") {
|
|
138
|
+
"idn-hostname": ({ node, pointer, data }) => {
|
|
139
|
+
if (typeof data !== "string" || isIdn(data)) {
|
|
153
140
|
return undefined;
|
|
154
141
|
}
|
|
155
|
-
|
|
142
|
+
return node.createError("format-idn-hostname-error", { value: data, pointer, schema: node.schema });
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @draft 7
|
|
147
|
+
* [RFC6531] https://json-schema.org/draft-07/json-schema-validation.html#RFC6531
|
|
148
|
+
*/
|
|
149
|
+
"idn-email": ({ node, pointer, data }) => {
|
|
150
|
+
if (typeof data !== "string" || data === "" || isIdnEmail(data)) {
|
|
156
151
|
return undefined;
|
|
157
152
|
}
|
|
158
|
-
return node.createError("format-
|
|
153
|
+
return node.createError("format-email-error", { value: data, pointer, schema: node.schema });
|
|
159
154
|
},
|
|
160
155
|
|
|
161
156
|
ipv4: ({ node, pointer, data }) => {
|
|
@@ -188,6 +183,22 @@ export const formats: Record<string, (options: JsonSchemaValidatorParams) => Val
|
|
|
188
183
|
return node.createError("format-ipv6-error", { value: data, pointer, schema });
|
|
189
184
|
},
|
|
190
185
|
|
|
186
|
+
iri: ({ node, pointer, data }) => {
|
|
187
|
+
const { schema } = node;
|
|
188
|
+
if (typeof data !== "string" || data === "" || isIri(data)) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
return node.createError("format-iri-error", { value: data, pointer, schema });
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
"iri-reference": ({ node, pointer, data }) => {
|
|
195
|
+
const { schema } = node;
|
|
196
|
+
if (typeof data !== "string" || data === "" || isIriReference(data)) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
return node.createError("format-iri-reference-error", { value: data, pointer, schema });
|
|
200
|
+
},
|
|
201
|
+
|
|
191
202
|
"json-pointer": ({ node, pointer, data }) => {
|
|
192
203
|
const { schema } = node;
|
|
193
204
|
if (typeof data !== "string" || data === "") {
|
|
@@ -281,14 +292,10 @@ export const formats: Record<string, (options: JsonSchemaValidatorParams) => Val
|
|
|
281
292
|
},
|
|
282
293
|
|
|
283
294
|
uri: ({ node, pointer, data }) => {
|
|
284
|
-
|
|
285
|
-
if (typeof data !== "string" || data === "") {
|
|
286
|
-
return undefined;
|
|
287
|
-
}
|
|
288
|
-
if (validUrl.isUri(data)) {
|
|
295
|
+
if (typeof data !== "string" || data === "" || isUri(data)) {
|
|
289
296
|
return undefined;
|
|
290
297
|
}
|
|
291
|
-
return node.createError("format-uri-error", { value: data, pointer, schema });
|
|
298
|
+
return node.createError("format-uri-error", { value: data, pointer, schema: node.schema });
|
|
292
299
|
},
|
|
293
300
|
|
|
294
301
|
"uri-reference": ({ node, pointer, data }) => {
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
declare module "@hyperjump/json-schema-formats" {
|
|
2
|
+
/**
|
|
3
|
+
* The 'date' format. Validates that a string represents a date according to
|
|
4
|
+
* [RFC 3339, section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6).
|
|
5
|
+
*
|
|
6
|
+
* @see [JSON Schema Core, section 7.3.1](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.1)
|
|
7
|
+
*/
|
|
8
|
+
export const isDate: (date: string) => boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The 'time' format. Validates that a string represents a time according to
|
|
12
|
+
* [RFC 3339, section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6).
|
|
13
|
+
*
|
|
14
|
+
* **NOTE**: Leap seconds are only allowed on specific dates. Since there is no date
|
|
15
|
+
* in this context, leap seconds are never allowed.
|
|
16
|
+
*
|
|
17
|
+
* @see [JSON Schema Core, section 7.3.1](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.1)
|
|
18
|
+
*/
|
|
19
|
+
export const isTime: (time: string) => boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The 'date-time' format. Validates that a string represents a date-time
|
|
23
|
+
* according to [RFC 3339, section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6).
|
|
24
|
+
*
|
|
25
|
+
* @see [JSON Schema Core, section 7.3.1](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.1)
|
|
26
|
+
*/
|
|
27
|
+
export const isDateTime: (dateTime: string) => boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The 'duration' format. Validates that a string represents a duration
|
|
31
|
+
* according to [RFC 3339, Appendix A](https://www.rfc-editor.org/rfc/rfc3339.html#appendix-A).
|
|
32
|
+
*
|
|
33
|
+
* @see [JSON Schema Core, section 7.3.1](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.1)
|
|
34
|
+
*/
|
|
35
|
+
export const isDuration: (duration: string) => boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The 'email' format. Validates that a string represents an email as defined by
|
|
39
|
+
* the "Mailbox" ABNF rule in [RFC 5321, section 4.1.2](https://www.rfc-editor.org/rfc/rfc5321.html#section-4.1.2).
|
|
40
|
+
*
|
|
41
|
+
* @see [JSON Schema Core, section 7.3.2](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.2)
|
|
42
|
+
*/
|
|
43
|
+
export const isEmail: (email: string) => boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The 'idn-email' format. Validates that a string represents an email as
|
|
47
|
+
* defined by the "Mailbox" ABNF rule in [RFC 6531, section 3.3](https://www.rfc-editor.org/rfc/rfc6531.html#section-3.3).
|
|
48
|
+
*
|
|
49
|
+
* @see [JSON Schema Core, section 7.3.2](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.2)
|
|
50
|
+
*/
|
|
51
|
+
export const isIdnEmail: (email: string) => boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The 'hostname' format in draft-04 - draft-06. Validates that a string
|
|
55
|
+
* represents a hostname as defined by [RFC 1123, section 2.1](https://www.rfc-editor.org/rfc/rfc1123.html#section-2.1).
|
|
56
|
+
*
|
|
57
|
+
* **NOTE**: The 'hostname' format changed in draft-07. Use {@link isAsciiIdn} for
|
|
58
|
+
* draft-07 and later.
|
|
59
|
+
*
|
|
60
|
+
* @see [JSON Schema Core, section 7.3.3](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.3)
|
|
61
|
+
*/
|
|
62
|
+
export const isHostname: (hostname: string) => boolean;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The 'hostname' format since draft-07. Validates that a string represents an
|
|
66
|
+
* IDNA2008 internationalized domain name consiting of only A-labels and NR-LDH
|
|
67
|
+
* labels as defined by [RFC 5890, section 2.3.2.1](https://www.rfc-editor.org/rfc/rfc5890.html#section-2.3.2.3).
|
|
68
|
+
*
|
|
69
|
+
* **NOTE**: The 'hostname' format changed in draft-07. Use {@link isHostname}
|
|
70
|
+
* for draft-06 and earlier.
|
|
71
|
+
*
|
|
72
|
+
* @see [JSON Schema Core, section 7.3.3](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.3)
|
|
73
|
+
*/
|
|
74
|
+
export const isAsciiIdn: (hostname: string) => boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The 'idn-hostname' format. Validates that a string represents an IDNA2008
|
|
78
|
+
* internationalized domain name as defined by [RFC 5890, section 2.3.2.1](https://www.rfc-editor.org/rfc/rfc5890.html#section-2.3.2.1).
|
|
79
|
+
*
|
|
80
|
+
* @see [JSON Schema Core, section 7.3.3](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.3)
|
|
81
|
+
*/
|
|
82
|
+
export const isIdn: (hostname: string) => boolean;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The 'ipv4' format. Validates that a string represents an IPv4 address
|
|
86
|
+
* according to the "dotted-quad" ABNF syntax as defined in
|
|
87
|
+
* [RFC 2673, section 3.2](https://www.rfc-editor.org/rfc/rfc2673.html#section-3.2).
|
|
88
|
+
*
|
|
89
|
+
* @see [JSON Schema Core, section 7.3.4](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.4)
|
|
90
|
+
*/
|
|
91
|
+
export const isIPv4: (ip: string) => boolean;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The 'ipv6' format. Validates that a string represents an IPv6 address as
|
|
95
|
+
* defined in [RFC 4291, section 2.2](https://www.rfc-editor.org/rfc/rfc4291.html#section-2.2).
|
|
96
|
+
*
|
|
97
|
+
* @see [JSON Schema Core, section 7.3.4](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.4)
|
|
98
|
+
*/
|
|
99
|
+
export const isIPv6: (ip: string) => boolean;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The 'uri' format. Validates that a string represents a URI as defined by [RFC
|
|
103
|
+
* 3986](https://www.rfc-editor.org/rfc/rfc3986.html).
|
|
104
|
+
*
|
|
105
|
+
* @see [JSON Schema Core, section 7.3.5](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.5)
|
|
106
|
+
*/
|
|
107
|
+
export const isUri: (uri: string) => boolean;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The 'uri-reference' format. Validates that a string represents a URI
|
|
111
|
+
* Reference as defined by [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986.html).
|
|
112
|
+
*
|
|
113
|
+
* @see [JSON Schema Core, section 7.3.5](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.5)
|
|
114
|
+
*/
|
|
115
|
+
export const isUriReference: (uri: string) => boolean;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The 'iri' format. Validates that a string represents an IRI as defined by
|
|
119
|
+
* [RFC 3987](https://www.rfc-editor.org/rfc/rfc3987.html).
|
|
120
|
+
*
|
|
121
|
+
* @see [JSON Schema Core, section 7.3.5](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.5)
|
|
122
|
+
*/
|
|
123
|
+
export const isIri: (iri: string) => boolean;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The 'iri-reference' format. Validates that a string represents an IRI
|
|
127
|
+
* Reference as defined by [RFC 3987](https://www.rfc-editor.org/rfc/rfc3987.html).
|
|
128
|
+
*
|
|
129
|
+
* @see [JSON Schema Core, section 7.3.5](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.5)
|
|
130
|
+
*/
|
|
131
|
+
export const isIriReference: (iri: string) => boolean;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The 'uuid' format. Validates that a string represents a UUID address as
|
|
135
|
+
* defined by [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.html).
|
|
136
|
+
*
|
|
137
|
+
* @see [JSON Schema Core, section 7.3.5](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.5)
|
|
138
|
+
*/
|
|
139
|
+
export const isUuid: (uuid: string) => boolean;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The 'uri-template' format. Validates that a string represents a URI Template
|
|
143
|
+
* as defined by [RFC 6570](https://www.rfc-editor.org/rfc/rfc6570.html).
|
|
144
|
+
*
|
|
145
|
+
* @see [JSON Schema Core, section 7.3.6](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.6)
|
|
146
|
+
*/
|
|
147
|
+
export const isUriTemplate: (uriTemplate: string) => boolean;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The 'json-pointer' format. Validates that a string represents a JSON Pointer
|
|
151
|
+
* as defined by [RFC 6901](https://www.rfc-editor.org/rfc/rfc6901.html).
|
|
152
|
+
*
|
|
153
|
+
* @see [JSON Schema Core, section 7.3.7](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.7)
|
|
154
|
+
*/
|
|
155
|
+
export const isJsonPointer: (pointer: string) => boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The 'relative-json-pointer' format. Validates that a string represents an IRI
|
|
159
|
+
* Reference as defined by [draft-bhutton-relative-json-pointer-00](https://datatracker.ietf.org/doc/html/draft-bhutton-relative-json-pointer-00).
|
|
160
|
+
*
|
|
161
|
+
* @see [JSON Schema Core, section 7.3.5](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.5)
|
|
162
|
+
*/
|
|
163
|
+
export const isRelativeJsonPointer: (pointer: string) => boolean;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The 'regex' format. Validates that a string represents a regular expression
|
|
167
|
+
* as defined by [ECMA-262](https://262.ecma-international.org/5.1/).
|
|
168
|
+
*
|
|
169
|
+
* @see [JSON Schema Core, section 7.3.8](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3.8)
|
|
170
|
+
*/
|
|
171
|
+
export const isRegex: (regex: string) => boolean;
|
|
172
|
+
}
|
package/src/keywords/$ref.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaNode } from "../types";
|
|
1
|
+
import { isJsonError, isSchemaNode, JsonError, SchemaNode } from "../types";
|
|
2
2
|
import { Keyword, JsonSchemaValidatorParams, ValidationPath, JsonSchemaReducerParams } from "../Keyword";
|
|
3
3
|
import { resolveUri } from "../utils/resolveUri";
|
|
4
4
|
import splitRef from "../utils/splitRef";
|
|
@@ -93,7 +93,12 @@ export function reduceRef({ node, data, key, pointer, path }: JsonSchemaReducerP
|
|
|
93
93
|
|
|
94
94
|
const resolvedNode = node.resolveRef({ pointer, path });
|
|
95
95
|
if (resolvedNode == null) {
|
|
96
|
-
return
|
|
96
|
+
return node.createError("ref-error", {
|
|
97
|
+
ref: node.schema.$ref ?? node.schema.$dynamicRef,
|
|
98
|
+
pointer,
|
|
99
|
+
schema: node.schema,
|
|
100
|
+
value: data
|
|
101
|
+
});
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
if (resolvedNode.schemaLocation === node.schemaLocation) {
|
|
@@ -107,6 +112,9 @@ export function reduceRef({ node, data, key, pointer, path }: JsonSchemaReducerP
|
|
|
107
112
|
export function resolveRef(this: SchemaNode, { pointer, path = [] }: { pointer?: string; path?: ValidationPath } = {}) {
|
|
108
113
|
if (this.schema.$dynamicRef) {
|
|
109
114
|
const nextNode = resolveRecursiveRef(this, path);
|
|
115
|
+
if (isJsonError(nextNode)) {
|
|
116
|
+
return nextNode;
|
|
117
|
+
}
|
|
110
118
|
path.push({ pointer: pointer!, node: nextNode! });
|
|
111
119
|
return nextNode;
|
|
112
120
|
}
|
|
@@ -116,7 +124,7 @@ export function resolveRef(this: SchemaNode, { pointer, path = [] }: { pointer?:
|
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
const resolvedNode = getRef(this);
|
|
119
|
-
if (resolvedNode
|
|
127
|
+
if (isSchemaNode(resolvedNode)) {
|
|
120
128
|
path.push({ pointer: pointer!, node: resolvedNode });
|
|
121
129
|
}
|
|
122
130
|
|
|
@@ -129,10 +137,16 @@ function validateRef({ node, data, pointer = "#", path }: JsonSchemaValidatorPar
|
|
|
129
137
|
// recursively resolveRef and validate
|
|
130
138
|
return validateNode(nextNode, data, pointer, path);
|
|
131
139
|
}
|
|
140
|
+
return node.createError("ref-error", {
|
|
141
|
+
ref: node.schema.$ref ?? node.schema.$dynamicRef,
|
|
142
|
+
pointer,
|
|
143
|
+
schema: node.schema,
|
|
144
|
+
value: data
|
|
145
|
+
});
|
|
132
146
|
}
|
|
133
147
|
|
|
134
148
|
// 1. https://json-schema.org/draft/2019-09/json-schema-core#scopes
|
|
135
|
-
function resolveRecursiveRef(node: SchemaNode, path: ValidationPath): SchemaNode |
|
|
149
|
+
function resolveRecursiveRef(node: SchemaNode, path: ValidationPath): SchemaNode | JsonError {
|
|
136
150
|
const history = path;
|
|
137
151
|
const refInCurrentScope = resolveUri(node.$id, node.schema.$dynamicRef);
|
|
138
152
|
|
|
@@ -180,7 +194,7 @@ function compileNext(referencedNode: SchemaNode, sourceNode: SchemaNode) {
|
|
|
180
194
|
);
|
|
181
195
|
}
|
|
182
196
|
|
|
183
|
-
export function getRef(node: SchemaNode, $ref = node?.$ref): SchemaNode |
|
|
197
|
+
export function getRef(node: SchemaNode, $ref = node?.$ref): SchemaNode | JsonError {
|
|
184
198
|
if ($ref == null) {
|
|
185
199
|
return node;
|
|
186
200
|
}
|
|
@@ -202,7 +216,12 @@ export function getRef(node: SchemaNode, $ref = node?.$ref): SchemaNode | undefi
|
|
|
202
216
|
// check for remote-host + pointer pair to switch rootSchema
|
|
203
217
|
const fragments = splitRef($ref);
|
|
204
218
|
if (fragments.length === 0) {
|
|
205
|
-
return
|
|
219
|
+
return node.createError("ref-error", {
|
|
220
|
+
ref: $ref,
|
|
221
|
+
pointer: node.evaluationPath,
|
|
222
|
+
schema: node.schema,
|
|
223
|
+
value: undefined
|
|
224
|
+
});
|
|
206
225
|
}
|
|
207
226
|
|
|
208
227
|
// resolve $ref as remote-host
|
|
@@ -212,6 +231,7 @@ export function getRef(node: SchemaNode, $ref = node?.$ref): SchemaNode | undefi
|
|
|
212
231
|
if (node.context.remotes[$ref]) {
|
|
213
232
|
return compileNext(node.context.remotes[$ref], node);
|
|
214
233
|
}
|
|
234
|
+
|
|
215
235
|
if ($ref[0] === "#") {
|
|
216
236
|
// support refOfUnknownKeyword
|
|
217
237
|
const rootSchema = node.context.rootNode.schema;
|
|
@@ -221,7 +241,12 @@ export function getRef(node: SchemaNode, $ref = node?.$ref): SchemaNode | undefi
|
|
|
221
241
|
}
|
|
222
242
|
}
|
|
223
243
|
// console.error("REF: UNFOUND 1", $ref);
|
|
224
|
-
return
|
|
244
|
+
return node.createError("ref-error", {
|
|
245
|
+
ref: $ref,
|
|
246
|
+
pointer: node.evaluationPath,
|
|
247
|
+
schema: node.schema,
|
|
248
|
+
value: undefined
|
|
249
|
+
});
|
|
225
250
|
}
|
|
226
251
|
|
|
227
252
|
if (fragments.length === 2) {
|
|
@@ -252,16 +277,25 @@ export function getRef(node: SchemaNode, $ref = node?.$ref): SchemaNode | undefi
|
|
|
252
277
|
// @ts-expect-error random path
|
|
253
278
|
currentNode = currentNode[property];
|
|
254
279
|
if (currentNode == null) {
|
|
255
|
-
console.error("REF: FAILED RESOLVING ref json-pointer", fragments[1]);
|
|
256
|
-
return
|
|
280
|
+
// console.error("REF: FAILED RESOLVING ref json-pointer", fragments[1]);
|
|
281
|
+
return node.createError("ref-error", {
|
|
282
|
+
ref: $ref,
|
|
283
|
+
pointer: node.evaluationPath,
|
|
284
|
+
schema: node.schema,
|
|
285
|
+
value: undefined,
|
|
286
|
+
host: fragments[0],
|
|
287
|
+
local: fragments[1]
|
|
288
|
+
});
|
|
257
289
|
}
|
|
258
290
|
}
|
|
259
291
|
return currentNode;
|
|
260
292
|
}
|
|
261
|
-
|
|
262
|
-
console.error("REF: UNFOUND 2", $ref);
|
|
263
|
-
return undefined;
|
|
264
293
|
}
|
|
265
294
|
|
|
266
|
-
|
|
295
|
+
return node.createError("ref-error", {
|
|
296
|
+
ref: $ref,
|
|
297
|
+
pointer: node.evaluationPath,
|
|
298
|
+
schema: node.schema,
|
|
299
|
+
value: undefined
|
|
300
|
+
});
|
|
267
301
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ValidationReturnType,
|
|
6
6
|
ValidationAnnotation
|
|
7
7
|
} from "../Keyword";
|
|
8
|
-
import { isBooleanSchema, isJsonSchema,
|
|
8
|
+
import { isBooleanSchema, isJsonSchema, SchemaNode } from "../types";
|
|
9
9
|
import { hasProperty } from "../utils/hasProperty";
|
|
10
10
|
import { isObject } from "../utils/isObject";
|
|
11
11
|
import { mergeSchema } from "../utils/mergeSchema";
|
package/src/methods/getData.ts
CHANGED
|
@@ -159,7 +159,7 @@ export function getData(node: SchemaNode, data?: unknown, opts?: TemplateOptions
|
|
|
159
159
|
return defaultData;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
if (resolvedNode
|
|
162
|
+
if (isSchemaNode(resolvedNode)) {
|
|
163
163
|
defaultData = resolvedNode.getData(defaultData, opts) ?? defaultData;
|
|
164
164
|
currentNode = resolvedNode;
|
|
165
165
|
}
|
package/src/validateNode.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { BooleanSchema, JsonSchema, SchemaNode } from "./types";
|
|
1
|
+
import { BooleanSchema, isJsonError, JsonSchema, SchemaNode } from "./types";
|
|
2
2
|
import { SchemaNodeWithRequired, ValidationPath, ValidationReturnType } from "./Keyword";
|
|
3
3
|
import sanitizeErrors from "./utils/sanitizeErrors";
|
|
4
4
|
|
|
5
5
|
export function validateNode(node: SchemaNode, data: unknown, pointer: string, path: ValidationPath) {
|
|
6
|
+
if (isJsonError(node)) {
|
|
7
|
+
return [node];
|
|
8
|
+
}
|
|
6
9
|
path.push({ pointer, node });
|
|
7
10
|
const schema = node.schema as BooleanSchema | JsonSchema;
|
|
8
11
|
if (schema === true) {
|
package/tsconfig.json
CHANGED
|
@@ -7,10 +7,17 @@
|
|
|
7
7
|
"module": "ESNext",
|
|
8
8
|
"resolveJsonModule": true,
|
|
9
9
|
"allowSyntheticDefaultImports": true,
|
|
10
|
-
"moduleResolution": "
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
11
|
"lib": ["DOM", "ES2018"],
|
|
12
|
-
"exactOptionalPropertyTypes": true
|
|
12
|
+
"exactOptionalPropertyTypes": true,
|
|
13
|
+
"baseUrl": ".",
|
|
14
|
+
"paths": {
|
|
15
|
+
"json-schema-library": ["./index.ts"],
|
|
16
|
+
"json-schema-library/remotes": ["./remotes/index.ts"],
|
|
17
|
+
"json-schema-library/package.json": ["./package.json"]
|
|
18
|
+
},
|
|
19
|
+
"types": ["node", "mocha"]
|
|
13
20
|
},
|
|
14
|
-
"exclude": ["src/**/*.test.ts"],
|
|
15
|
-
"include": ["index.ts", "src/**/*"]
|
|
21
|
+
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts", "bowtie/**/*.test.ts"],
|
|
22
|
+
"include": ["index.ts", "src/**/*", "remotes/**/*", "bowtie/**/*"]
|
|
16
23
|
}
|
package/tsconfig.test.json
CHANGED
|
@@ -5,11 +5,18 @@
|
|
|
5
5
|
"incremental": false /* Enable incremental compilation */,
|
|
6
6
|
"target": "ESNEXT" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
|
7
7
|
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
|
8
|
+
"moduleResolution": "node10",
|
|
8
9
|
"sourceMap": false /* Generates corresponding '.map' file. */,
|
|
9
10
|
"strict": false /* Enable all strict type-checking options. */,
|
|
10
11
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
11
|
-
"types": ["mocha", "node"]
|
|
12
|
+
"types": ["mocha", "node"],
|
|
13
|
+
"baseUrl": ".",
|
|
14
|
+
"paths": {
|
|
15
|
+
"json-schema-library": ["./index.ts"],
|
|
16
|
+
"json-schema-library/remotes": ["./remotes/index.ts"],
|
|
17
|
+
"json-schema-library/package.json": ["./package.json"]
|
|
18
|
+
}
|
|
12
19
|
},
|
|
13
20
|
"exclude": [],
|
|
14
|
-
"include": ["src/**/*.test.ts"]
|
|
21
|
+
"include": ["src/**/*.test.ts", "bowtie/**/*.test.ts"]
|
|
15
22
|
}
|
package/tsdown.config.ts
CHANGED
package/Dockerfile
DELETED
package/bowtie_jlib.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* test file for bowtie integration
|
|
3
|
-
*
|
|
4
|
-
* - Tutorial: https://docs.bowtie.report/en/stable/implementers/
|
|
5
|
-
*
|
|
6
|
-
* Build Dockerfile:
|
|
7
|
-
*
|
|
8
|
-
* ```
|
|
9
|
-
* docker build -t localhost/jlib .
|
|
10
|
-
* ````
|
|
11
|
-
*
|
|
12
|
-
* Test setup:
|
|
13
|
-
*
|
|
14
|
-
* ```
|
|
15
|
-
bowtie run -i localhost/jlib -V <<EOF
|
|
16
|
-
{"description": "test case 1", "schema": {}, "tests": [{"description": "a test", "instance": {}}] }
|
|
17
|
-
{"description": "test case 2", "schema": {"const": 37}, "tests": [{"description": "not 37", "instance": {}}, {"description": "is 37", "instance": 37}] }
|
|
18
|
-
EOF
|
|
19
|
-
*
|
|
20
|
-
* Test draft
|
|
21
|
-
*
|
|
22
|
-
* ```
|
|
23
|
-
* bowtie suite -i localhost/jlib draft7 | bowtie summary --show failures
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
const readline = require("readline/promises");
|
|
28
|
-
const process = require("process");
|
|
29
|
-
const os = require("os");
|
|
30
|
-
const packageJson = require("./package.json");
|
|
31
|
-
const jlib = require("./dist/jsonSchemaLibrary.js");
|
|
32
|
-
|
|
33
|
-
const compileSchema = jlib.compileSchema;
|
|
34
|
-
|
|
35
|
-
const stdio = readline.createInterface({
|
|
36
|
-
input: process.stdin,
|
|
37
|
-
output: process.stdout,
|
|
38
|
-
terminal: false
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// const schemaIds: { [id: string]: SchemaDraft } = {
|
|
42
|
-
// "https://json-schema.org/draft/2020-12/schema": SchemaDraft.v2020_12,
|
|
43
|
-
// "https://json-schema.org/draft/2019-09/schema": SchemaDraft.v2019_09,
|
|
44
|
-
// "http://json-schema.org/draft-07/schema#": SchemaDraft.v7,
|
|
45
|
-
// "http://json-schema.org/draft-06/schema#": SchemaDraft.v6,
|
|
46
|
-
// "http://json-schema.org/draft-04/schema#": SchemaDraft.v4
|
|
47
|
-
// };
|
|
48
|
-
|
|
49
|
-
function send(data) {
|
|
50
|
-
console.log(JSON.stringify(data));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let started = false;
|
|
54
|
-
// let dialect;
|
|
55
|
-
|
|
56
|
-
const cmds = {
|
|
57
|
-
start: async (args) => {
|
|
58
|
-
console.assert(args.version === 1, { args });
|
|
59
|
-
started = true;
|
|
60
|
-
return {
|
|
61
|
-
version: 1,
|
|
62
|
-
implementation: {
|
|
63
|
-
language: "javascript",
|
|
64
|
-
name: "json-schema-library",
|
|
65
|
-
version: packageJson.version,
|
|
66
|
-
homepage: "https://github.com/sagold/json-schema-library",
|
|
67
|
-
issues: "https://github.com/sagold/json-schema-library/issues",
|
|
68
|
-
source: "https://github.com/sagold/json-schema-library",
|
|
69
|
-
|
|
70
|
-
dialects: [
|
|
71
|
-
"https://json-schema.org/draft/2020-12/schema",
|
|
72
|
-
"https://json-schema.org/draft/2019-09/schema",
|
|
73
|
-
"http://json-schema.org/draft-07/schema#",
|
|
74
|
-
"http://json-schema.org/draft-06/schema#",
|
|
75
|
-
"http://json-schema.org/draft-04/schema#"
|
|
76
|
-
],
|
|
77
|
-
os: os.platform(),
|
|
78
|
-
os_version: os.release(),
|
|
79
|
-
language_version: process.version
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
dialect: async (args) => {
|
|
85
|
-
console.assert(started, "Not started!");
|
|
86
|
-
// dialect = schemaIds[args.dialect];
|
|
87
|
-
return { ok: true };
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
run: async (args) => {
|
|
91
|
-
console.assert(started, "Not started!");
|
|
92
|
-
|
|
93
|
-
// for (const id in testCase.registry) {
|
|
94
|
-
// ajv.addSchema(testCase.registry[id], id);
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
const testCase = args.case;
|
|
98
|
-
// as {
|
|
99
|
-
// registry: Recors<sring, string>;
|
|
100
|
-
// schema: Record<string, any>;
|
|
101
|
-
// tests: {
|
|
102
|
-
// /** testdata */
|
|
103
|
-
// instance: unknown;
|
|
104
|
-
// }[];
|
|
105
|
-
// };
|
|
106
|
-
|
|
107
|
-
const node = compileSchema(testCase.schema);
|
|
108
|
-
const results = testCase.tests.map((test) => {
|
|
109
|
-
try {
|
|
110
|
-
const errors = node.validate(test.instance);
|
|
111
|
-
return { valid: errors.length === 0 };
|
|
112
|
-
} catch (error) {
|
|
113
|
-
return {
|
|
114
|
-
errored: true,
|
|
115
|
-
context: {
|
|
116
|
-
traceback: error.stack,
|
|
117
|
-
message: error.message
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return { seq: args.seq, results: results };
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
stop: async (_) => {
|
|
127
|
-
console.assert(started, "Not started!");
|
|
128
|
-
process.exit(0);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
async function main() {
|
|
133
|
-
for await (const line of stdio) {
|
|
134
|
-
const request = JSON.parse(line);
|
|
135
|
-
const response = await cmds[request.cmd](request);
|
|
136
|
-
send(response);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
main();
|