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
Broken ref when using different file for request & response #326
Comments
@AndrewIsh this is a bit cryptic to read. OpenAPI See the 'Escape Characters' section here
For example, to refer to the path so ultimately,
It appears to have the correct location, but it's not resolving the schema. this gets sent to AJV which isn't capable of resolving multi file yamls. there needs to be some additional logic to dereference that properly for this case. Note that we already do this using $refParser.mode It's blowing up AJV when compiling the response schema here Using the debugger, I inspected the state of the parsed and bundled apiDoc. Basically, your API spec files consolidated to a single JSON (here)[https://github.com/cdimascio/express-openapi-validator/blob/master/src/framework/index.ts#L26] I notice that So what might we do... A good first excercise may be to use json-schema-ref-parser to dereference you API spec properly. If you can get that to do the right thing, I will expose those options (assuming we need them) via this validator. Currently, json-schema-ref-parser options are offered. For example, we support Apologies, for not having a solution immediately, but hopefully, we'll be able to come to one after some investigation. |
Hmm.. I see these $ref resolved
This may be an issue in the json-schema-ref-praser itself |
@AndrewIsh ignore my note above. i'm a bit off with the diagnosis. |
please give |
Hi @cdimascio Thanks so much for responding to this so quickly. Your fix in Thanks for creating such a useful library, it's made life much easier for me on my project :-) |
Hi @cdimascio Sorry to re-open this one. But I think I've just hit the thing you thought I might hit. When you created the fix for my previous problem, you said:
I have an endpoint with both a
Prior to me adding the spec & component for the
The error is weird because it's saying it can't resolve the I've looked at what you did to fix the previous issue, with a view to trying a similar fix for requests, but have not been able to determine where such a fix would be made. Do you think this could be the problem you suggested? |
yes. working on a fix |
#326 improve paths, andcomponents $ref resolution for multi-file specs
PR #334 should resolve this. |
Hi @cdimascio Thanks for the super speedy response. I just tried it and it works perfectly! Many thanks for fixing it, and for your continued work on this extremely useful package! :-) |
This update fixes the bug I reported in: cdimascio/express-openapi-validator#326 (comment)
Describe the bug
I have spent many hours trying to get to the bottom of this with no luck, so I'm hoping I've found a bug and it's not just my ineptness! :-)
I have a very minimal schema representing
get
&post
methods on a/queries
endpoint (see schema below). I'm getting some super weird errors when trying to use them. The problem appears to be related to thepost
portion of the schema, which has references to two different files, one for the request object and one for the response object (although for debugging purposes, the contents of both files is currently identical)When I make a GET request, I receive:
I am confident the referenced file
schemas/queryresponse.yaml
is present:In fact, the
queries.yaml
schema for theget
route references this file with no problems.Bizarrely, in the spec, if I rename the the ref for the response object to
schemas/queryrequest.yaml
, it works, which is especially odd since both files are currently identical.I'm surmising from all this that it's something to do with having two differently named files for request & response refs, though in the OpenAPI 3 spec I've not been able to find anything that would prohibit that.
I'm completely out of ideas. My spec seems valid (according to https://editor.swagger.io/ anyway). Might this be a bug?
Examples and context
ems.yaml
:schemas/queries.yaml
:schemas/queryrequest.yaml
&schemas/queryresponse.yaml
:The text was updated successfully, but these errors were encountered: