[X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.11.0
Plugin version
3.5.0
Node.js version
v18.4.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.0.1 (22A400)
Description
The schemaController.compilersFactory.buildValidator property that can be passed to the Fastify-function is not of the same type as the return value of StandaloneValidator anymore.
Here is the error:
error TS2769: No overload matches this call.
The last overload gave the following error.
Type '{ (externalSchemas: { [key: string]: AnySchema | AnySchema[]; }, options?: { mode: "JTD"; customOptions?: JTDOptions | undefined; } | undefined): AjvCompile; (externalSchemas: { ...; }, options?: { ...; } | undefined): AjvCompile; }' is not assignable to type 'ValidatorCompiler | undefined'.
Type '{ (externalSchemas: { [key: string]: AnySchema | AnySchema[]; }, options?: { mode: "JTD"; customOptions?: JTDOptions | undefined; } | undefined): AjvCompile; (externalSchemas: { ...; }, options?: { ...; } | undefined): AjvCompile; }' is not assignable to type 'AjvCompile'.
Types of parameters 'externalSchemas' and 'schema' are incompatible.
Type 'AnySchema' is not assignable to type '{ [key: string]: AnySchema | AnySchema[]; }'.
Type 'boolean' is not assignable to type '{ [key: string]: AnySchema | AnySchema[]; }'.
56 buildValidator: factory,
Steps to Reproduce
Check out this code snippet from the readme:
const { StandaloneValidator } = require('@fastify/ajv-compiler')
const factory = StandaloneValidator({
readMode: false,
storeFunction (routeOpts, schemaValidationCode) {
// routeOpts is like: { schema, method, url, httpPart }
// schemaValidationCode is a string source code that is the compiled schema function
const fileName = generateFileName(routeOpts)
fs.writeFileSync(path.join(__dirname, fileName), schemaValidationCode)
}
})
const app = fastify({
jsonShorthand: false,
schemaController: {
compilersFactory: {
buildValidator: factory // this does not compile anymore
}
}
})
Prerequisites
Fastify version
4.11.0
Plugin version
3.5.0
Node.js version
v18.4.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.0.1 (22A400)
Description
The
schemaController.compilersFactory.buildValidator
property that can be passed to theFastify
-function is not of the same type as the return value ofStandaloneValidator
anymore.Here is the error:
Steps to Reproduce
Check out this code snippet from the readme:
Expected Behavior
It should compile.