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
fix: unused shared schema to serializer #1496
Conversation
@@ -34,7 +34,7 @@ Schemas.prototype.resolve = function (id) { | |||
return this.store[id] | |||
} | |||
|
|||
Schemas.prototype.resolveRefs = function (routeSchemas) { | |||
Schemas.prototype.resolveRefs = function (routeSchemas, dontClearId) { |
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.
Can you please add a bit of description of dontClearId
, and why somebody should set it to true
?
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.
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:
fastify/test/decorator.test.js
Line 635 in cf7a096
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.
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.
Can you put some of this explanation in the code itself?
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.
Done
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, can you do a backport PR?
* fix: unused shared schema to serializer * add: details on bool check
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. |
Closes #1491
This fix needs to be backported to v1.x
Checklist
npm run test
andnpm run benchmark