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

Doesn't support $ref fields with just relative file paths #65

Open
doughsay opened this issue Aug 5, 2024 · 2 comments
Open

Doesn't support $ref fields with just relative file paths #65

doughsay opened this issue Aug 5, 2024 · 2 comments

Comments

@doughsay
Copy link

doughsay commented Aug 5, 2024

Hey, I'm pretty new to Open API, so there could be things I'm just misunderstanding, but according to this doc here: https://swagger.io/specification/#reference-object the $ref field looks like it can take on multiple forms.

e.g. it could be a "Reference Object":

"$ref": "#/components/schemas/Pet"

a "Relative Schema Document":

"$ref": "Pet.json"

or a combination of both? a "Relative Documents With Embedded Schema":

"$ref": "definitions.json#/Pet"

this code here though: https://github.com/aj-foster/open-api-generator/blob/main/lib/open_api/reader/state.ex#L172 seems to assume that the ref will always contain a "#", so when I run it on this spec it crashes. This is the spec I'm using, just to play around with this and get a feel for this library: https://github.com/SpaceTradersAPI/api-docs/tree/v2.1.0

It uses refs of the middle form, i.e. relative paths to files without a # in them.

@doughsay
Copy link
Author

doughsay commented Aug 5, 2024

I'm just now realizing that maybe the problem is that this library only supports yaml specs, and this one is json? I've heard "json is just a subset of yaml", but I've also heard to be very dubious of this claim 😅

@aj-foster
Copy link
Owner

Hello there 👋🏼

Thanks for reporting this, and thank you for the example spec. Although it's unusual for individual schemas to be broken out into separate files like this, it's perfectly allowable, and I failed to handle it correctly. I'm working on a fix, however there are a few issues to deal with along the way.

The first fix is simple: I assumed that all refs would have the # character, which is wrong. In the future we'll use a default path of #/, meaning the root of the document, in case one isn't provided.

After that, it looks like the generator doesn't correctly deal with schemas that are located in separate files. I'm still working on the fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants