-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Clarify if JSON References are restricted to properties that explicitly allow them #1037
Comments
We have attempted to be explicit about where $ref can be used. Also, now that reusable stuff is contained in the |
OK, so is it fair to say that:
Is that right? |
That is how I understand it, other than one really weird exception that I just realized when reading your fourth point. I have envisioned that $ref should only be used to reference things in the components collection. With the exception of an external reference that can reference in any arbitrary fragment of a JSON/YAML file. However, I just realized that there is nothing stopping an external reference pointing back to the current OpenAPI spec, at which point you can point to any part of the document. Therefore, your last statement is correct, but not what I was hoping. The idea of $refs being able to point to other operational parts of the spec, that might also reference other parts of the spec is a complexity that I had hope to avoid. The only way to enforce what I was thinking is to require external docs to be valid OAS docs and only allow references into component sections. However, I know this would never fly with the TDC as there is already a feeling that our current use of $refs is too limiting. |
@darrelmiller - what @tedepstein summarized is pretty much the spirit of what we intended in 2.0, and have hopefully managed to capture in the changes to 3.0. As for the fourth point, I believe that's right and intentional. We've had people $ref extensions before, or even, unfortunately, schemas from other inline definitions. I would never recommend doing either, but - a. any resolver shouldn't have an issue with it, and b. trying to restrict it in the spec would make it more cumbersome to read/write, and can be painful for tooling. |
@webron , thanks for clarifying. Though it's possible to infer all of these things from the spec as it's written, I might still suggest stating them explicitly. I'm not sure exactly where these clarifications should be stated; probably in the Reference Object documentation. When I get a moment, I'll open a PR with suggested clarifications, and you (collectively, the TDC) can decide if they improve the spec. |
Given that we're very explicit about where Reference Objects are allowed (and we've done the best we can about the Path Item |
This issue has been labeled with |
$ref properties and Reference Objects were a big point of confusion in 2.0, because some people assumed they were allowed anywhere within an OpenAPI spec. There are multiple Swagger-OpenAPI 2.0 tutorials that show disallowed use of $ref properties. Comments from @webron and others that eventually made it clear to me that JSON References are only allowed in specific contexts, where it's explicitly shown in the language spec.
I remember hearing that OpenAPI 3.0 was going to allow $refs anywhere. (Or at least, wherever an object of any kind is expected.) But I don't see any evidence of that change in the current 3.0 draft spec.
Can we assume that JSON References in OpenAPI 3.0 are still only allowed in the specific contexts described in the 3.0 spec? If so, that's fine, but I would suggest adding that restriction to the spec, so it's easy to find and understand. And if not, that change should also be called out explicitly.
The text was updated successfully, but these errors were encountered: