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

[Help] How to access the underlying instance of ajv #942

Closed
giovanni-bertoncelli opened this issue Oct 4, 2023 · 3 comments
Closed

[Help] How to access the underlying instance of ajv #942

giovanni-bertoncelli opened this issue Oct 4, 2023 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@giovanni-bertoncelli
Copy link

giovanni-bertoncelli commented Oct 4, 2023

💬 Question here

How to access the underlying instance of ajv in a plugin or a route without having to call setValidatorCompiler()?
For many reason this issue is similar to the one I opened here some years ago: #374, but somehow I keep fighting with this question. I want to access to the underlying fastify ajv instance (supposingly through the fastify.validatorCompiler decorator) but, upgrading fastify from 3.x to 4.x, that decorator is always null. I've tried by waiting the server to be ready but the field is always falsey. Is there any way to access ajv without setting a custom validator?

// example codes if any
app.addHook('onReady', function (done) {
      // logs undefined, undefined
      console.log(this.validatorCompiler, app.validatorCompiler)
      done();
  })

Your Environment

  • node version: 20
  • fastify version: >=4.0.0
  • os: Mac
@giovanni-bertoncelli giovanni-bertoncelli added the help wanted Extra attention is needed label Oct 4, 2023
@Eomm
Copy link
Member

Eomm commented Oct 4, 2023

It is null when you don't have any schema - it creates only if necessary

Thanks to these utilities: https://fastify.dev/docs/latest/Reference/Request/#validateinputdata-schema--httpstatus-httpstatus I wonder if you really need access it

@giovanni-bertoncelli
Copy link
Author

giovanni-bertoncelli commented Oct 4, 2023 via email

@giovanni-bertoncelli
Copy link
Author

@Eomm I've added a pull request for better documenting validatorCompiler usage. Let me know if it can be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants