import Ajv, { JSONSchemaType } from 'ajv' import { EndPointBody } from '../types' const schema: JSONSchemaType = { type: 'object', properties: { correlationId: { type: 'string' }, env: { type: 'string' }, }, required: ['correlationId', 'env'], additionalProperties: true, } const validateBody = (body) => { const ajv: Ajv = new Ajv() const validate = ajv.compile(schema) const valid = validate(body) if (!valid && validate.errors && validate.errors.length != null) { throw new Error( validate.errors .map((err) => `${err.instancePath} ${err.message}`) .join(' '), ) } } export default validateBody