const Ajv = require("ajv/dist/2020.js")
const ajv = new Ajv()
const data = {
"name": "limit",
"in": "query",
"description": "How many items to return at one time (max 100)",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
}
const validator = ajv.compile(
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"in": {
"enum": [
"query",
"header",
"path",
"cookie"
]
},
"description": {
"type": "string"
},
"required": {
"default": false,
"type": "boolean"
},
"deprecated": {
"default": false,
"type": "boolean"
},
"allowEmptyValue": {
"default": false,
"type": "boolean"
},
"schema": {
"$dynamicRef": "#meta"
},
"content": {
"type": "object"
}
},
"required": [
"in"
],
"oneOf": [
{
"required": [
"schema"
]
},
{
"required": [
"content"
]
}
]
}
)
const result = {
result: validator(data)
}
console.log(result, validator.errors)