2.0.0 • Published 3 years ago

jsvrx-ajv v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

jsvrx-ajv

RxJS operators to validate/discriminate data objects using JSON Schema(s) and Ajv: Another JSON Schema Validator.

npm ajv npm bundle size Top Language MIT License

Install

npm i jsvrx-ajv

Usage

AjvDataValidtor is DataValidator interface implementation using Ajv.

For more information about DataValidation interface and usage examples see jsvrx.

Create a new AjvDataValidator instance using ajv.Options or pass an ajv instace as the constructor's parameter.

import { AjvDataValidator } from 'jsvrx-ajv';
const dv = new AjvDataValidator({ coerceTypes: true })

import ajv from 'ajv';
const dv = new AjvDataValidator(new ajv())

AjvDataValidator.discriminate(ids: JSONSchemaID[], unk?: JSONSchemaID) implementation doesn't provide optimized validation for multiple JSON Schemas. It executes single JSON Schema validation attempts in ids array order. Fill the ids array accordingly.

ValidationError.e holds ajv.ValidateFunction.errors for the validate error and array of ajv.ValidateFunction.errors for the discriminate error.