在Fastify中使用"fluent json模式"处理验证错误



我使用fluent-json-schema来验证请求。具有以下模式:

const gwoogl = S.object()
.prop('title_desc', S.string()/*.allow('')*/.minLength(3).maxLength(100))
.prop('exact', S.boolean().default(false))
.prop('div_q', S.string()/*.allow('')*/.minLength(3).maxLength(40))
.prop('since', S.string().format(S.FORMATS.DATE_TIME))
.prop('section', S.string().enum(['donations', 'skills']))
const gwooglSchema = {
body: gwoogl,
}

显示它在哪里消费如下(所以我认为格式是正确的(:

{"level":50,"time":1643319721118,"pid":9712,"hostname":"WIN-E91D14FS6F4","body":{"isFluentSchema":true,"isFluentJSONSchema":true}}

问题是我看不出我是如何处理错误的,而且似乎根本没有考虑到模式,例如POST { title_desc: 'a' },它必须不验证。

fastify.post('/gwoogl', { gwooglSchema }, async (req, reply) => {});

我的坏我应该通过:{ schema: gwooglSchema }

最新更新