我希望能够验证架构中的所有属性,但我收到一个错误,其中仅包含一个缺失的属性,而不是所有属性。我有以下架构:
const headersSchema = S.object()
.prop('platform', S.string()).required()
.prop('device-data', S.string()).required()
.prop('device-id', S.string()).required()
.prop('consumer-id', S.string()).required()
.prop('version', S.string()).required()
这是我遇到的错误:
[
{
"instancePath": "",
"schemaPath": "#/required",
"keyword": "required",
"params": {
"missingProperty": "device-data"
},
"message": "must have required property 'device-data'"
}
]
但我不会在标题上发送两个属性:
device-data
和device-id
。我想收到一个错误,表明缺少这 2 个属性,但我没有提交。
这是我的路线:
server.post(
'/headers',
{
schema: {
headers: headersSchema
}
},
() => {}
)
这是一个ajv设置,您必须配置它,因为它可能会导致DOS攻击:
const fastify = require('fastify')({
ajv: {
customOptions: {
allErrors: true
}
}
})
关于DOS攻击:
来源: