Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2021-07-27 22:26:34 +00:00
parent 5f6ba88b4b
commit 67954db0cf
9 changed files with 526 additions and 164 deletions

227
node_modules/jsonschema/README.md generated vendored
View file

@ -1,18 +1,22 @@
[![Build Status](https://secure.travis-ci.org/tdegrunt/jsonschema.svg)](http://travis-ci.org/tdegrunt/jsonschema)
# jsonschema
[JSON schema](http://json-schema.org/) validator, which is designed to be fast and simple to use.
The latest IETF published draft is v6, this library is mostly v4 compatible.
## Contributing & bugs
Please fork the repository, make the changes in your fork and include tests. Once you're done making changes, send in a pull request.
### Bug reports
Please include a test which shows why the code fails.
## Usage
### Simple
Simple object validation using JSON schemas.
```javascript
@ -78,6 +82,7 @@ v.addSchema(addressSchema, '/SimpleAddress');
console.log(v.validate(p, schema));
```
### Example for Array schema
```json
var arraySchema = {
"type": "array",
@ -95,21 +100,42 @@ For a comprehensive, annotated example illustrating all possible validation opti
## Features
### Definitions
All schema definitions are supported, $schema is ignored.
### Types
All types are supported
### Handling `undefined`
`undefined` is not a value known to JSON, and by default, the validator treats it as if it is not invalid. i.e., it will return valid.
```javascript
var res = validate(undefined, {type: 'string'});
res.valid // true
```
This behavior may be changed with the "required" option:
```javascript
var res = validate(undefined, {type: 'string'}, {required: true});
res.valid // false
```
### Formats
#### Disabling the format keyword.
You may disable format validation by providing `disableFormat: true` to the validator
options.
#### String Formats
All formats are supported, phone numbers are expected to follow the [E.123](http://en.wikipedia.org/wiki/E.123) standard.
#### Custom Formats
You may add your own custom format functions. Format functions accept the input
being validated and return a boolean value. If the returned value is `true`, then
validation succeeds. If the returned value is `false`, then validation fails.
@ -133,27 +159,86 @@ validator.validate('foo', {type: 'string', format: 'myFormat'}).valid; // false
```
### Results
The first error found will be thrown as an `Error` object if `options.throwError` is `true`. Otherwise all results will be appended to the `result.errors` array which also contains the success flag `result.valid`.
When `oneOf` or `anyOf` validations fail, errors that caused any of the sub-schemas referenced therein to fail are not reported, unless `options.nestedErrors` is truthy. This option may be useful when troubleshooting validation errors in complex schemas.
By default, results will be returned in a `ValidatorResult` object with the following properties:
### Custom properties
Specify your own JSON Schema properties with the validator.attributes property:
* `instance`: any.
* `schema`: Schema.
* `errors`: ValidationError[].
* `valid`: boolean.
Each item in `errors` is a `ValidationError` with the following properties:
* path: array. An array of property keys or array offsets, indicating where inside objects or arrays the instance was found.
* property: string. Describes the property path. Starts with `instance`, and is delimited with a dot (`.`).
* message: string. A human-readable message for debugging use. Provided in English and subject to change.
* schema: object. The schema containing the keyword that failed
* instance: any. The instance that failed
* name: string. The keyword within the schema that failed.
* argument: any. Provides information about the keyword that failed.
The validator can be configured to throw in the event of a validation error:
* If the `throwFirst` option is set, the validator will terminate validation at the first encountered error and throw a `ValidatorResultError` object.
* If the `throwAll` option is set, the validator will throw a `ValidatorResultError` object after the entire instance has been validated.
* If the `throwError` option is set, it will throw at the first encountered validation error (like `throwFirst`), but the `ValidationError` object itself will be thrown. Note that, despite the name, this does not inherit from Error like `ValidatorResultError` does.
The `ValidatorResultError` object has the same properties as `ValidatorResult` and additionally inherits from Error.
#### "nestedErrors" option
When `oneOf` or `anyOf` validations fail, errors that caused any of the sub-schemas referenced therein to fail are normally suppressed, because it is not necessary to fix all of them. And in the case of `oneOf`, it would itself be an error to fix all of the listed errors.
This behavior may be configured with `options.nestedErrors`. If truthy, it will emit all the errors from the subschemas. This option may be useful when troubleshooting validation errors in complex schemas:
```javascript
var schema = {
oneOf: [
{ type: 'string', minLength: 32, maxLength: 32 },
{ type: 'string', maxLength: 16 },
{ type: 'number' },
]
};
var validator = new Validator();
var result = validator.validate('This string is 28 chars long', schema, {nestedErrors: true});
// result.toString() reads out:
// 0: instance does not meet minimum length of 32
// 1: instance does not meet maximum length of 16
// 2: instance is not of a type(s) number
// 3: instance is not exactly one from [subschema 0],[subschema 1],[subschema 2]
```
#### Localizing Error Messages
To provide localized, human-readable errors, use the `name` string as a translation key. Feel free to open an issue for support relating to localizing error messages. For example:
```
var localized = result.errors.map(function(err){
return localeService.translate(err.name);
});
```
### Custom keywords
Specify your own JSON Schema keywords with the validator.attributes property:
```javascript
validator.attributes.contains = function validateContains(instance, schema, options, ctx) {
if(typeof instance!='string') return;
if(typeof schema.contains!='string') throw new jsonschema.SchemaError('"contains" expects a string', schema);
if(typeof instance !== 'string') return;
if(typeof schema.contains !== 'string') throw new jsonschema.SchemaError('"contains" expects a string', schema);
if(instance.indexOf(schema.contains)<0){
return 'does not contain the string ' + JSON.stringify(schema.contains);
}
}
var result = validator.validate("i am an instance", { type:"string", contains: "i am" });
var result = validator.validate("I am an instance", { type:"string", contains: "I am" });
// result.valid === true;
```
The instance passes validation if the function returns nothing. A single validation error is produced
if the fuction returns a string. Any number of errors (maybe none at all) may be returned by passing a
if the function returns a string. Any number of errors (maybe none at all) may be returned by passing a
`ValidatorResult` object, which may be used like so:
```javascript
@ -165,6 +250,7 @@ if the fuction returns a string. Any number of errors (maybe none at all) may be
```
### Dereferencing schemas
Sometimes you may want to download schemas from remote sources, like a database, or over HTTP. When importing a schema,
unknown references are inserted into the `validator.unresolvedRefs` Array. Asynchronously shift elements off this array and import
them:
@ -184,44 +270,119 @@ function importNextSchema(){
importNextSchema();
```
### Default base URI
Schemas should typically have an `id` with an absolute, full URI. However if the schema you are using contains only relative URI references, the `base` option will be used to resolve these.
This following example would throw a `SchemaError` if the `base` option were unset:
```javascript
var result = validate(["Name"], {
id: "/schema.json",
type: "array",
items: { $ref: "http://example.com/schema.json#/definitions/item" },
definitions: {
item: { type: "string" },
},
}, { base: 'http://example.com/' });
```
### Rewrite Hook
The `rewrite` option lets you change the value of an instance after it has successfully been validated. This will mutate the `instance` passed to the validate function. This can be useful for unmarshalling data and parsing it into native instances, such as changing a string to a `Date` instance.
The `rewrite` option accepts a function with the following arguments:
* instance: any
* schema: object
* options: object
* ctx: object
* return value: any new value for the instance
The value may be removed by returning `undefined`.
If you don't want to change the value, call `return instance`.
Here is an example that can convert a property expecting a date into a Date instance:
```javascript
const schema = {
properties: {
date: {id: 'http://example.com/date', type: 'string'},
},
};
const value = {
date: '2020-09-30T23:39:27.060Z',
};
function unmarshall(instance, schema){
if(schema.id === 'http://example.com/date'){
return new Date(instance);
}
return instance;
}
const v = new Validator();
const res = v.validate(value, schema, {rewrite: unmarshall});
assert(res.instance.date instanceof Date);
```
### Pre-Property Validation Hook
If some processing of properties is required prior to validation a function may be passed via the options parameter of the validate function. For example, say you needed to perform type coercion for some properties:
```javascript
const coercionHook = function (instance, property, schema, options, ctx) {
var value = instance[property];
// See examples/coercion.js
function preValidateProperty(object, key, schema, options, ctx) {
var value = object[key];
if (typeof value === 'undefined') return;
// Skip nulls and undefineds
if (value === null || typeof value == 'undefined') {
return;
}
// If the schema declares a type and the property fails type validation.
if (schema.type && this.attributes.type.call(this, instance, schema, options, ctx.makeChild(schema, property))) {
var types = Array.isArray(schema.type) ? schema.type : [schema.type];
var coerced = undefined;
// Go through the declared types until we find something that we can
// coerce the value into.
for (var i = 0; typeof coerced == 'undefined' && i < types.length; i++) {
// If we support coercion to this type
if (lib.coercions[types[i]]) {
// ...attempt it.
coerced = lib.coercions[types[i]](value);
}
// Test if the schema declares a type, but the type keyword fails validation
if (schema.type && validator.attributes.type.call(validator, value, schema, options, ctx.makeChild(schema, key))) {
// If the type is "number" but the instance is not a number, cast it
if(schema.type==='number' && typeof value!=='number'){
object[key] = parseFloat(value);
return;
}
// If we got a successful coercion we modify the property of the instance.
if (typeof coerced != 'undefined') {
instance[property] = coerced;
// If the type is "string" but the instance is not a string, cast it
if(schema.type==='string' && typeof value!=='string'){
object[key] = String(value).toString();
return;
}
}
}.bind(validator)
};
// And now, to actually perform validation with the coercion hook!
v.validate(instance, schema, { preValidateProperty: coercionHook });
v.validate(instance, schema, { preValidateProperty });
```
### Skip validation of certain keywords
Use the "skipAttributes" option to skip validation of certain keywords. Provide an array of keywords to ignore.
For skipping the "format" keyword, see the disableFormat option.
### Fail on unknown keywords
By default, JSON Schema is supposed to ignore unknown schema keywords.
You can change this behavior to require that all keywords used in a schema have a defined behavior, by using setting the "allowUnknownAttributes" option to false.
This example will throw a `SchemaError`:
```javascript
var schema = {
type: "string",
format: "email",
example: "foo",
};
var result = validate("Name", schema, { allowUnknownAttributes: false });
```
## Tests
Uses [JSON Schema Test Suite](https://github.com/json-schema/JSON-Schema-Test-Suite) as well as our own tests.
You'll need to update and init the git submodules: