1

I have fastify 2.14 installed. I am following the documentation to use custom validation library.

Here's my code:

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;

I also tried passing it in the route options and typescript doesn't recognize it as a field.

also setSerializerCompiler is not a function.

2 Answers 2

2

It seems like they have wrong documentation versioning.

I was reading version 2.14 documentation and it was for 3-alpha.

Installing the 3-alpha version solved my problem.

0
fastify.setValidatorCompiler(({ schema, method, url, httpPart }) => {
  return ajv.compile(schema)
})

https://www.fastify.io/docs/v3.3.x/Validation-and-Serialization/#validator-compiler

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.