Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone stops compiling when updating from 3.4.0 to 3.5.0 #95

Closed
2 tasks done
brodo opened this issue Jan 9, 2023 · 3 comments · Fixed by fastify/fastify#4555
Closed
2 tasks done

Standalone stops compiling when updating from 3.4.0 to 3.5.0 #95

brodo opened this issue Jan 9, 2023 · 3 comments · Fixed by fastify/fastify#4555

Comments

@brodo
Copy link

brodo commented Jan 9, 2023

Prerequisites

  • I have written a descriptive issue title
  • 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
    }
  }
})

Expected Behavior

It should compile.

@Eomm
Copy link
Member

Eomm commented Jan 9, 2023

I'm not a TS user so could you add a Minimal, Reproducible Example with the tsconfig and package.json details?

@brodo brodo changed the title Standalone stops working when updating from 3.4.0 to 3.5.0 Standalone stops compiling when updating from 3.4.0 to 3.5.0 Jan 10, 2023
@brodo
Copy link
Author

brodo commented Jan 10, 2023

Here you go. Thanks for following up so fast.

@Uzlopak
Copy link
Contributor

Uzlopak commented Feb 6, 2023

Well...
I provided a PR for fastify regarding this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants