rksh1997
rksh1997

Reputation: 1203

fastify.setValidatorCompiler is not a function

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.

Upvotes: 1

Views: 1308

Answers (2)

Gonzalo A.
Gonzalo A.

Reputation: 21

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

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

Upvotes: 0

rksh1997
rksh1997

Reputation: 1203

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.

Upvotes: 2

Related Questions