-
-
Notifications
You must be signed in to change notification settings - Fork 8
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] fastify.validatorCompiler is null #374
Comments
Without an example to look at, all I can suggest is to explore the new https://www.fastify.io/docs/latest/Server/#schemacontroller option. |
Mmm I can try to write a snippet: // myplugin.js
function plugin(fastify, opts, done) {
fastify.decorate('customValidator', (objectToValidate, schema) => {
const { validatorCompiler } = fastify;
// there is no way to know if fastify.validatorCompiler is not null....
const validator = validatorCompiler({
schema
});
return validator(objectToValidate);
})
} |
Your plugin would need to be registered after |
The compilers are ready, after the ready event. Here there are the tests that cover this behaviour: This is needed because the ajv instance is built async and when needed and it is not created by default |
Thank you @Eomm. I figured that out. |
💬 Question here
Is there a way to know exactly when
fastify.validatorCompiler
is not null and is ready? Since it seems not to be added through the decorate API and I have to use it internally for validation in a not-covered scenario sometimes I get the ajv instance, sometimesnull
... If there is no way how can I rely on the internal AJV instance of Fastify?The text was updated successfully, but these errors were encountered: