-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Allow nested $ref to resolve for OpenAPI? #462
Comments
Go submit! Remember to add a test! |
Could you share some code with a failing example as first step? |
Hmm, this may be a larger #ref issue...
Because I assume the id in the ref will be the same as the property name on see cjsewell/fastify-swagger-nested-refs for an example of it failing. and the branch with-fix with an example using a forked version of fastify-swagger |
I agree on that: we should find when remove the $id because we can't mutate the user's input object. We do a lot of schema navigation, so I think we could find an existing loop instead of creating a new one
This assumption is not true by the spec. You are not using $ref as the specification would like to (read here for more details) The $ref resolution should be already done here: fastify-swagger/lib/spec/swagger/utils.js Line 167 in 8d5a3e0
so I think the |
Yes, I see. It seems that if the schema is directly in the route ( via querystring, body, params etc ) then it is parsed correctly through resolveCommonParams in lib/spec/openapi/utils.js#290. But schemas added via fastify.addSchema() or the config openapi.componets.schemas don't parsed in the same way? |
Perhaps the could be a cleaner solution? |
Hi, I have exactly the same trouble. |
failing test fix ref id
implementation
rewrite test using await/async to be more readable
hey, I'm having the same trouble but for the swagger-api. I've found a workaround, but it's not great. I name all the $ref $Id's to include the definition path (e.g.
This feels a bit manual, and problematic to be a good solution, but it might help people out of a bind. The solution above cjsewell@1a816ee produced duplicated definitions which were nested oddly for me. The original solution worked, once modified to take into account
|
I've added a PR with tests, some of which are failing at the moment. i.e. if we do not transofrm the ID's using |
* #462 Allow nested to resolve for OpenAPI : failing test * #462 Allow nested to resolve for OpenAPI failing test fix ref id * add prepareOpenapiSchemas to resolve refs * #462 Allow nested $ref to resolve for OpenAPI implementation * #462 Provide more complex test rewrite test using await/async to be more readable Co-authored-by: Corey Sewell <corey.sewell@jucyworld.com>
Prerequisites
Issue
Currently, nested $refs are not resolved, $ref remains as the schema id.
If the id exists in components.schemas its should be rewritten to
#/components/schemas/{id of the schema}
This can achieve this by adding modifying the loop at /lib/spec/openapi/index.js#L31
E.g search through each prop, and if a $ref is found with the same value as an existing schema, prefix it with
#/components/schemas/
I would like to submit this as a pull request, but I'm not too familiar with swagger, JSON schema etc so would like some feedback before I do... Or should I just submit it a go from there?
The text was updated successfully, but these errors were encountered: