json-schema-library 5.2.1 → 6.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/.prettierignore +1 -0
- package/.prettierrc +7 -0
- package/README.md +9 -8
- package/dist/index.d.ts +13 -44
- package/dist/jsonSchemaLibrary.js +1 -1
- package/dist/lib/addValidator.d.ts +2 -1
- package/dist/lib/compile/index.d.ts +11 -0
- package/dist/lib/config/strings.d.ts +1 -39
- package/dist/lib/cores/CoreInterface.d.ts +28 -9
- package/dist/lib/cores/Draft04.d.ts +2 -2
- package/dist/lib/cores/Draft06.d.ts +15 -0
- package/dist/lib/cores/Draft07.d.ts +15 -0
- package/dist/lib/cores/JsonEditor.d.ts +2 -2
- package/dist/lib/draft06/addSchema.d.ts +7 -0
- package/dist/lib/draft06/compile/index.d.ts +15 -0
- package/dist/lib/draft06/validation/keyword.d.ts +3 -0
- package/dist/lib/draft06/validation/type.d.ts +17 -0
- package/dist/lib/draft06/validation/typeKeywordMapping.d.ts +13 -0
- package/dist/lib/getChildSchemaSelection.d.ts +7 -5
- package/dist/lib/getSchema.d.ts +1 -1
- package/dist/lib/getTemplate.d.ts +5 -1
- package/dist/lib/getTypeOf.d.ts +2 -1
- package/dist/lib/schema/getTypeId.d.ts +1 -1
- package/dist/lib/step.d.ts +4 -4
- package/dist/lib/types.d.ts +10 -2
- package/dist/lib/utils/filter.d.ts +0 -1
- package/dist/lib/utils/merge.d.ts +3 -0
- package/dist/lib/validate.d.ts +1 -1
- package/dist/lib/validation/format.d.ts +6 -0
- package/dist/lib/validation/keyword.d.ts +2 -27
- package/dist/lib/validation/type.d.ts +3 -10
- package/dist/lib/validation/typeKeywordMapping.d.ts +4 -4
- package/dist/module/index.js +13 -6
- package/dist/module/lib/addValidator.js +3 -4
- package/dist/module/lib/compile/getRef.js +1 -1
- package/dist/module/lib/compile/index.js +11 -0
- package/dist/module/lib/config/strings.js +15 -2
- package/dist/module/lib/cores/CoreInterface.js +22 -0
- package/dist/module/lib/cores/Draft06.js +61 -0
- package/dist/module/lib/cores/Draft07.js +61 -0
- package/dist/module/lib/createSchemaOf.js +1 -1
- package/dist/module/lib/draft06/addSchema.js +11 -0
- package/dist/module/lib/draft06/compile/index.js +65 -0
- package/dist/module/lib/draft06/validation/keyword.js +156 -0
- package/dist/module/lib/draft06/validation/type.js +30 -0
- package/dist/module/lib/draft06/validation/typeKeywordMapping.js +15 -0
- package/dist/module/lib/each.js +1 -1
- package/dist/module/lib/eachSchema.js +3 -3
- package/dist/module/lib/getChildSchemaSelection.js +7 -6
- package/dist/module/lib/getSchema.js +2 -1
- package/dist/module/lib/getTemplate.js +57 -23
- package/dist/module/lib/resolveAllOf.js +3 -4
- package/dist/module/lib/resolveOneOf.fuzzy.js +13 -3
- package/dist/module/lib/resolveOneOf.strict.js +11 -2
- package/dist/module/lib/resolveRef.strict.js +8 -0
- package/dist/module/lib/schema/getTypeDefs.js +12 -1
- package/dist/module/lib/schema/getTypeId.js +1 -1
- package/dist/module/lib/step.js +62 -11
- package/dist/module/lib/types.js +7 -1
- package/dist/module/lib/utils/filter.js +3 -5
- package/dist/module/lib/utils/merge.js +3 -0
- package/dist/module/lib/validate.js +33 -8
- package/dist/module/lib/validateAsync.js +7 -7
- package/dist/module/lib/validation/errors.js +15 -2
- package/dist/module/lib/validation/format.js +105 -4
- package/dist/module/lib/validation/keyword.js +77 -30
- package/dist/module/lib/validation/type.js +2 -1
- package/dist/module/remotes/draft06.json +155 -0
- package/dist/module/remotes/draft07.json +172 -0
- package/dist/module/remotes/index.js +0 -1
- package/dist/remotes/index.d.ts +0 -1
- package/index.ts +14 -5
- package/lib/addValidator.ts +5 -5
- package/lib/compile/getRef.ts +1 -1
- package/lib/compile/index.ts +11 -1
- package/lib/config/strings.ts +17 -3
- package/lib/cores/CoreInterface.ts +37 -10
- package/lib/cores/Draft04.ts +2 -4
- package/lib/cores/Draft06.ts +76 -0
- package/lib/cores/Draft07.ts +75 -0
- package/lib/cores/JsonEditor.ts +2 -4
- package/lib/createSchemaOf.ts +1 -3
- package/lib/draft06/addSchema.ts +14 -0
- package/lib/draft06/compile/index.ts +68 -0
- package/lib/draft06/validation/keyword.ts +177 -0
- package/lib/draft06/validation/type.ts +43 -0
- package/lib/draft06/validation/typeKeywordMapping.ts +15 -0
- package/lib/each.ts +8 -3
- package/lib/eachSchema.ts +3 -3
- package/lib/getChildSchemaSelection.ts +14 -7
- package/lib/getSchema.ts +15 -7
- package/lib/getTemplate.ts +148 -38
- package/lib/getTypeOf.ts +2 -1
- package/lib/resolveAllOf.ts +9 -5
- package/lib/resolveOneOf.fuzzy.ts +25 -8
- package/lib/resolveOneOf.strict.ts +17 -4
- package/lib/resolveRef.strict.ts +9 -0
- package/lib/schema/getTypeDefs.ts +14 -1
- package/lib/schema/getTypeId.ts +2 -2
- package/lib/step.ts +103 -22
- package/lib/types.ts +21 -4
- package/lib/utils/filter.ts +4 -6
- package/lib/utils/merge.ts +4 -0
- package/lib/validate.ts +45 -15
- package/lib/validateAsync.ts +13 -12
- package/lib/validation/errors.ts +15 -2
- package/lib/validation/format.ts +113 -4
- package/lib/validation/keyword.ts +147 -78
- package/lib/validation/type.ts +5 -1
- package/package.json +73 -63
- package/remotes/draft06.json +155 -0
- package/remotes/draft07.json +172 -0
- package/remotes/draft2019-09.json +86 -0
- package/remotes/index.ts +0 -2
- package/tsconfig.json +2 -9
|
@@ -2,31 +2,41 @@ import getTypeOf from "../getTypeOf";
|
|
|
2
2
|
import isSame from "../utils/deepCompare";
|
|
3
3
|
import settings from "../config/settings";
|
|
4
4
|
import ucs2decode from "../utils/punycode.ucs2decode";
|
|
5
|
+
import { JSONValidator, isJSONError } from "../types";
|
|
5
6
|
const FPP = settings.floatingPointPrecision;
|
|
6
7
|
|
|
8
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
9
|
+
const hasProperty = (value: Record<string, unknown>, property: string) =>
|
|
10
|
+
!(value[property] === undefined || !hasOwnProperty.call(value, property));
|
|
7
11
|
|
|
8
12
|
// list of validation keywords: http://json-schema.org/latest/json-schema-validation.html#rfc.section.5
|
|
9
|
-
const KeywordValidation = {
|
|
10
|
-
|
|
13
|
+
const KeywordValidation: Record<string, JSONValidator> = {
|
|
11
14
|
additionalProperties: (core, schema, value, pointer) => {
|
|
12
15
|
if (schema.additionalProperties === true || schema.additionalProperties == null) {
|
|
13
16
|
return undefined;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
if (
|
|
19
|
+
if (
|
|
20
|
+
getTypeOf(schema.patternProperties) === "object" &&
|
|
21
|
+
schema.additionalProperties === false
|
|
22
|
+
) {
|
|
17
23
|
// this is an arrangement with patternProperties. patternProperties validate before additionalProperties:
|
|
18
24
|
// https://spacetelescope.github.io/understanding-json-schema/reference/object.html#index-5
|
|
19
25
|
return undefined;
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
const errors = [];
|
|
23
|
-
let receivedProperties = Object.keys(value).filter(
|
|
29
|
+
let receivedProperties = Object.keys(value).filter(
|
|
30
|
+
(prop) => settings.propertyBlacklist.includes(prop) === false
|
|
31
|
+
);
|
|
24
32
|
const expectedProperties = Object.keys(schema.properties || {});
|
|
25
33
|
|
|
26
34
|
if (getTypeOf(schema.patternProperties) === "object") {
|
|
27
35
|
// filter received properties by matching patternProperties
|
|
28
|
-
const patterns = Object.keys(schema.patternProperties).map(
|
|
29
|
-
|
|
36
|
+
const patterns = Object.keys(schema.patternProperties).map(
|
|
37
|
+
(pattern) => new RegExp(pattern)
|
|
38
|
+
);
|
|
39
|
+
receivedProperties = receivedProperties.filter((prop) => {
|
|
30
40
|
for (let i = 0; i < patterns.length; i += 1) {
|
|
31
41
|
if (patterns[i].test(prop)) {
|
|
32
42
|
return false; // remove
|
|
@@ -45,37 +55,48 @@ const KeywordValidation = {
|
|
|
45
55
|
// additionalProperties { oneOf: [] }
|
|
46
56
|
if (isObject && Array.isArray(schema.additionalProperties.oneOf)) {
|
|
47
57
|
const result = core.resolveOneOf(
|
|
48
|
-
value[property],
|
|
58
|
+
value[property],
|
|
59
|
+
schema.additionalProperties,
|
|
60
|
+
`${pointer}/${property}`
|
|
49
61
|
);
|
|
50
|
-
if (result
|
|
51
|
-
errors.push(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
if (isJSONError(result)) {
|
|
63
|
+
errors.push(
|
|
64
|
+
core.errors.additionalPropertiesError({
|
|
65
|
+
schema: schema.additionalProperties,
|
|
66
|
+
property: receivedProperties[i],
|
|
67
|
+
properties: expectedProperties,
|
|
68
|
+
pointer,
|
|
69
|
+
// pass all validation errors
|
|
70
|
+
errors: result.data.errors
|
|
71
|
+
})
|
|
72
|
+
);
|
|
60
73
|
} else {
|
|
61
74
|
errors.push(core.validate(value[property], result, pointer));
|
|
62
75
|
}
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
// additionalProperties {}
|
|
65
78
|
} else if (isObject) {
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
if (
|
|
80
|
+
core.validate(value[property], schema.additionalProperties, pointer)
|
|
81
|
+
.length !== 0
|
|
82
|
+
) {
|
|
83
|
+
errors.push(
|
|
84
|
+
core.errors.additionalPropertiesError({
|
|
85
|
+
schema: schema.additionalProperties,
|
|
86
|
+
property: receivedProperties[i],
|
|
87
|
+
properties: expectedProperties,
|
|
88
|
+
pointer
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
errors.push(
|
|
94
|
+
core.errors.noAdditionalPropertiesError({
|
|
69
95
|
property: receivedProperties[i],
|
|
70
96
|
properties: expectedProperties,
|
|
71
97
|
pointer
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} else {
|
|
76
|
-
errors.push(core.errors.noAdditionalPropertiesError(
|
|
77
|
-
{ property: receivedProperties[i], properties: expectedProperties, pointer }
|
|
78
|
-
));
|
|
98
|
+
})
|
|
99
|
+
);
|
|
79
100
|
}
|
|
80
101
|
}
|
|
81
102
|
}
|
|
@@ -89,7 +110,7 @@ const KeywordValidation = {
|
|
|
89
110
|
}
|
|
90
111
|
|
|
91
112
|
const errors = [];
|
|
92
|
-
schema.allOf.forEach(subSchema => {
|
|
113
|
+
schema.allOf.forEach((subSchema) => {
|
|
93
114
|
errors.push(core.validate(value, subSchema, pointer));
|
|
94
115
|
});
|
|
95
116
|
|
|
@@ -116,32 +137,43 @@ const KeywordValidation = {
|
|
|
116
137
|
}
|
|
117
138
|
|
|
118
139
|
const errors = [];
|
|
119
|
-
Object.keys(value)
|
|
120
|
-
.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
140
|
+
Object.keys(value).forEach((property) => {
|
|
141
|
+
if (schema.dependencies[property] === undefined) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
124
144
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
145
|
+
// @draft >= 6 boolean schema
|
|
146
|
+
if (schema.dependencies[property] === true) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (schema.dependencies[property] === false) {
|
|
150
|
+
errors.push(core.errors.missingDependencyError({ pointer }));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
133
153
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
154
|
+
let dependencyErrors;
|
|
155
|
+
const type = getTypeOf(schema.dependencies[property]);
|
|
156
|
+
if (type === "array") {
|
|
157
|
+
dependencyErrors = schema.dependencies[property]
|
|
158
|
+
.filter((dependency) => value[dependency] === undefined)
|
|
159
|
+
.map((missingProperty) =>
|
|
160
|
+
core.errors.missingDependencyError({ missingProperty, pointer })
|
|
161
|
+
);
|
|
162
|
+
} else if (type === "object") {
|
|
163
|
+
dependencyErrors = core.validate(value, schema.dependencies[property]);
|
|
164
|
+
} else {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`Invalid dependency definition for ${pointer}/${property}. Must be list or schema`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
137
169
|
|
|
138
|
-
|
|
139
|
-
|
|
170
|
+
errors.push(...dependencyErrors);
|
|
171
|
+
});
|
|
140
172
|
|
|
141
173
|
return errors.length > 0 ? errors : undefined;
|
|
142
174
|
},
|
|
143
175
|
|
|
144
|
-
|
|
176
|
+
enum: (core, schema, value, pointer) => {
|
|
145
177
|
const type = getTypeOf(value);
|
|
146
178
|
if (type === "object" || type === "array") {
|
|
147
179
|
const valueStr = JSON.stringify(value);
|
|
@@ -164,13 +196,20 @@ const KeywordValidation = {
|
|
|
164
196
|
return undefined;
|
|
165
197
|
},
|
|
166
198
|
items: (core, schema, value, pointer) => {
|
|
199
|
+
// @draft >= 7 bool schema
|
|
200
|
+
if (schema.items === false) {
|
|
201
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
return core.errors.invalidDataError({ pointer, value });
|
|
205
|
+
}
|
|
206
|
+
|
|
167
207
|
const errors = [];
|
|
168
208
|
for (let i = 0; i < value.length; i += 1) {
|
|
169
209
|
const itemData = value[i];
|
|
170
210
|
// @todo reevaluate: incomplete schema is created here
|
|
171
211
|
const itemSchema = core.step(i, schema, value, pointer);
|
|
172
|
-
|
|
173
|
-
if (itemSchema && itemSchema.type === "error") {
|
|
212
|
+
if (isJSONError(itemSchema)) {
|
|
174
213
|
return [itemSchema];
|
|
175
214
|
}
|
|
176
215
|
|
|
@@ -197,7 +236,11 @@ const KeywordValidation = {
|
|
|
197
236
|
return undefined;
|
|
198
237
|
}
|
|
199
238
|
if (schema.maxItems < value.length) {
|
|
200
|
-
return core.errors.maxItemsError({
|
|
239
|
+
return core.errors.maxItemsError({
|
|
240
|
+
maximum: schema.maxItems,
|
|
241
|
+
length: value.length,
|
|
242
|
+
pointer
|
|
243
|
+
});
|
|
201
244
|
}
|
|
202
245
|
return undefined;
|
|
203
246
|
},
|
|
@@ -207,7 +250,11 @@ const KeywordValidation = {
|
|
|
207
250
|
}
|
|
208
251
|
const lengthOfString = ucs2decode(value).length;
|
|
209
252
|
if (schema.maxLength < lengthOfString) {
|
|
210
|
-
return core.errors.maxLengthError({
|
|
253
|
+
return core.errors.maxLengthError({
|
|
254
|
+
maxLength: schema.maxLength,
|
|
255
|
+
length: lengthOfString,
|
|
256
|
+
pointer
|
|
257
|
+
});
|
|
211
258
|
}
|
|
212
259
|
return undefined;
|
|
213
260
|
},
|
|
@@ -228,7 +275,11 @@ const KeywordValidation = {
|
|
|
228
275
|
}
|
|
229
276
|
const lengthOfString = ucs2decode(value).length;
|
|
230
277
|
if (schema.minLength > lengthOfString) {
|
|
231
|
-
return core.errors.minLengthError({
|
|
278
|
+
return core.errors.minLengthError({
|
|
279
|
+
minLength: schema.minLength,
|
|
280
|
+
length: lengthOfString,
|
|
281
|
+
pointer
|
|
282
|
+
});
|
|
232
283
|
}
|
|
233
284
|
return undefined;
|
|
234
285
|
},
|
|
@@ -249,7 +300,11 @@ const KeywordValidation = {
|
|
|
249
300
|
return undefined;
|
|
250
301
|
}
|
|
251
302
|
if (schema.minItems > value.length) {
|
|
252
|
-
return core.errors.minItemsError({
|
|
303
|
+
return core.errors.minItemsError({
|
|
304
|
+
minItems: schema.minItems,
|
|
305
|
+
length: value.length,
|
|
306
|
+
pointer
|
|
307
|
+
});
|
|
253
308
|
}
|
|
254
309
|
return undefined;
|
|
255
310
|
},
|
|
@@ -261,7 +316,8 @@ const KeywordValidation = {
|
|
|
261
316
|
if (schema.minProperties > propertyCount) {
|
|
262
317
|
return core.errors.minPropertiesError({
|
|
263
318
|
minProperties: schema.minProperties,
|
|
264
|
-
length: propertyCount,
|
|
319
|
+
length: propertyCount,
|
|
320
|
+
pointer
|
|
265
321
|
});
|
|
266
322
|
}
|
|
267
323
|
return undefined;
|
|
@@ -272,9 +328,10 @@ const KeywordValidation = {
|
|
|
272
328
|
}
|
|
273
329
|
// https://github.com/cfworker/cfworker/blob/master/packages/json-schema/src/validate.ts#L1061
|
|
274
330
|
// https://github.com/ExodusMovement/schemasafe/blob/master/src/compile.js#L441
|
|
275
|
-
if ((value * FPP) % (schema.multipleOf * FPP) / FPP !== 0) {
|
|
331
|
+
if (((value * FPP) % (schema.multipleOf * FPP)) / FPP !== 0) {
|
|
276
332
|
return core.errors.multipleOfError({ multipleOf: schema.multipleOf, value, pointer });
|
|
277
333
|
}
|
|
334
|
+
// also check https://stackoverflow.com/questions/1815367/catch-and-compute-overflow-during-multiplication-of-two-large-integers
|
|
278
335
|
return undefined;
|
|
279
336
|
},
|
|
280
337
|
not: (core, schema, value, pointer) => {
|
|
@@ -290,7 +347,7 @@ const KeywordValidation = {
|
|
|
290
347
|
}
|
|
291
348
|
|
|
292
349
|
schema = core.resolveOneOf(value, schema, pointer);
|
|
293
|
-
if (schema
|
|
350
|
+
if (isJSONError(schema)) {
|
|
294
351
|
return schema;
|
|
295
352
|
}
|
|
296
353
|
|
|
@@ -302,7 +359,8 @@ const KeywordValidation = {
|
|
|
302
359
|
return core.errors.patternError({
|
|
303
360
|
pattern: schema.pattern,
|
|
304
361
|
description: schema.patternExample || schema.pattern,
|
|
305
|
-
received: value,
|
|
362
|
+
received: value,
|
|
363
|
+
pointer
|
|
306
364
|
});
|
|
307
365
|
}
|
|
308
366
|
return undefined;
|
|
@@ -316,18 +374,22 @@ const KeywordValidation = {
|
|
|
316
374
|
|
|
317
375
|
const errors = [];
|
|
318
376
|
const keys = Object.keys(value);
|
|
319
|
-
const patterns = Object.keys(pp).map(expr => ({
|
|
377
|
+
const patterns = Object.keys(pp).map((expr) => ({
|
|
320
378
|
regex: new RegExp(expr),
|
|
321
379
|
patternSchema: pp[expr]
|
|
322
380
|
}));
|
|
323
381
|
|
|
324
|
-
keys.forEach(key => {
|
|
382
|
+
keys.forEach((key) => {
|
|
325
383
|
let patternFound = false;
|
|
326
384
|
|
|
327
385
|
for (let i = 0, l = patterns.length; i < l; i += 1) {
|
|
328
386
|
if (patterns[i].regex.test(key)) {
|
|
329
387
|
patternFound = true;
|
|
330
|
-
const valErrors = core.validate(
|
|
388
|
+
const valErrors = core.validate(
|
|
389
|
+
value[key],
|
|
390
|
+
patterns[i].patternSchema,
|
|
391
|
+
`${pointer}/${key}`
|
|
392
|
+
);
|
|
331
393
|
if (valErrors && valErrors.length > 0) {
|
|
332
394
|
errors.push(...valErrors);
|
|
333
395
|
}
|
|
@@ -340,9 +402,13 @@ const KeywordValidation = {
|
|
|
340
402
|
|
|
341
403
|
if (patternFound === false && schema.additionalProperties === false) {
|
|
342
404
|
// this is an arrangement with additionalProperties
|
|
343
|
-
errors.push(
|
|
344
|
-
|
|
345
|
-
|
|
405
|
+
errors.push(
|
|
406
|
+
core.errors.patternPropertiesError({
|
|
407
|
+
key,
|
|
408
|
+
pointer,
|
|
409
|
+
patterns: Object.keys(pp).join(",")
|
|
410
|
+
})
|
|
411
|
+
);
|
|
346
412
|
}
|
|
347
413
|
});
|
|
348
414
|
|
|
@@ -353,7 +419,7 @@ const KeywordValidation = {
|
|
|
353
419
|
const keys = Object.keys(schema.properties || {});
|
|
354
420
|
for (let i = 0; i < keys.length; i += 1) {
|
|
355
421
|
const key = keys[i];
|
|
356
|
-
if (value
|
|
422
|
+
if (hasProperty(value, key)) {
|
|
357
423
|
const itemSchema = core.step(key, schema, value, pointer);
|
|
358
424
|
const keyErrors = core.validate(value[key], itemSchema, `${pointer}/${key}`);
|
|
359
425
|
errors.push(...keyErrors);
|
|
@@ -377,13 +443,13 @@ const KeywordValidation = {
|
|
|
377
443
|
}
|
|
378
444
|
return errors;
|
|
379
445
|
},
|
|
380
|
-
required: (core, schema, value, pointer) => {
|
|
446
|
+
required: (core, schema, value: Record<string, unknown>, pointer) => {
|
|
381
447
|
if (Array.isArray(schema.required) === false) {
|
|
382
448
|
return undefined;
|
|
383
449
|
}
|
|
384
450
|
|
|
385
|
-
return schema.required.map(property => {
|
|
386
|
-
if (value
|
|
451
|
+
return schema.required.map((property: string) => {
|
|
452
|
+
if (!hasProperty(value, property)) {
|
|
387
453
|
return core.errors.requiredPropertyError({ key: property, pointer });
|
|
388
454
|
}
|
|
389
455
|
return undefined;
|
|
@@ -395,9 +461,12 @@ const KeywordValidation = {
|
|
|
395
461
|
return undefined;
|
|
396
462
|
}
|
|
397
463
|
|
|
398
|
-
return schema.required.map(property => {
|
|
464
|
+
return schema.required.map((property) => {
|
|
399
465
|
if (value[property] == null || value[property] === "") {
|
|
400
|
-
return core.errors.valueNotEmptyError({
|
|
466
|
+
return core.errors.valueNotEmptyError({
|
|
467
|
+
property,
|
|
468
|
+
pointer: `${pointer}/${property}`
|
|
469
|
+
});
|
|
401
470
|
}
|
|
402
471
|
return undefined;
|
|
403
472
|
});
|
|
@@ -411,12 +480,14 @@ const KeywordValidation = {
|
|
|
411
480
|
value.forEach((item, index) => {
|
|
412
481
|
for (let i = index + 1; i < value.length; i += 1) {
|
|
413
482
|
if (isSame(item, value[i])) {
|
|
414
|
-
errors.push(
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
483
|
+
errors.push(
|
|
484
|
+
core.errors.uniqueItemsError({
|
|
485
|
+
pointer,
|
|
486
|
+
itemPointer: `${pointer}/${index}`,
|
|
487
|
+
duplicatePointer: `${pointer}/${i}`,
|
|
488
|
+
value: JSON.stringify(item)
|
|
489
|
+
})
|
|
490
|
+
);
|
|
420
491
|
}
|
|
421
492
|
}
|
|
422
493
|
});
|
|
@@ -425,6 +496,4 @@ const KeywordValidation = {
|
|
|
425
496
|
}
|
|
426
497
|
};
|
|
427
498
|
|
|
428
|
-
|
|
429
499
|
export default KeywordValidation;
|
|
430
|
-
|
package/lib/validation/type.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { JSONTypeValidator } from "../types";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @todo: type is also a keyword, as is properties, items, etc
|
|
3
5
|
*
|
|
@@ -5,7 +7,7 @@
|
|
|
5
7
|
* or seven in case of ajv https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md#type
|
|
6
8
|
* 1 null, 2 boolean, 3 object, 4 array, 5 number, 6 string (7 integer)
|
|
7
9
|
*/
|
|
8
|
-
|
|
10
|
+
const typeValidators: Record<string, JSONTypeValidator> = {
|
|
9
11
|
|
|
10
12
|
array: (core, schema, value, pointer) =>
|
|
11
13
|
core.typeKeywords.array
|
|
@@ -42,3 +44,5 @@ export default {
|
|
|
42
44
|
.filter(key => schema && schema[key] != null)
|
|
43
45
|
.map(key => core.validateKeyword[key](core, schema, value, pointer))
|
|
44
46
|
};
|
|
47
|
+
|
|
48
|
+
export default typeValidators;
|
package/package.json
CHANGED
|
@@ -1,65 +1,75 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
2
|
+
"name": "json-schema-library",
|
|
3
|
+
"version": "6.1.0",
|
|
4
|
+
"description": "Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation",
|
|
5
|
+
"module": "dist/module/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "dist/jsonSchemaLibrary.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dist": "rm -rf dist; yarn dist:es5 && yarn dist:es6",
|
|
10
|
+
"dist:es5": "NODE_ENV=production webpack",
|
|
11
|
+
"dist:es6": "tsc --outDir dist/module --target ES2019",
|
|
12
|
+
"test": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/**/*.test.ts'",
|
|
13
|
+
"test:integration": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/integration/**/*.test.ts'",
|
|
14
|
+
"test:unit": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/unit/**/*.test.ts'",
|
|
15
|
+
"test:spec": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/spec/**/*.test.ts'",
|
|
16
|
+
"test:4": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/spec/v4/*.test.ts'",
|
|
17
|
+
"test:6": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/spec/v6/*.test.ts'",
|
|
18
|
+
"test:7": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/spec/v7/*.test.ts'",
|
|
19
|
+
"test:2019": "TS_NODE_PROJECT=./test/tsconfig.json mocha -r ts-node/register -R spec 'test/spec/v2019-09/*.test.ts'",
|
|
20
|
+
"tdd": "watch \"npm run test:unit\" lib/ test/",
|
|
21
|
+
"coverage": "nyc npm run test --reporter=lcov",
|
|
22
|
+
"analyze": "NODE_ENV=production webpack --json | webpack-bundle-size-analyzer",
|
|
23
|
+
"lint": "eslint lib",
|
|
24
|
+
"prepublishOnly": "yarn dist"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/sagold/json-schema-library.git"
|
|
29
|
+
},
|
|
30
|
+
"author": "Sascha Goldhofer <github@saschagoldhofer.de> (https://github.com/sagold/)",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/sagold/json-schema-library/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/sagold/json-schema-library",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/chai": "^4.2.14",
|
|
38
|
+
"@types/mocha": "^9.1.1",
|
|
39
|
+
"@types/node": "^14.14.10",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.20.0",
|
|
42
|
+
"chai": "^4.2.0",
|
|
43
|
+
"chalk": "^2.3.0",
|
|
44
|
+
"eslint": "^8.14.0",
|
|
45
|
+
"eslint-plugin-array-func": "^3.1.7",
|
|
46
|
+
"eslint-plugin-node": "^11.1.0",
|
|
47
|
+
"eslint-plugin-optimize-regex": "^1.2.0",
|
|
48
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
49
|
+
"glob": "^8.0.1",
|
|
50
|
+
"json-schema-test-suite": "https://github.com/json-schema-org/JSON-Schema-Test-Suite",
|
|
51
|
+
"mocha": "^9.2.2",
|
|
52
|
+
"nyc": "^15.1.0",
|
|
53
|
+
"terser-webpack-plugin": "^5.0.3",
|
|
54
|
+
"ts-loader": "^9.2.8",
|
|
55
|
+
"ts-node": "^10.7.0",
|
|
56
|
+
"typescript": "^4.6.4",
|
|
57
|
+
"watch": "^1.0.1",
|
|
58
|
+
"webpack": "^5.9.0",
|
|
59
|
+
"webpack-cli": "^4.2.0"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"deepmerge": "^4.2.2",
|
|
63
|
+
"fast-deep-equal": "^3.1.3",
|
|
64
|
+
"gson-pointer": "^4.1.1",
|
|
65
|
+
"gson-query": "^5.1.0",
|
|
66
|
+
"valid-url": "^1.0.9"
|
|
67
|
+
},
|
|
68
|
+
"resolutions": {
|
|
69
|
+
"lodash": "4.x",
|
|
70
|
+
"merge": "2.x"
|
|
71
|
+
},
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"registry": "https://registry.npmjs.org"
|
|
74
|
+
}
|
|
65
75
|
}
|