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
fix: custom validator should not mutate headers schema #4295
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@@ -327,7 +327,8 @@ function buildRouting (options) { | |||
schemaController.setupValidator(this[kOptions]) | |||
} | |||
try { | |||
compileSchemasForValidation(context, opts.validatorCompiler || schemaController.validatorCompiler) | |||
const isCustom = typeof opts?.validatorCompiler === 'function' || schemaController.customValidatorCompiler | |||
compileSchemasForValidation(context, opts.validatorCompiler || schemaController.validatorCompiler, isCustom) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do the same for compileSchemasForSerialization
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have thought about it before. But serialization didn't mutate the schema and I would leave it for now.
The isCustomSerializerCompiler
is added only because it maybe useful in future.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
We should not take any assumption that
object
is something we want and mutate theheaders
schema.Instead, whenever the
user
pass custom validator. All the responsibility should be given to the user and that library to handle.Fixes fastify/fastify-type-provider-typebox#42
Checklist
npm run test
andnpm run benchmark
and the Code of conduct