json-schema-library 11.1.0 → 11.3.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.
Files changed (82) hide show
  1. package/.mocharc.js +1 -0
  2. package/CHANGELOG.md +11 -0
  3. package/README.md +21 -13
  4. package/bowtie/.editorconfig +21 -0
  5. package/bowtie/.prettierrc +6 -0
  6. package/bowtie/BOWTIE.md +54 -0
  7. package/bowtie/Dockerfile +6 -0
  8. package/bowtie/bowtie-api.ts +101 -0
  9. package/bowtie/bowtie-jlib.ts +150 -0
  10. package/bowtie/bowtie.test.ts +267 -0
  11. package/bowtie/package.json +11 -0
  12. package/bowtie/tsconfig.json +12 -0
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +66 -503
  15. package/dist/index.d.mts +66 -503
  16. package/dist/index.mjs +1 -1
  17. package/dist/jlib.js +2 -13
  18. package/dist/remotes/index.cjs +1 -0
  19. package/dist/remotes/index.d.cts +7 -0
  20. package/dist/remotes/index.d.mts +7 -0
  21. package/dist/remotes/index.mjs +1 -0
  22. package/dist/types-B2wwNWyo.d.cts +513 -0
  23. package/dist/types-BhTU1l2h.d.mts +513 -0
  24. package/index.ts +0 -3
  25. package/package.json +14 -8
  26. package/src/Draft.ts +1 -1
  27. package/src/Keyword.ts +2 -3
  28. package/src/SchemaNode.ts +9 -0
  29. package/src/compileSchema.test.ts +52 -0
  30. package/src/compileSchema.ts +53 -3
  31. package/src/draft04/keywords/$ref.ts +22 -14
  32. package/src/draft04/keywords/exclusiveMaximum.ts +14 -0
  33. package/src/draft04/keywords/exclusiveMinimum.ts +14 -0
  34. package/src/draft04/validateSchema.test.ts +20 -0
  35. package/src/draft04.ts +2 -2
  36. package/src/draft06/keywords/$ref.ts +15 -5
  37. package/src/draft06.ts +2 -2
  38. package/src/draft07.ts +2 -2
  39. package/src/draft2019-09/keywords/$ref.test.ts +3 -1
  40. package/src/draft2019-09/keywords/$ref.ts +44 -30
  41. package/src/draft2019-09/keywords/additionalItems.ts +33 -10
  42. package/src/draft2019-09/keywords/items.ts +32 -10
  43. package/src/draft2019-09/keywords/unevaluatedItems.ts +19 -6
  44. package/src/draft2019-09/methods/getData.ts +1 -1
  45. package/src/draft2019-09/validateSchema.test.ts +28 -0
  46. package/src/draft2019.ts +1 -1
  47. package/src/draft2020.ts +1 -1
  48. package/src/errors/errors.ts +4 -0
  49. package/src/formats/formats.ts +35 -28
  50. package/src/formats/hyperjump.d.ts +172 -0
  51. package/src/keywords/$ref.ts +50 -17
  52. package/src/keywords/oneOf.test.ts +3 -3
  53. package/src/keywords/properties.ts +1 -1
  54. package/src/keywords/propertyDependencies.ts +1 -1
  55. package/src/methods/getData.ts +1 -1
  56. package/src/settings.ts +27 -1
  57. package/src/validateNode.ts +4 -1
  58. package/tsconfig.json +11 -4
  59. package/tsconfig.test.json +9 -2
  60. package/tsdown.config.ts +1 -1
  61. package/Dockerfile +0 -6
  62. package/bowtie_jlib.js +0 -140
  63. package/remotes/draft04.json +0 -150
  64. package/remotes/draft06.json +0 -155
  65. package/remotes/draft07.json +0 -155
  66. package/remotes/draft2019-09.json +0 -42
  67. package/remotes/draft2019-09_meta_applicator.json +0 -53
  68. package/remotes/draft2019-09_meta_content.json +0 -14
  69. package/remotes/draft2019-09_meta_core.json +0 -54
  70. package/remotes/draft2019-09_meta_format.json +0 -11
  71. package/remotes/draft2019-09_meta_meta-data.json +0 -34
  72. package/remotes/draft2019-09_meta_validation.json +0 -95
  73. package/remotes/draft2020-12.json +0 -55
  74. package/remotes/draft2020-12_meta_applicator.json +0 -45
  75. package/remotes/draft2020-12_meta_content.json +0 -14
  76. package/remotes/draft2020-12_meta_core.json +0 -48
  77. package/remotes/draft2020-12_meta_format_annotation.json +0 -11
  78. package/remotes/draft2020-12_meta_format_assertion.json +0 -11
  79. package/remotes/draft2020-12_meta_meta_data.json +0 -34
  80. package/remotes/draft2020-12_meta_unevaluated.json +0 -12
  81. package/remotes/draft2020-12_meta_validation.json +0 -87
  82. package/remotes/index.ts +0 -48
@@ -0,0 +1,267 @@
1
+ import { strict as assert } from "node:assert";
2
+ import { compileSchema } from "../src/compileSchema";
3
+ import { remotes } from "json-schema-library/remotes";
4
+ import { JsonSchema } from "../src/types";
5
+ import { runCommand } from "./bowtie-jlib";
6
+ import { ErrorResponse, RunCmdResponse } from "./bowtie-api";
7
+
8
+ const isRunCmdResponse = (value: unknown): value is RunCmdResponse =>
9
+ value != null && typeof value === "object" && "results" in value && Array.isArray(value.results);
10
+
11
+ const isErrorResponse = (value: unknown): value is ErrorResponse =>
12
+ value != null && typeof value === "object" && "errored" in value && value.errored === true;
13
+
14
+ const remote = compileSchema({ $id: "draft2020-12" });
15
+ remotes.map((schema: JsonSchema) => remote.addRemoteSchema(schema.$id ?? schema.id, schema));
16
+
17
+ describe("bowtie (draft7)", async () => {
18
+ before(async () => {
19
+ await runCommand({ cmd: "start", version: 1 });
20
+ await runCommand({ cmd: "dialect", dialect: "http://json-schema.org/draft-07/schema#" });
21
+ });
22
+ after(async () => runCommand({ cmd: "stop" }));
23
+
24
+ it("additionalItems as schema - additional items match schema", async () => {
25
+ const response = await runCommand({
26
+ cmd: "run",
27
+ seq: 1,
28
+ case: {
29
+ description: "additionalItems as schema",
30
+ schema: { items: [{}], additionalItems: { type: "integer" } },
31
+ tests: [{ description: "additional items match schema", instance: [null, 2, 3, 4], valid: true }]
32
+ }
33
+ });
34
+ assert(isRunCmdResponse(response));
35
+ assert(!isErrorResponse(response.results[0]));
36
+ assert.equal(response.results[0].valid, true);
37
+ });
38
+
39
+ it("additionalItems as schema - additional items do not match schema", async () => {
40
+ const response = await runCommand({
41
+ cmd: "run",
42
+ seq: 1,
43
+ case: {
44
+ description: "additionalItems as schema",
45
+ schema: { items: [{}], additionalItems: { type: "integer" } },
46
+ tests: [
47
+ { description: "additional items do not match schema", instance: [null, 2, 3, "foo"], valid: false }
48
+ ]
49
+ }
50
+ });
51
+ assert(isRunCmdResponse(response));
52
+ assert(!isErrorResponse(response.results[0]));
53
+ assert.equal(response.results[0].valid, false);
54
+ });
55
+ });
56
+
57
+ describe("bowtie (2019-09)", () => {
58
+ const testCase = {
59
+ description: "schema that uses custom metaschema with with no validation vocabulary",
60
+ schema: {
61
+ $id: "https://schema/using/no/validation",
62
+ $schema: "http://localhost:1234/draft2019-09/metaschema-no-validation.json",
63
+ properties: { badProperty: false, numberProperty: { minimum: 10 } }
64
+ },
65
+ registry: {
66
+ "http://localhost:1234/draft2019-09/integer.json": {
67
+ $schema: "https://json-schema.org/draft/2019-09/schema",
68
+ type: "integer"
69
+ },
70
+ "http://localhost:1234/draft2019-09/dependentRequired.json": {
71
+ $id: "http://localhost:1234/draft2019-09/dependentRequired.json",
72
+ $schema: "https://json-schema.org/draft/2019-09/schema",
73
+ dependentRequired: { foo: ["bar"] }
74
+ },
75
+ "http://localhost:1234/draft2019-09/detached-ref.json": {
76
+ $id: "http://localhost:1234/draft2019-09/detached-ref.json",
77
+ $schema: "https://json-schema.org/draft/2019-09/schema",
78
+ $defs: { foo: { $ref: "#detached" }, detached: { $anchor: "detached", type: "integer" } }
79
+ },
80
+ "http://localhost:1234/integer.json": { type: "integer" },
81
+ "http://localhost:1234/draft2019-09/nested/foo-ref-string.json": {
82
+ $schema: "https://json-schema.org/draft/2019-09/schema",
83
+ type: "object",
84
+ properties: { foo: { $ref: "string.json" } }
85
+ },
86
+ "http://localhost:1234/draft2019-09/urn-ref-string.json": {
87
+ $id: "urn:uuid:feebdaed-ffff-0000-2019-0900deadbeef",
88
+ $defs: { bar: { type: "string" } },
89
+ $ref: "#/$defs/bar"
90
+ },
91
+ "http://localhost:1234/draft2019-09/locationIndependentIdentifier.json": {
92
+ $schema: "https://json-schema.org/draft/2019-09/schema",
93
+ $defs: { refToInteger: { $ref: "#foo" }, A: { $anchor: "foo", type: "integer" } }
94
+ },
95
+ "http://localhost:1234/baseUriChangeFolder/folderInteger.json": { type: "integer" },
96
+ "http://localhost:1234/draft2019-09/baseUriChange/folderInteger.json": {
97
+ $schema: "https://json-schema.org/draft/2019-09/schema",
98
+ type: "integer"
99
+ },
100
+ "http://localhost:1234/draft2019-09/ref-and-defs.json": {
101
+ $schema: "https://json-schema.org/draft/2019-09/schema",
102
+ $id: "http://localhost:1234/draft2019-09/ref-and-defs.json",
103
+ $defs: { inner: { properties: { bar: { type: "string" } } } },
104
+ $ref: "#/$defs/inner"
105
+ },
106
+ "http://localhost:1234/baseUriChangeFolderInSubschema/folderInteger.json": { type: "integer" },
107
+ "http://localhost:1234/draft2019-09/baseUriChangeFolder/folderInteger.json": {
108
+ $schema: "https://json-schema.org/draft/2019-09/schema",
109
+ type: "integer"
110
+ },
111
+ "http://localhost:1234/nested/foo-ref-string.json": {
112
+ type: "object",
113
+ properties: { foo: { $ref: "string.json" } }
114
+ },
115
+ "http://localhost:1234/nested/string.json": { type: "string" },
116
+ "http://localhost:1234/draft2019-09/baseUriChangeFolderInSubschema/folderInteger.json": {
117
+ $schema: "https://json-schema.org/draft/2019-09/schema",
118
+ type: "integer"
119
+ },
120
+ "http://localhost:1234/draft2019-09/name-defs.json": {
121
+ $schema: "https://json-schema.org/draft/2019-09/schema",
122
+ $defs: { orNull: { anyOf: [{ type: "null" }, { $ref: "#" }] } },
123
+ type: "string"
124
+ },
125
+ "http://localhost:1234/v1/different-id-ref-string.json": {
126
+ $id: "http://localhost:1234/v1/real-id-ref-string.json",
127
+ $defs: { bar: { type: "string" } },
128
+ $ref: "#/$defs/bar"
129
+ },
130
+ "http://localhost:1234/v1/nested-absolute-ref-to-string.json": {
131
+ $defs: { bar: { $id: "http://localhost:1234/v1/the-nested-id.json", type: "string" } },
132
+ $ref: "http://localhost:1234/v1/the-nested-id.json"
133
+ },
134
+ "http://localhost:1234/v1/urn-ref-string.json": {
135
+ $id: "urn:uuid:feebdaed-ffff-0000-ff01-0000deadbeef",
136
+ $defs: { bar: { type: "string" } },
137
+ $ref: "#/$defs/bar"
138
+ },
139
+ "http://localhost:1234/draft2019-09/ignore-prefixItems.json": {
140
+ $id: "http://localhost:1234/draft2019-09/ignore-prefixItems.json",
141
+ $schema: "https://json-schema.org/draft/2019-09/schema",
142
+ prefixItems: [{ type: "string" }]
143
+ },
144
+ "http://localhost:1234/draft2019-09/subSchemas.json": {
145
+ $schema: "https://json-schema.org/draft/2019-09/schema",
146
+ $defs: { integer: { type: "integer" }, refToInteger: { $ref: "#/$defs/integer" } }
147
+ },
148
+ "http://localhost:1234/draft2019-09/nested-absolute-ref-to-string.json": {
149
+ $defs: { bar: { $id: "http://localhost:1234/draft2019-09/the-nested-id.json", type: "string" } },
150
+ $ref: "http://localhost:1234/draft2019-09/the-nested-id.json"
151
+ },
152
+ "http://localhost:1234/draft2019-09/nested/string.json": {
153
+ $schema: "https://json-schema.org/draft/2019-09/schema",
154
+ type: "string"
155
+ },
156
+ "http://localhost:1234/draft2019-09/metaschema-optional-vocabulary.json": {
157
+ $schema: "https://json-schema.org/draft/2019-09/schema",
158
+ $id: "http://localhost:1234/draft2019-09/metaschema-optional-vocabulary.json",
159
+ $vocabulary: {
160
+ "https://json-schema.org/draft/2019-09/vocab/validation": true,
161
+ "https://json-schema.org/draft/2019-09/vocab/core": true,
162
+ "http://localhost:1234/draft/2019-09/vocab/custom": false
163
+ },
164
+ $recursiveAnchor: true,
165
+ allOf: [
166
+ { $ref: "https://json-schema.org/draft/2019-09/meta/validation" },
167
+ { $ref: "https://json-schema.org/draft/2019-09/meta/core" }
168
+ ]
169
+ },
170
+ "http://localhost:1234/draft2019-09/different-id-ref-string.json": {
171
+ $id: "http://localhost:1234/draft2019-09/real-id-ref-string.json",
172
+ $defs: { bar: { type: "string" } },
173
+ $ref: "#/$defs/bar"
174
+ },
175
+ "http://localhost:1234/draft2019-09/extendible-dynamic-ref.json": {
176
+ description: "extendible array",
177
+ $schema: "https://json-schema.org/draft/2019-09/schema",
178
+ $id: "http://localhost:1234/draft2019-09/extendible-dynamic-ref.json",
179
+ type: "object",
180
+ properties: { elements: { type: "array", items: { $dynamicRef: "#elements" } } },
181
+ required: ["elements"],
182
+ additionalProperties: false,
183
+ $defs: { elements: { $dynamicAnchor: "elements" } }
184
+ },
185
+ "http://localhost:1234/draft2019-09/metaschema-no-validation.json": {
186
+ $schema: "https://json-schema.org/draft/2019-09/schema",
187
+ $id: "http://localhost:1234/draft2019-09/metaschema-no-validation.json",
188
+ $vocabulary: {
189
+ "https://json-schema.org/draft/2019-09/vocab/applicator": true,
190
+ "https://json-schema.org/draft/2019-09/vocab/core": true
191
+ },
192
+ $recursiveAnchor: true,
193
+ allOf: [
194
+ { $ref: "https://json-schema.org/draft/2019-09/meta/applicator" },
195
+ { $ref: "https://json-schema.org/draft/2019-09/meta/core" }
196
+ ]
197
+ },
198
+ "http://localhost:1234/baseUriChange/folderInteger.json": { type: "integer" }
199
+ }
200
+ };
201
+
202
+ before(async () => {
203
+ await runCommand({ cmd: "start", version: 1 });
204
+ await runCommand({ cmd: "dialect", dialect: "https://json-schema.org/draft/2019-09/schema" });
205
+ });
206
+ after(async () => runCommand({ cmd: "stop" }));
207
+
208
+ it(`${testCase.description} - applicator vocabulary still works`, async () => {
209
+ const response = await runCommand({
210
+ cmd: "run",
211
+ seq: 1,
212
+ case: {
213
+ ...testCase,
214
+ tests: [
215
+ {
216
+ description: "applicator vocabulary still works",
217
+ instance: { badProperty: "this property should not exist" },
218
+ valid: false
219
+ }
220
+ ]
221
+ }
222
+ });
223
+ assert(isRunCmdResponse(response));
224
+ assert(!isErrorResponse(response.results[0]));
225
+ assert.equal(response.results[0].valid, false);
226
+ });
227
+
228
+ it(`${testCase.description} - no validation: valid number`, async () => {
229
+ const response = await runCommand({
230
+ cmd: "run",
231
+ seq: 1,
232
+ case: {
233
+ ...testCase,
234
+ tests: [
235
+ {
236
+ description: "no validation: valid number",
237
+ instance: { numberProperty: 20 },
238
+ valid: true
239
+ }
240
+ ]
241
+ }
242
+ });
243
+ assert(isRunCmdResponse(response));
244
+ assert(!isErrorResponse(response.results[0]));
245
+ assert.equal(response.results[0].valid, true);
246
+ });
247
+
248
+ it(`${testCase.description} - no validation: invalid number, but it still validates`, async () => {
249
+ const response = await runCommand({
250
+ cmd: "run",
251
+ seq: 1,
252
+ case: {
253
+ ...testCase,
254
+ tests: [
255
+ {
256
+ description: "no validation: invalid number, but it still validates",
257
+ instance: { numberProperty: 1 },
258
+ valid: true
259
+ }
260
+ ]
261
+ }
262
+ });
263
+ assert(isRunCmdResponse(response));
264
+ assert(!isErrorResponse(response.results[0]));
265
+ assert.equal(response.results[0].valid, true);
266
+ });
267
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "bowtie-jlib",
3
+ "version": "1.0.0",
4
+ "scripts": {
5
+ "format": "prettier -w ."
6
+ },
7
+ "dependencies": {
8
+ "json-schema-library": ">=11.2.0",
9
+ "prettier": "^3.8.1"
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../tsconfig.test.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "rootDir": "..",
6
+ "paths": {
7
+ "json-schema-library": ["./index.ts"],
8
+ "json-schema-library/remotes": ["./remotes/index.ts"],
9
+ "json-schema-library/package.json": ["./package.json"]
10
+ }
11
+ }
12
+ }