[英]Fastify plugin fastify-autoload error plugin must be a function
[英]fastify.setValidatorCompiler is not a function
我已经安装了 fastify 2.14
。 我正在按照文档使用自定义验证库。
这是我的代码:
import fastify from 'fastify';
const app = fastify({});
app.setValidatorCompiler(({schema}) => data => schema.validate(data)); // setValidatorCompiler is not a function
console.log(app.setValidatorCompiler) // undefined
export default app;
我还尝试在路由选项中传递它,但 typescript 不将其识别为字段。
还setSerializerCompiler
不是 function。
他们似乎有错误的文档版本控制。
我正在阅读2.14
版文档,它是针对3-alpha
。
安装3-alpha
版本解决了我的问题。
fastify.setValidatorCompiler(({ schema, method, url, httpPart }) => {
return ajv.compile(schema)
})
https://www.fastify.io/docs/v3.3.x/Validation-and-Serialization/#validator-compiler
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.