-
Notifications
You must be signed in to change notification settings - Fork 9.1k
OAS3 Tag/template to define external-components URL #1979
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
Comments
[EDIT: I misunderstood some stuff, see my next comment] @gerardbosch OpenAPI (or really JSON Schema as that is where this feature comes from) would need to come up with a completely different feature for this, because breaking RFC 3986 compatibility would be a huge problem. In JSON Schema proper, this is handled by allowing |
@handrews Do you think this issue could be treated as a "Feature Request" in some way? I think it would be very beneficial to have clean What I pretend is a way of shortening and reusing the URL part to the |
@gerardbosch Actually I'm now realizing that I misread your primary use case of a base URI in the sense of referencing another file/resource. Not referencing a different location in the same file with some sort of relative fragment.
There might be something here around an OpenAPI-specific variable substitution thing, which would ore closely match what you wrote- I'll leave that to someone else to respond to, I'm mostly just here for JSON Schema stuff 😃 |
Coming back to this- the base URI is determined by the Server Object's URLs. You would need to at least have the file name of the external file, plus the fragment, but that is a way that you can dramatically shrink the URLs in your @gerardbosch does that answer your question? If you still have it- sorry for the delay. |
@gerardbosch Many years later... we now have a proposal for OAS 3.2 that allows OAS documents to self-identify, which also sets the base URI. So you could do something like this:
@gerardbosch if you are still interested in this, would this be sufficient for your needs? |
Hi @handrews, it has been a long time and right now I'm not sure as I'm not working in the same project currently. But from your snippet above it's not very clear to me the location where the error is referenced as there's no So in this case, where is And thanks for following up after so much time :) |
@gerardbosch apologies again for the delayed reply, although shorter this time! My late Aug-Oct got rather hectic, and we weren't focusing on 3.2 yet which is where this would be addressed. We are now shifting to that release since 3.0.4 and 3.1.1 are finally out! In this example,
When you see
So the combination of the new
is equivalent to:
Does that help? |
Hi @handrews, thanks for taking time to check this after so long 🙏 Yes, this looks exactly what I was asking back in the day. I think it's a nice thing, although I had no time to investigate about the Anyway, thanks for the update! 🙂 |
@gerardbosch that is correct. I'm hoping we will get 3.2 out in the first half of 2025. Ideally by April, but hopefully at least by June. |
This will be resolved by PR #4556. |
Hi @handrews, that's really nice that you take this in account after so many years 🙂. I have to admit that nowadays I'm not actively working with OpenApi YAML definitions as that was 6 years ago, hehe. But I took a little time to revisit this and your explanation here, and if I understood well, I'm not very sure that the new Back in the day, what I was doing was:
And to have a reusable set of API components, I had some other git repositories that only contained a YAML with some global reusable parts like an error message schema. Those yaml documents were just published to the corporate Artifactory as simple YAMLs (no code generation here), just with the goal to being referenced by the microservice API definition (second bullet above). So in summary, my YAML definitions were published in URLs like this: Service API: Reusable components API: So, if I was using
The idea was to be able to update them all at once in a single place, like a term or variable in the yaml, to be able to assign one (or several named base URLs). Then use those terms in $ref: '${baseUrlApicomponentsErrors}#/components/responses/BadRequest
...
$ref: '${baseUrlApicomponentsErrors}#/components/responses/Unauthorized
...
$ref: '${baseUrlApicomponentsErrors}#/components/responses/InternalServerError where baseUrlApicomponentsErrors: 'http://repos.my-organization.foo/artifactory/libs-release-local/foo/projectcodename/api/contract/apicomponents-errors/1.0/apicomponents-errors-1.0-api.yaml' Thinking nowadays about this, I think that using Git submodules for YAML dependencies would have been a neat way for that use case—would have allowed to deal with YAML dependencies as local files. |
@gerardbosch thanks for replying even though you've moved on from this! I do see your point here. This means you can define a set of URIs independent from the location of the documents across different repos, and design the URIs to shorten the necessary relative references. But it is true that it does not directly provide a templating system for multiple reference targets. I don't see us doing that, as implementors find the referencing system challenging enough as it is. The behavior of The other reason I don't see us doing this is that setting and using variables would be something to do in general, and not to fence off to a single aspect of the spec. Instead, we are likely to think through referencing more comprehensively for OAS 4.0 a.k.a. "Moonwalk." But I definitely understand that designing an alternate set of URIs is not as flexible as setting and using variables. |
Hi there,
I find myself using the power of
$ref
to reference external components in my API definitions, which is great as allows component reuse. But I find myself with this kind of code in my API definitions, where the links to external components are very long and hard to read:I would really like to know if is there any way to define the base-path of that URLs in some kind of variable or YAML tag, so I could lead to
$ref
s of this form:$ref: '{apicomponents-errors}#/components/schemas/Something'
where I could define
apicomponents-errors: http://...
just once.This is not only for better readability, but to allow update the versions all-in-once, as you can see from this example that the referenced components are versioned by its URL.
I have no idea if such kind of feature exists or can be implemented in OAS 3.
P.S. This does not only applies to schemas, but any kind of ref.
The text was updated successfully, but these errors were encountered: