-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
PR-2044 (one schema for multiple routes) introduce breaking change behavior on routes schema resolve. #2104
Comments
@SkeLLLa what would be your recommendation? Thanks. |
@mcollina that's depends actually on that PR and if it could be done in different way. During that And after that there's no easy way of getting resolved schemes. So as it was done in initial fastify-swagger PR you should use According to this snippet #2024 (comment) I'd rather recommend just to clone schema object (shallow or deep - doesn't matter). Because in most cases there will be no need for having the same schemes for two different routes. So I think it's easier to add documentation about using same scheme object in different routes and advice to use named schemes in this situation, rather applying fixes to several modules. Or probably we can add some method to get all routes with resolved schemes, but I don't know if it's really good idea, cause it will need to walk through all fastify child scopes tree. This will help to solve fastify-swagger and fastify-oas issues without lot's of changes, but I'm not sure about how other people may used that functionality. TLDR:
PS. May be @snacqs have some ideas about how to improve that workaround? |
I'm actually for option 3, cause Original issue was about sharing single schema between two routes. And fastify already has documentation related to shared schemes https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md#adding-a-shared-schema. Btw shared schemes were mentioned in original issue #2024 (comment). |
I took master and reverted the commit and the issue is still there. Moreover, the Lines 193 to 194 in 9b53f9a
So I think the issue is something else Here the test I tried:
|
Yes, it does. But afterwards (when app calls
I definitely sure that this regression was introduced in 2.12, but I'll doublecheck now if it's was done in that PR. |
I'm not arguing with that, I think we should triage more this issue 👍 If you have also a little test of your module to share, that was ok with 2.11 and fails with 2.12 it would be helpful (I was unable to find it here ) |
@Eomm I don't have those tests yet. But probably the same issue fastify/fastify-swagger#226 could help you. Basically to reproduce the issue:
I think you could modify test's you've wrote by adding array for storing routes, |
That's what I think about what's happening here. When you add a route After that when And there traverse metod is called https://github.com/fastify/fastify/blob/master/lib/schemas.js#L69 and it replaced strings with resolved objects in https://github.com/fastify/fastify/blob/master/lib/schemas.js#L107 Before that PR that traverse was called on the same object, that was in onRoute hook. But now it's called on As it's a shallow copy keys like query, querystring, body, etc. that contain strings are cloned and they will not be updated by reference as it was before. |
@SkeLLLa would you like to send a PR? I'm a bit lost on what is the proposed fix for this. |
Now I understand, the test I posted above #2104 (comment) is wrong because the check should be done after the ready, not in the hook. I would like to give it another check to understand if we can solve both the issues (this and the #2044) |
💥 Regression Report
PR #2044 breaks https://github.com/SkeLLLa/fastify-oas and probably related to fastify/fastify-swagger#224
Consider you have fastify onRoute hook and save the routes like
Earlier after
.ready()
method is finished his job, e.g.await app.ready()
, inschema
in route object was resolved to actual schema objects.E.g. if you referenced schemas by id
after app is
ready
you could expect an object inroute.schema.querystring
.However now it's not resolved and still is a string.
Last working version
Worked up to version: 2.11.0
Stopped working in version: 2.12.0
To Reproduce
Steps to reproduce the behaviour:
fastify.addSchema
Paste your code here:
Expected behavior
It expects that
route.schema.[body,querystring,params,headers]
will be an resolved object after app is ready. However after that PR it is a string (when schema ids are used)Your Environment
The text was updated successfully, but these errors were encountered: