OpenRTB parser and validator
npm install openrtb-schema-validatoropenrtb-schema-validator is a simple thin layer on top of ajv that validates openrtb request and responess, it supports multiple schemas
bash
npm install --save openrtb-schema-validator
`by example
#### validate a request
`javascript
const { parser, schemas } = require('openrtb-schema-validator')const requestValidator = parser(schemas.request['2.5'], { removeAdditional: true })
const { error, data } = requestValidator.validate({
id: '1',
imp: [{ id: '1' }]
})
if (error) {
console.error(error)
}
cosole.log(data)
`#### validate a response
`javascript
const { parser, schemas } = require('openrtb-schema-validator')const responseValidator = parser(schemas.response['2.5'], { removeAdditional: true })
const { error, data } = responseValidator.validate({
id: '1',
seatbid: {
bid: []
}
})
`#### modify a schema
`javascript
const { parser, schemas } = require('openrtb-schema-validator')const schema = schemas.request['2.5'].clone()
schema.root.properties.foo = { type: 'string' }
const requestValidator = parser(schema, { removeAdditional: true })
const { error, data } = requestValidator.validate({
id: '1',
foo: 'bar',
seatbid: {
bid: []
}
})
`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#### schemas[]
* request['2.5']
* response['2.5']
* 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