about
openrtb-schema-validator
is a simple thin layer on top of ajv that validates openrtb request and responess, it supports multiple schemas
installation
npm install --save openrtb-schema-validator
by example
validate a request
const parser schemas = const requestValidator = const error data = requestValidator if error consolecosole
validate a response
const parser schemas = const responseValidator = const error data = responseValidator
modify a schema
const parser schemas = const schema = schemasrequest'2.5'schemarootpropertiesfoo = type: 'string' const requestValidator = const error data = requestValidator
API
parser(schema, { emitErrors, removeAdditional, coerceTypes, useDefaults })
- schema - an object of type Schema
- options
- emitErrors - boolean, if set the parser object would emit events of type
error
whenever validation failed - removeAdditional - if there are properties not set in the schema, they would be removed, otherwise validation would failed (from ajv)
- coerceTypes - force types into data, eg: if a property is defined as string but an integer is provided, that property would be coerced into a string (from ajv)
- useDefaults - allow defaults values in the schema (from ajv)
- emitErrors - boolean, if set the parser object would emit events of type
schemas[]
- request['2.5']
- response['2.5']
benchmarks
- validation only: 100000 calls in 172ms
- validation and coerceTypes: 100000 calls in 167ms
- with payload: 179ms
- with payload and coerceTypes: 100000 calls in 179ms
- with payload and removeAdditional: 100000 calls in 177ms
License: MIT