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: unused shared schema to serializer #1496

Merged
merged 2 commits into from Mar 2, 2019

Conversation

Eomm
Copy link
Member

@Eomm Eomm commented Feb 28, 2019

Closes #1491

This fix needs to be backported to v1.x

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@@ -34,7 +34,7 @@ Schemas.prototype.resolve = function (id) {
return this.store[id]
}

Schemas.prototype.resolveRefs = function (routeSchemas) {
Schemas.prototype.resolveRefs = function (routeSchemas, dontClearId) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a bit of description of dontClearId, and why somebody should set it to true?

Copy link
Member Author

Choose a reason for hiding this comment

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

That boolean needs because it resolve the shared schema when added without removing the $id that is needed by fastify-plugin.
If I remove that condition (only) this specific test fails:

test('a decorator should addSchema to all the encapsulated tree', t => {

because the $id would be removed from the object, than the same object reference would be given to children that throw a FST_ERR_SCH_MISSING_ID error.
I have tried to clone the object, but I get so many fails..

Only schemas.js should set it to true


Context:

When a shared schema is added, a pair of $id + JSON with $id is created

When a JSON schema is resolved by the validation.js during the startup, the JSON with $id is injected in the right place.
During the injection che $id field is deleted because, if a user use two or more time the same shared schema AJV will complain for "multiple equals $id".

If a user add a shared schema with a reference to another shared schema and doesn't use it, the shared shema will not resolved and the code break.

Copy link
Member

Choose a reason for hiding this comment

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

Can you put some of this explanation in the code itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

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, can you do a backport PR?

@mcollina mcollina merged commit 9398dfa into fastify:master Mar 2, 2019
Eomm added a commit to Eomm/fastify that referenced this pull request Mar 2, 2019
* fix: unused shared schema to serializer

* add: details on bool check
@Eomm Eomm mentioned this pull request Mar 2, 2019
4 tasks
mcollina pushed a commit that referenced this pull request Mar 2, 2019
* fix: unused shared schema to serializer

* add: details on bool check
@delvedor delvedor added bugfix Issue or PR that should land as semver patch backport 1.x Issue or pr that should be backported to Fastify v1 labels Mar 6, 2019
@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 Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport 1.x Issue or pr that should be backported to Fastify v1 bugfix Issue or PR that should land as semver patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using named schema in items field breaks schema validation
3 participants