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

fix: custom validator should not mutate headers schema #4295

Merged
merged 3 commits into from Sep 23, 2022
Merged

Conversation

climba03003
Copy link
Member

@climba03003 climba03003 commented Sep 21, 2022

We should not take any assumption that object is something we want and mutate the headers 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

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

lib/schema-controller.js Outdated Show resolved Hide resolved
lib/schema-controller.js Outdated Show resolved Hide resolved
lib/schema-controller.js Outdated Show resolved Hide resolved
lib/schema-controller.js Outdated Show resolved Hide resolved
lib/route.js Outdated Show resolved Hide resolved
@@ -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)
Copy link
Member

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?

Copy link
Member Author

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.

@Eomm Eomm merged commit 8e985b4 into main Sep 23, 2022
@Eomm Eomm deleted the custom-validator branch September 23, 2022 06:53
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FST_ERR_SCH_VALIDATION_BUILD error when using 'header' validation
4 participants