z-schema 7.0.9 → 7.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/README.md +237 -483
- package/cjs/index.d.ts +9 -2
- package/cjs/index.js +356 -7314
- package/dist/format-validators.js +7 -6
- package/dist/json-validation.js +12 -4
- package/dist/schema-cache.js +22 -3
- package/dist/schema-compiler.js +127 -37
- package/dist/schema-validator.js +10 -10
- package/dist/types/schema-cache.d.ts +3 -0
- package/dist/types/schema-compiler.d.ts +14 -1
- package/dist/types/utils/properties.d.ts +2 -0
- package/dist/types/utils/schema-regex.d.ts +10 -0
- package/dist/types/z-schema.d.ts +2 -1
- package/dist/utils/clone.js +3 -3
- package/dist/utils/properties.js +15 -0
- package/dist/utils/schema-regex.js +39 -0
- package/dist/utils/uri.js +1 -1
- package/dist/z-schema.js +16 -4
- package/package.json +11 -18
- package/src/format-validators.ts +7 -7
- package/src/json-validation.ts +12 -4
- package/src/schema-cache.ts +24 -3
- package/src/schema-compiler.ts +144 -36
- package/src/schema-validator.ts +10 -8
- package/src/utils/clone.ts +4 -3
- package/src/utils/properties.ts +16 -0
- package/src/utils/schema-regex.ts +39 -0
- package/src/utils/uri.ts +1 -1
- package/src/z-schema.ts +20 -5
- package/umd/ZSchema.js +356 -7314
- package/umd/ZSchema.min.js +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
## Topics
|
|
8
8
|
|
|
9
9
|
- [What](#what)
|
|
10
|
+
- [Versions](#versions)
|
|
10
11
|
- [Usage](#usage)
|
|
11
12
|
- [Features](#features)
|
|
12
13
|
- [Options](#options)
|
|
@@ -17,6 +18,11 @@
|
|
|
17
18
|
|
|
18
19
|
What is a JSON Schema? Find here: [https://json-schema.org/](https://json-schema.org/)
|
|
19
20
|
|
|
21
|
+
## Versions
|
|
22
|
+
|
|
23
|
+
- v6 - old version which has been around a long time, supports JSON Schema draft-04
|
|
24
|
+
- v7 - modernized version (to ESM module with Typescript) which passes all tests from JSON Schema Test Suite for draft-04
|
|
25
|
+
|
|
20
26
|
## Usage
|
|
21
27
|
|
|
22
28
|
Validator will try to perform sync validation when possible for speed, but supports async callbacks when they are necessary.
|
|
@@ -118,489 +124,13 @@ ZSchema.setSchemaReader(function (uri) {
|
|
|
118
124
|
|
|
119
125
|
## Features
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
- [Compile arrays of schemas and use references between them](#compile-arrays-of-schemas-and-use-references-between-them)
|
|
123
|
-
- [Register a custom format](#register-a-custom-format)
|
|
124
|
-
- [Automatic downloading of remote schemas](#automatic-downloading-of-remote-schemas)
|
|
125
|
-
- [Prefill default values to object using format](#prefill-default-values-to-object-using-format)
|
|
126
|
-
- [Define a custom timeout for all async operations](#asynctimeout)
|
|
127
|
-
- [Disallow validation of empty arrays as arrays](#noemptyarrays)
|
|
128
|
-
- [Disallow validation of empty strings as strings](#noemptystrings)
|
|
129
|
-
- [Disallow schemas that don't have a type specified](#notypeless)
|
|
130
|
-
- [Disallow schemas that contain unrecognized keywords and are not validated by parent schemas](#noextrakeywords)
|
|
131
|
-
- [Assume additionalItems/additionalProperties are defined in schemas as false](#assumeadditional)
|
|
132
|
-
- [Force additionalItems/additionalProperties to be defined in schemas](#forceadditional)
|
|
133
|
-
- [Force items to be defined in array type schemas](#forceitems)
|
|
134
|
-
- [Force minItems to be defined in array type schemas](#forceminitems)
|
|
135
|
-
- [Force maxItems to be defined in array type schemas](#forcemaxitems)
|
|
136
|
-
- [Force minLength to be defined in string type schemas](#forceminlength)
|
|
137
|
-
- [Force maxLength to be defined in string type schemas](#forcemaxlength)
|
|
138
|
-
- [Force properties or patternProperties to be defined in object type schemas](#forceproperties)
|
|
139
|
-
- [Ignore remote references to schemas that are not cached or resolvable](#ignoreunresolvablereferences)
|
|
140
|
-
- [Ignore case mismatch when validating enum values](#enumCaseInsensitiveComparison)
|
|
141
|
-
- [Only allow strictly absolute URIs to be used in schemas](#stricturis)
|
|
142
|
-
- [Turn on z-schema strict mode](#strictmode)
|
|
143
|
-
- [Set validator to collect as many errors as possible](#breakonfirsterror)
|
|
144
|
-
- [Report paths in errors as arrays so they can be processed easier](#reportpathasarray)
|
|
145
|
-
|
|
146
|
-
### Validate against subschema
|
|
147
|
-
|
|
148
|
-
In case you don't want to split your schema into multiple schemas using reference for any reason, you can use option schemaPath when validating:
|
|
149
|
-
|
|
150
|
-
```javascript
|
|
151
|
-
var valid = validator.validate(cars, schema, { schemaPath: 'definitions.car.definitions.cars' });
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
See more details in the [test](/test/spec/schemaPathSpec.js).
|
|
155
|
-
|
|
156
|
-
### Compile arrays of schemas and use references between them
|
|
157
|
-
|
|
158
|
-
You can use validator to compile an array of schemas that have references between them and then validate against one of those schemas:
|
|
159
|
-
|
|
160
|
-
```javascript
|
|
161
|
-
var schemas = [
|
|
162
|
-
{
|
|
163
|
-
id: 'personDetails',
|
|
164
|
-
type: 'object',
|
|
165
|
-
properties: {
|
|
166
|
-
firstName: { type: 'string' },
|
|
167
|
-
lastName: { type: 'string' },
|
|
168
|
-
},
|
|
169
|
-
required: ['firstName', 'lastName'],
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
id: 'addressDetails',
|
|
173
|
-
type: 'object',
|
|
174
|
-
properties: {
|
|
175
|
-
street: { type: 'string' },
|
|
176
|
-
city: { type: 'string' },
|
|
177
|
-
},
|
|
178
|
-
required: ['street', 'city'],
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
id: 'personWithAddress',
|
|
182
|
-
allOf: [{ $ref: 'personDetails' }, { $ref: 'addressDetails' }],
|
|
183
|
-
},
|
|
184
|
-
];
|
|
185
|
-
|
|
186
|
-
var data = {
|
|
187
|
-
firstName: 'Martin',
|
|
188
|
-
lastName: 'Zagora',
|
|
189
|
-
street: 'George St',
|
|
190
|
-
city: 'Sydney',
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
var validator = new ZSchema();
|
|
194
|
-
|
|
195
|
-
// compile & validate schemas first, z-schema will automatically handle array
|
|
196
|
-
var allSchemasValid = validator.validateSchema(schemas);
|
|
197
|
-
// allSchemasValid === true
|
|
198
|
-
|
|
199
|
-
// now validate our data against the last schema
|
|
200
|
-
var valid = validator.validate(data, schemas[2]);
|
|
201
|
-
// valid === true
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
## Register a custom format
|
|
205
|
-
|
|
206
|
-
You can register any format of your own. Your sync validator function should always respond with a boolean:
|
|
207
|
-
|
|
208
|
-
```javascript
|
|
209
|
-
ZSchema.registerFormat('xstring', function (str) {
|
|
210
|
-
return str === 'xxx';
|
|
211
|
-
});
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Async format validators are also supported, they should accept two arguments, value and a callback to which they need to respond:
|
|
215
|
-
|
|
216
|
-
```javascript
|
|
217
|
-
ZSchema.registerFormat('xstring', function (str, callback) {
|
|
218
|
-
setTimeout(function () {
|
|
219
|
-
callback(str === 'xxx');
|
|
220
|
-
}, 1);
|
|
221
|
-
});
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
### Helper method to check the formats that have been registered
|
|
225
|
-
|
|
226
|
-
```javascript
|
|
227
|
-
var registeredFormats = ZSchema.getRegisteredFormats();
|
|
228
|
-
//registeredFormats will now contain an array of all formats that have been registered with z-schema
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
### Automatic downloading of remote schemas
|
|
232
|
-
|
|
233
|
-
Automatic downloading of remote schemas was removed from version `3.x` but is still possible with a bit of extra code,
|
|
234
|
-
see [this test](test/spec/AutomaticSchemaLoadingSpec.js) for more information on this.
|
|
235
|
-
|
|
236
|
-
### Prefill default values to object using format
|
|
237
|
-
|
|
238
|
-
Using format, you can pre-fill values of your choosing into the objects like this:
|
|
239
|
-
|
|
240
|
-
```javascript
|
|
241
|
-
ZSchema.registerFormat('fillHello', function (obj) {
|
|
242
|
-
obj.hello = 'world';
|
|
243
|
-
return true;
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
var data = {};
|
|
247
|
-
|
|
248
|
-
var schema = {
|
|
249
|
-
type: 'object',
|
|
250
|
-
format: 'fillHello',
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
validator.validate(data, schema);
|
|
254
|
-
// data.hello === "world"
|
|
255
|
-
```
|
|
127
|
+
See [FEATURES.md](FEATURES.md) for a full list of features.
|
|
256
128
|
|
|
257
129
|
## Options
|
|
258
130
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
Defines a time limit, which should be used when waiting for async tasks like async format validators to perform their validation,
|
|
262
|
-
before the validation fails with an `ASYNC_TIMEOUT` error.
|
|
263
|
-
|
|
264
|
-
```javascript
|
|
265
|
-
var validator = new ZSchema({
|
|
266
|
-
asyncTimeout: 2000,
|
|
267
|
-
});
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### noEmptyArrays
|
|
271
|
-
|
|
272
|
-
When true, validator will assume that minimum count of items in any `array` is 1, except when `minItems: 0` is explicitly defined.
|
|
273
|
-
|
|
274
|
-
```javascript
|
|
275
|
-
var validator = new ZSchema({
|
|
276
|
-
noEmptyArrays: true,
|
|
277
|
-
});
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
### noEmptyStrings
|
|
281
|
-
|
|
282
|
-
When true, validator will assume that minimum length of any string to pass type `string` validation is 1, except when `minLength: 0` is explicitly defined.
|
|
283
|
-
|
|
284
|
-
```javascript
|
|
285
|
-
var validator = new ZSchema({
|
|
286
|
-
noEmptyStrings: true,
|
|
287
|
-
});
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### noTypeless
|
|
291
|
-
|
|
292
|
-
When true, validator will fail validation for schemas that don't specify a `type` of object that they expect.
|
|
293
|
-
|
|
294
|
-
```javascript
|
|
295
|
-
var validator = new ZSchema({
|
|
296
|
-
noTypeless: true,
|
|
297
|
-
});
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
### noExtraKeywords
|
|
301
|
-
|
|
302
|
-
When true, validator will fail for schemas that use keywords not defined in JSON Schema specification and doesn't provide a parent schema in `$schema` property to validate the schema.
|
|
303
|
-
|
|
304
|
-
```javascript
|
|
305
|
-
var validator = new ZSchema({
|
|
306
|
-
noExtraKeywords: true,
|
|
307
|
-
});
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### assumeAdditional
|
|
311
|
-
|
|
312
|
-
When true, validator assumes that additionalItems/additionalProperties are defined as false so you don't have to manually fix all your schemas.
|
|
313
|
-
|
|
314
|
-
```javascript
|
|
315
|
-
var validator = new ZSchema({
|
|
316
|
-
assumeAdditional: true,
|
|
317
|
-
});
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
When an array, validator assumes that additionalItems/additionalProperties are defined as false, but allows some properties to pass.
|
|
321
|
-
|
|
322
|
-
```javascript
|
|
323
|
-
var validator = new ZSchema({
|
|
324
|
-
assumeAdditional: ['$ref'],
|
|
325
|
-
});
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### forceAdditional
|
|
329
|
-
|
|
330
|
-
When true, validator doesn't validate schemas where additionalItems/additionalProperties should be defined to either true or false.
|
|
331
|
-
|
|
332
|
-
```javascript
|
|
333
|
-
var validator = new ZSchema({
|
|
334
|
-
forceAdditional: true,
|
|
335
|
-
});
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
### forceItems
|
|
339
|
-
|
|
340
|
-
When true, validator doesn't validate schemas where `items` are not defined for `array` type schemas.
|
|
341
|
-
This is to avoid passing anything through an array definition.
|
|
342
|
-
|
|
343
|
-
```javascript
|
|
344
|
-
var validator = new ZSchema({
|
|
345
|
-
forceItems: true,
|
|
346
|
-
});
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
### forceMinItems
|
|
350
|
-
|
|
351
|
-
When true, validator doesn't validate schemas where `minItems` is not defined for `array` type schemas.
|
|
352
|
-
This is to avoid passing zero-length arrays which application doesn't expect to handle.
|
|
353
|
-
|
|
354
|
-
```javascript
|
|
355
|
-
var validator = new ZSchema({
|
|
356
|
-
forceMinItems: true,
|
|
357
|
-
});
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
### forceMaxItems
|
|
131
|
+
See [OPTIONS.md](OPTIONS.md) for all available options and their descriptions.
|
|
361
132
|
|
|
362
|
-
|
|
363
|
-
This is to avoid passing arrays with unlimited count of elements which application doesn't expect to handle.
|
|
364
|
-
|
|
365
|
-
```javascript
|
|
366
|
-
var validator = new ZSchema({
|
|
367
|
-
forceMaxItems: true,
|
|
368
|
-
});
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
### forceMinLength
|
|
372
|
-
|
|
373
|
-
When true, validator doesn't validate schemas where `minLength` is not defined for `string` type schemas.
|
|
374
|
-
This is to avoid passing zero-length strings which application doesn't expect to handle.
|
|
375
|
-
|
|
376
|
-
```javascript
|
|
377
|
-
var validator = new ZSchema({
|
|
378
|
-
forceMinLength: true,
|
|
379
|
-
});
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
### forceMaxLength
|
|
383
|
-
|
|
384
|
-
When true, validator doesn't validate schemas where `maxLength` is not defined for `string` type schemas.
|
|
385
|
-
This is to avoid passing extremly large strings which application doesn't expect to handle.
|
|
386
|
-
|
|
387
|
-
```javascript
|
|
388
|
-
var validator = new ZSchema({
|
|
389
|
-
forceMaxLength: true,
|
|
390
|
-
});
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
### forceProperties
|
|
394
|
-
|
|
395
|
-
When true, validator doesn't validate schemas where `properties` or `patternProperties` is not defined for `object` type schemas.
|
|
396
|
-
This is to avoid having objects with unexpected properties in application.
|
|
397
|
-
|
|
398
|
-
```javascript
|
|
399
|
-
var validator = new ZSchema({
|
|
400
|
-
forceProperties: true,
|
|
401
|
-
});
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
### ignoreUnresolvableReferences
|
|
405
|
-
|
|
406
|
-
When true, validator doesn't end with error when a remote reference is unreachable. **This setting is not recommended in production outside of testing.**
|
|
407
|
-
|
|
408
|
-
```javascript
|
|
409
|
-
var validator = new ZSchema({
|
|
410
|
-
ignoreUnresolvableReferences: true,
|
|
411
|
-
});
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
### enumCaseInsensitiveComparison
|
|
415
|
-
|
|
416
|
-
When true, validator will return a `ENUM_CASE_MISMATCH` when the enum values mismatch only in case.
|
|
417
|
-
|
|
418
|
-
```javascript
|
|
419
|
-
var validator = new ZSchema({
|
|
420
|
-
enumCaseInsensitiveComparison: true,
|
|
421
|
-
});
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
### strictUris
|
|
425
|
-
|
|
426
|
-
When true, all strings of format `uri` must be an absolute URIs and not only URI references. See more details in [this issue](https://github.com/zaggino/z-schema/issues/18).
|
|
427
|
-
|
|
428
|
-
```javascript
|
|
429
|
-
var validator = new ZSchema({
|
|
430
|
-
strictUris: true,
|
|
431
|
-
});
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
### strictMode
|
|
435
|
-
|
|
436
|
-
Strict mode of z-schema is currently equal to the following:
|
|
437
|
-
|
|
438
|
-
```javascript
|
|
439
|
-
if (this.options.strictMode === true) {
|
|
440
|
-
this.options.forceAdditional = true;
|
|
441
|
-
this.options.forceItems = true;
|
|
442
|
-
this.options.forceMaxLength = true;
|
|
443
|
-
this.options.forceProperties = true;
|
|
444
|
-
this.options.noExtraKeywords = true;
|
|
445
|
-
this.options.noTypeless = true;
|
|
446
|
-
this.options.noEmptyStrings = true;
|
|
447
|
-
this.options.noEmptyArrays = true;
|
|
448
|
-
}
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
```javascript
|
|
452
|
-
var validator = new ZSchema({
|
|
453
|
-
strictMode: true,
|
|
454
|
-
});
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
### breakOnFirstError
|
|
458
|
-
|
|
459
|
-
default: `false`<br />
|
|
460
|
-
When true, will stop validation after the first error is found:
|
|
461
|
-
|
|
462
|
-
```javascript
|
|
463
|
-
var validator = new ZSchema({
|
|
464
|
-
breakOnFirstError: true,
|
|
465
|
-
});
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
### reportPathAsArray
|
|
469
|
-
|
|
470
|
-
Report error paths as an array of path segments instead of a string:
|
|
471
|
-
|
|
472
|
-
```javascript
|
|
473
|
-
var validator = new ZSchema({
|
|
474
|
-
reportPathAsArray: true,
|
|
475
|
-
});
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
### ignoreUnknownFormats
|
|
479
|
-
|
|
480
|
-
By default, z-schema reports all unknown formats, formats not defined by JSON Schema and not registered using
|
|
481
|
-
`ZSchema.registerFormat`, as an error. But the
|
|
482
|
-
[JSON Schema specification](http://json-schema.org/latest/json-schema-validation.html#anchor106) says that validator
|
|
483
|
-
implementations _"they SHOULD offer an option to disable validation"_ for `format`. That being said, setting this
|
|
484
|
-
option to `true` will disable treating unknown formats as errlrs
|
|
485
|
-
|
|
486
|
-
```javascript
|
|
487
|
-
var validator = new ZSchema({
|
|
488
|
-
ignoreUnknownFormats: true,
|
|
489
|
-
});
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
### includeErrors
|
|
493
|
-
|
|
494
|
-
By default, z-schema reports all errors. If interested only in a subset of the errors, passing the option `includeErrors` to `validate` will perform validations only for those errors.
|
|
495
|
-
|
|
496
|
-
```javascript
|
|
497
|
-
var validator = new ZSchema();
|
|
498
|
-
// will only execute validation for "INVALID_TYPE" error.
|
|
499
|
-
validator.validate(json, schema, { includeErrors: ['INVALID_TYPE'] });
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
### customValidator
|
|
503
|
-
|
|
504
|
-
**Warning**: Use only if know what you are doing. Always consider using [custom format](#register-a-custom-format) before using this option.
|
|
505
|
-
|
|
506
|
-
Register function to be called as part of validation process on every subshema encounter during validation.
|
|
507
|
-
|
|
508
|
-
Let's make a real-life example with this feature.
|
|
509
|
-
Imagine you have number of transactions:
|
|
510
|
-
|
|
511
|
-
```json
|
|
512
|
-
{
|
|
513
|
-
"fromId": 1034834329,
|
|
514
|
-
"toId": 1034834543,
|
|
515
|
-
"amount": 200
|
|
516
|
-
}
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
So you write the schema:
|
|
520
|
-
|
|
521
|
-
```json
|
|
522
|
-
{
|
|
523
|
-
"type": "object",
|
|
524
|
-
"properties": {
|
|
525
|
-
"fromId": {
|
|
526
|
-
"type": "integer"
|
|
527
|
-
},
|
|
528
|
-
"toId": {
|
|
529
|
-
"type": "integer"
|
|
530
|
-
},
|
|
531
|
-
"amount": {
|
|
532
|
-
"type": "number"
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
But how to check that `fromId` and `toId` are never equal.
|
|
539
|
-
In JSON Schema Draft4 there is no possibility to do this.
|
|
540
|
-
Actually, it's easy to just write validation code for such simple payloads.
|
|
541
|
-
But what if you have to do the same check for many objects in different places of JSON payload.
|
|
542
|
-
One solution is to add custom keyword `uniqueProperties` with array of property names as a value. So in our schema we would need to add:
|
|
543
|
-
|
|
544
|
-
```json
|
|
545
|
-
"uniqueProperties": [
|
|
546
|
-
"fromId",
|
|
547
|
-
"toId"
|
|
548
|
-
]
|
|
549
|
-
```
|
|
550
|
-
|
|
551
|
-
To teach `z-schema` about this new keyword we need to write handler for it:
|
|
552
|
-
|
|
553
|
-
```javascript
|
|
554
|
-
function customValidatorFn(report, schema, json) {
|
|
555
|
-
// check if our custom property is present
|
|
556
|
-
if (Array.isArray(schema.uniqueProperties)) {
|
|
557
|
-
var seenValues = [];
|
|
558
|
-
schema.uniqueProperties.forEach(function (prop) {
|
|
559
|
-
var value = json[prop];
|
|
560
|
-
if (typeof value !== 'undefined') {
|
|
561
|
-
if (seenValues.indexOf(value) !== -1) {
|
|
562
|
-
// report error back to z-schema core
|
|
563
|
-
report.addCustomError(
|
|
564
|
-
'NON_UNIQUE_PROPERTY_VALUE',
|
|
565
|
-
'Property "{0}" has non-unique value: {1}',
|
|
566
|
-
[prop, value],
|
|
567
|
-
null,
|
|
568
|
-
schema.description
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
seenValues.push(value);
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
var validator = new ZSchema({
|
|
578
|
-
// register our custom validator inside z-schema
|
|
579
|
-
customValidator: customValidatorFn,
|
|
580
|
-
});
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
Let's test it:
|
|
584
|
-
|
|
585
|
-
```javascript
|
|
586
|
-
var data = {
|
|
587
|
-
fromId: 1034834346,
|
|
588
|
-
toId: 1034834346,
|
|
589
|
-
amount: 50,
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
validator.validate(data, schema);
|
|
593
|
-
console.log(validator.getLastErrors());
|
|
594
|
-
//[ { code: 'NON_UNIQUE_PROPERTY_VALUE',
|
|
595
|
-
// params: [ 'toId', 1034834346 ],
|
|
596
|
-
// message: 'Property "toId" has non-unique value: 1034834346',
|
|
597
|
-
// path: '#/',
|
|
598
|
-
// schemaId: undefined } ]
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
**Note:** before creating your own keywords you should consider all compatibility issues.
|
|
602
|
-
|
|
603
|
-
## Contributing:
|
|
133
|
+
## Contributing
|
|
604
134
|
|
|
605
135
|
These repository has several submodules and should be cloned as follows:
|
|
606
136
|
|
|
@@ -608,9 +138,233 @@ These repository has several submodules and should be cloned as follows:
|
|
|
608
138
|
|
|
609
139
|
## Contributors
|
|
610
140
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
-
|
|
614
|
-
|
|
141
|
+
Big thanks to:
|
|
142
|
+
|
|
143
|
+
<!-- readme: contributors -start -->
|
|
144
|
+
<table>
|
|
145
|
+
<tbody>
|
|
146
|
+
<tr>
|
|
147
|
+
<td align="center">
|
|
148
|
+
<a href="https://github.com/zaggino">
|
|
149
|
+
<img src="https://avatars.githubusercontent.com/u/1067319?v=4" width="100;" alt="zaggino"/>
|
|
150
|
+
<br />
|
|
151
|
+
<sub><b>Martin Zagora</b></sub>
|
|
152
|
+
</a>
|
|
153
|
+
</td>
|
|
154
|
+
<td align="center">
|
|
155
|
+
<a href="https://github.com/sergey-shandar">
|
|
156
|
+
<img src="https://avatars.githubusercontent.com/u/902339?v=4" width="100;" alt="sergey-shandar"/>
|
|
157
|
+
<br />
|
|
158
|
+
<sub><b>Sergey Shandar</b></sub>
|
|
159
|
+
</a>
|
|
160
|
+
</td>
|
|
161
|
+
<td align="center">
|
|
162
|
+
<a href="https://github.com/IvanGoncharov">
|
|
163
|
+
<img src="https://avatars.githubusercontent.com/u/8336157?v=4" width="100;" alt="IvanGoncharov"/>
|
|
164
|
+
<br />
|
|
165
|
+
<sub><b>Ivan Goncharov</b></sub>
|
|
166
|
+
</a>
|
|
167
|
+
</td>
|
|
168
|
+
<td align="center">
|
|
169
|
+
<a href="https://github.com/pgonzal">
|
|
170
|
+
<img src="https://avatars.githubusercontent.com/u/47177787?v=4" width="100;" alt="pgonzal"/>
|
|
171
|
+
<br />
|
|
172
|
+
<sub><b>Pete Gonzalez (OLD ALIAS)</b></sub>
|
|
173
|
+
</a>
|
|
174
|
+
</td>
|
|
175
|
+
<td align="center">
|
|
176
|
+
<a href="https://github.com/simon-p-r">
|
|
177
|
+
<img src="https://avatars.githubusercontent.com/u/4668724?v=4" width="100;" alt="simon-p-r"/>
|
|
178
|
+
<br />
|
|
179
|
+
<sub><b>Simon R</b></sub>
|
|
180
|
+
</a>
|
|
181
|
+
</td>
|
|
182
|
+
<td align="center">
|
|
183
|
+
<a href="https://github.com/TheToolbox">
|
|
184
|
+
<img src="https://avatars.githubusercontent.com/u/2837017?v=4" width="100;" alt="TheToolbox"/>
|
|
185
|
+
<br />
|
|
186
|
+
<sub><b>Jason Oettinger</b></sub>
|
|
187
|
+
</a>
|
|
188
|
+
</td>
|
|
189
|
+
</tr>
|
|
190
|
+
<tr>
|
|
191
|
+
<td align="center">
|
|
192
|
+
<a href="https://github.com/whitlockjc">
|
|
193
|
+
<img src="https://avatars.githubusercontent.com/u/98899?v=4" width="100;" alt="whitlockjc"/>
|
|
194
|
+
<br />
|
|
195
|
+
<sub><b>Jeremy Whitlock</b></sub>
|
|
196
|
+
</a>
|
|
197
|
+
</td>
|
|
198
|
+
<td align="center">
|
|
199
|
+
<a href="https://github.com/epoberezkin">
|
|
200
|
+
<img src="https://avatars.githubusercontent.com/u/2769109?v=4" width="100;" alt="epoberezkin"/>
|
|
201
|
+
<br />
|
|
202
|
+
<sub><b>Evgeny</b></sub>
|
|
203
|
+
</a>
|
|
204
|
+
</td>
|
|
205
|
+
<td align="center">
|
|
206
|
+
<a href="https://github.com/toofishes">
|
|
207
|
+
<img src="https://avatars.githubusercontent.com/u/265817?v=4" width="100;" alt="toofishes"/>
|
|
208
|
+
<br />
|
|
209
|
+
<sub><b>Dan McGee</b></sub>
|
|
210
|
+
</a>
|
|
211
|
+
</td>
|
|
212
|
+
<td align="center">
|
|
213
|
+
<a href="https://github.com/antialias">
|
|
214
|
+
<img src="https://avatars.githubusercontent.com/u/447517?v=4" width="100;" alt="antialias"/>
|
|
215
|
+
<br />
|
|
216
|
+
<sub><b>Thomas Hallock</b></sub>
|
|
217
|
+
</a>
|
|
218
|
+
</td>
|
|
219
|
+
<td align="center">
|
|
220
|
+
<a href="https://github.com/kallaspriit">
|
|
221
|
+
<img src="https://avatars.githubusercontent.com/u/277993?v=4" width="100;" alt="kallaspriit"/>
|
|
222
|
+
<br />
|
|
223
|
+
<sub><b>Priit Kallas</b></sub>
|
|
224
|
+
</a>
|
|
225
|
+
</td>
|
|
226
|
+
<td align="center">
|
|
227
|
+
<a href="https://github.com/santam85">
|
|
228
|
+
<img src="https://avatars.githubusercontent.com/u/2706307?v=4" width="100;" alt="santam85"/>
|
|
229
|
+
<br />
|
|
230
|
+
<sub><b>Marco Santarelli</b></sub>
|
|
231
|
+
</a>
|
|
232
|
+
</td>
|
|
233
|
+
</tr>
|
|
234
|
+
<tr>
|
|
235
|
+
<td align="center">
|
|
236
|
+
<a href="https://github.com/Hirse">
|
|
237
|
+
<img src="https://avatars.githubusercontent.com/u/2564094?v=4" width="100;" alt="Hirse"/>
|
|
238
|
+
<br />
|
|
239
|
+
<sub><b>Jan Pilzer</b></sub>
|
|
240
|
+
</a>
|
|
241
|
+
</td>
|
|
242
|
+
<td align="center">
|
|
243
|
+
<a href="https://github.com/geraintluff">
|
|
244
|
+
<img src="https://avatars.githubusercontent.com/u/1957191?v=4" width="100;" alt="geraintluff"/>
|
|
245
|
+
<br />
|
|
246
|
+
<sub><b>Geraint</b></sub>
|
|
247
|
+
</a>
|
|
248
|
+
</td>
|
|
249
|
+
<td align="center">
|
|
250
|
+
<a href="https://github.com/dgerber">
|
|
251
|
+
<img src="https://avatars.githubusercontent.com/u/393344?v=4" width="100;" alt="dgerber"/>
|
|
252
|
+
<br />
|
|
253
|
+
<sub><b>Daniel Gerber</b></sub>
|
|
254
|
+
</a>
|
|
255
|
+
</td>
|
|
256
|
+
<td align="center">
|
|
257
|
+
<a href="https://github.com/addaleax">
|
|
258
|
+
<img src="https://avatars.githubusercontent.com/u/899444?v=4" width="100;" alt="addaleax"/>
|
|
259
|
+
<br />
|
|
260
|
+
<sub><b>Anna Henningsen</b></sub>
|
|
261
|
+
</a>
|
|
262
|
+
</td>
|
|
263
|
+
<td align="center">
|
|
264
|
+
<a href="https://github.com/mctep">
|
|
265
|
+
<img src="https://avatars.githubusercontent.com/u/1949681?v=4" width="100;" alt="mctep"/>
|
|
266
|
+
<br />
|
|
267
|
+
<sub><b>Konstantin Vasilev</b></sub>
|
|
268
|
+
</a>
|
|
269
|
+
</td>
|
|
270
|
+
<td align="center">
|
|
271
|
+
<a href="https://github.com/barrtender">
|
|
272
|
+
<img src="https://avatars.githubusercontent.com/u/3101221?v=4" width="100;" alt="barrtender"/>
|
|
273
|
+
<br />
|
|
274
|
+
<sub><b>barrtender</b></sub>
|
|
275
|
+
</a>
|
|
276
|
+
</td>
|
|
277
|
+
</tr>
|
|
278
|
+
<tr>
|
|
279
|
+
<td align="center">
|
|
280
|
+
<a href="https://github.com/RomanHotsiy">
|
|
281
|
+
<img src="https://avatars.githubusercontent.com/u/3975738?v=4" width="100;" alt="RomanHotsiy"/>
|
|
282
|
+
<br />
|
|
283
|
+
<sub><b>Roman Hotsiy</b></sub>
|
|
284
|
+
</a>
|
|
285
|
+
</td>
|
|
286
|
+
<td align="center">
|
|
287
|
+
<a href="https://github.com/sauvainr">
|
|
288
|
+
<img src="https://avatars.githubusercontent.com/u/1715747?v=4" width="100;" alt="sauvainr"/>
|
|
289
|
+
<br />
|
|
290
|
+
<sub><b>RenaudS</b></sub>
|
|
291
|
+
</a>
|
|
292
|
+
</td>
|
|
293
|
+
<td align="center">
|
|
294
|
+
<a href="https://github.com/figadore">
|
|
295
|
+
<img src="https://avatars.githubusercontent.com/u/3253971?v=4" width="100;" alt="figadore"/>
|
|
296
|
+
<br />
|
|
297
|
+
<sub><b>Reese</b></sub>
|
|
298
|
+
</a>
|
|
299
|
+
</td>
|
|
300
|
+
<td align="center">
|
|
301
|
+
<a href="https://github.com/MattiSG">
|
|
302
|
+
<img src="https://avatars.githubusercontent.com/u/222463?v=4" width="100;" alt="MattiSG"/>
|
|
303
|
+
<br />
|
|
304
|
+
<sub><b>Matti Schneider</b></sub>
|
|
305
|
+
</a>
|
|
306
|
+
</td>
|
|
307
|
+
<td align="center">
|
|
308
|
+
<a href="https://github.com/sandersky">
|
|
309
|
+
<img src="https://avatars.githubusercontent.com/u/422902?v=4" width="100;" alt="sandersky"/>
|
|
310
|
+
<br />
|
|
311
|
+
<sub><b>Matthew Dahl</b></sub>
|
|
312
|
+
</a>
|
|
313
|
+
</td>
|
|
314
|
+
<td align="center">
|
|
315
|
+
<a href="https://github.com/jfromaniello">
|
|
316
|
+
<img src="https://avatars.githubusercontent.com/u/178512?v=4" width="100;" alt="jfromaniello"/>
|
|
317
|
+
<br />
|
|
318
|
+
<sub><b>José F. Romaniello</b></sub>
|
|
319
|
+
</a>
|
|
320
|
+
</td>
|
|
321
|
+
</tr>
|
|
322
|
+
<tr>
|
|
323
|
+
<td align="center">
|
|
324
|
+
<a href="https://github.com/KEIII">
|
|
325
|
+
<img src="https://avatars.githubusercontent.com/u/1167833?v=4" width="100;" alt="KEIII"/>
|
|
326
|
+
<br />
|
|
327
|
+
<sub><b>Ivan Kasenkov</b></sub>
|
|
328
|
+
</a>
|
|
329
|
+
</td>
|
|
330
|
+
<td align="center">
|
|
331
|
+
<a href="https://github.com/HanOterLin">
|
|
332
|
+
<img src="https://avatars.githubusercontent.com/u/21137108?v=4" width="100;" alt="HanOterLin"/>
|
|
333
|
+
<br />
|
|
334
|
+
<sub><b>Tony Lin</b></sub>
|
|
335
|
+
</a>
|
|
336
|
+
</td>
|
|
337
|
+
<td align="center">
|
|
338
|
+
<a href="https://github.com/domoritz">
|
|
339
|
+
<img src="https://avatars.githubusercontent.com/u/589034?v=4" width="100;" alt="domoritz"/>
|
|
340
|
+
<br />
|
|
341
|
+
<sub><b>Dominik Moritz</b></sub>
|
|
342
|
+
</a>
|
|
343
|
+
</td>
|
|
344
|
+
<td align="center">
|
|
345
|
+
<a href="https://github.com/Semigradsky">
|
|
346
|
+
<img src="https://avatars.githubusercontent.com/u/1198848?v=4" width="100;" alt="Semigradsky"/>
|
|
347
|
+
<br />
|
|
348
|
+
<sub><b>Dmitry Semigradsky</b></sub>
|
|
349
|
+
</a>
|
|
350
|
+
</td>
|
|
351
|
+
<td align="center">
|
|
352
|
+
<a href="https://github.com/countcain">
|
|
353
|
+
<img src="https://avatars.githubusercontent.com/u/1751150?v=4" width="100;" alt="countcain"/>
|
|
354
|
+
<br />
|
|
355
|
+
<sub><b>Tao Huang</b></sub>
|
|
356
|
+
</a>
|
|
357
|
+
</td>
|
|
358
|
+
<td align="center">
|
|
359
|
+
<a href="https://github.com/BuBuaBu">
|
|
360
|
+
<img src="https://avatars.githubusercontent.com/u/3825745?v=4" width="100;" alt="BuBuaBu"/>
|
|
361
|
+
<br />
|
|
362
|
+
<sub><b>BuBuaBu</b></sub>
|
|
363
|
+
</a>
|
|
364
|
+
</td>
|
|
365
|
+
</tr>
|
|
366
|
+
<tbody>
|
|
367
|
+
</table>
|
|
368
|
+
<!-- readme: contributors -end -->
|
|
615
369
|
|
|
616
370
|
and to everyone submitting [issues](https://github.com/zaggino/z-schema/issues) on GitHub
|