Create ApiValidator instance.
Initializes ApiValidator and reads validation JSON Schemas.
Each JSON schema needs to have an id of this format: #${service}-${method}
.
JSON schemas needs to be located on the file system in the following topology:
└─ <${validationSchemasDir}>
└─ service-1
│ ├─ schema-1.json
│ └─ schema-2.json
├─ service-2
│ ├─ schema-1.json
│ ├─ schema-2.json
│ └─ schema-n.json
└─ service-n
└─ schema-1.json
Directory where validation schemas are located.
Defaults to ${process.env['XDG_CONFIG_HOME'] ||
${process.env['HOME']}/.config}/${process.env['APP_NAME']}/validation
.
Directories from the validationSchemasDir
which needs to be excluded, i.e. their schemas should not be loaded.
Joins errors from the exception thrown by ApiValidator.validate method.
Errors can be joined into text or object.
When text is specified, errors will be joined into message using ajv-i18n.
When json is specified, errors will be joined into an object,
having as key instancePath error property and as value message error property.
(https://ajv.js.org/api.html#error-objects) from the exception thrown by ApiValidator.validate method.
Format into which errors need to be joined.
When format is json, you can skip some error objects having keyword property present in this list.
Joined errors.
Sanitizes data against XSS vulnerability.
Notice that in case of JSON data, only values will be sanitized, while keys will be left untouched.
Data to be sanitized.
When data is an object, you can specify a set of dot paths, values of which should not be sanitized.
Sanitized data.
Validate data against JSON schema.
Id of the schema is formed from #${service}-${method}
.
Name of the service.
Name of the method.
Data to be validated.
Validated data.
Class which allows to validate data that is coming to API endpoints.
Internally it uses ajv in order to validate JSON objects.
XSS sanitization is performed with the xss npm package.