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: setSchemaController not inheriting Schemas from root parent #3401

Merged
merged 11 commits into from Nov 6, 2021

Conversation

metcoder95
Copy link
Member

@metcoder95 metcoder95 commented Oct 28, 2021

As stated in #3121, during the development of the plugin I noticed that when setting up a custom SchemaController on the second level of encapsulation (root -> instance), the custom Validator is not correctly inheriting the schemas defined on the root layer of encapsulation. Causing the following error:

Failed building the validation schema for POST: /, due to error can't resolve reference some# from id #

Full Reproduction in the test case added.

Checklist

@mcollina mcollina requested review from Eomm and zekth October 28, 2021 15:53
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

fastify.js Outdated Show resolved Hide resolved
test/schema-feature.test.js Outdated Show resolved Hide resolved
test/schema-feature.test.js Show resolved Hide resolved
test/schema-feature.test.js Outdated Show resolved Hide resolved
test/schema-feature.test.js Outdated Show resolved Hide resolved
test/schema-feature.test.js Outdated Show resolved Hide resolved
metcoder95 and others added 4 commits October 28, 2021 22:16
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
@metcoder95
Copy link
Member Author

Hi @Eomm, I adjusted the tests as you suggested in the following commit 4dd513b

Thanks to that, I notice that thanks to the change, the buildSerializer was missed in the chain, as when overwriting the SchemaController, neither the constructor nor the buildSchemaController static function was taking into consideration the compilersFactory at all, trying to always reach them at the instance level.

I added the function getCompilersFactory to the instance of the controller, in order to do a recursive search over the chain of controller till reaches the most recent buildSerializer implementation.

Please let me know what you think about this approach, not so sure if is the right approach as it might be better to even decouple it a little and have one function for the buildSerializer, and another one for the buildValidator.

Note:

  • The coverage decreased because the change, I'll work on set it back to 100% during the weekend 👍

@metcoder95 metcoder95 requested a review from Eomm October 28, 2021 21:30
@metcoder95
Copy link
Member Author

Done, please feel free to have a look when you have time 🙂

Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

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

Minor remark. Overall LGTM.

Good catch on this.

test/schema-feature.test.js Outdated Show resolved Hide resolved
test/schema-feature.test.js Outdated Show resolved Hide resolved
Co-authored-by: Vincent LE GOFF <vince.legoff@gmail.com>
Copy link

@FAVE01 FAVE01 left a comment

Choose a reason for hiding this comment

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

nice

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

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

GREAT test cases 👏🏽

Almost done!

lib/schema-controller.js Show resolved Hide resolved
test/schema-feature.test.js Outdated Show resolved Hide resolved
test/schema-feature.test.js Outdated Show resolved Hide resolved
metcoder95 and others added 3 commits November 4, 2021 22:46
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
@metcoder95 metcoder95 requested review from Eomm and zekth November 4, 2021 21:56
@Eomm Eomm added the bugfix Issue or PR that should land as semver patch label Nov 6, 2021
@Eomm Eomm merged commit 53fe09f into fastify:main Nov 6, 2021
@github-actions
Copy link

github-actions bot commented Nov 7, 2022

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 Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix Issue or PR that should land as semver patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants