-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Circular references in Definitions Object #822
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
Putting tooling aside, what you describe is not something that can actually be represented as a JSON and returned by the API. The circular dependencies is not the issue, it's the fact you made it infinite by requiring the properties to always exist. Say you want to have an |
You're pretty much repeating what I said. As far as I can tell, the Open-API spec allows these infinite loops, even though it's impossible in practice (as you reiterated). Shouldn't the spec explicitely forbid such situations or atleast address them in a way that allows implementors to deal with them? A standard specification document must be unambigious, on this particular issue, it is not. |
It wasn't clear from your original question what it is that you actually seek. It's not the job of the spec to deal with such a case. It's JSON Schema that allows it, and not the OpenAPI spec itself. You can do a lot of crazy things or things that won't make sense using JSON Schema, and we allow users to use it for modeling for its common general use, but we cannot safe-guard every case. |
Okay, too bad the spec will leave in this ambiguity. I'll just add checks to my own tools to prevent users accidentally specifying impossibilities. |
I can imagine people wanting to have such circular dependencies – you'll just have some of the properties being non-required. The actually transmitted object then will have its depth truncated after some level (e.g. by omitting further references from all entities which were already included before). |
Hi , Is there any resolution here so far (Open API 2.0, 3.0) ? or this is how the spec is meant to render the references with circular pattern? Thanks. |
Just read through this, and I think a few points are worth adding, or reiterating:
|
Thanks for adding your thoughts here. But the Open API spec 2.0 renders null in place of reference in the example and just [] for a model. |
@SaravanZ You keep using phrases like "OpenAPI spec 2.0 renders". The OpenAPI specification doesn't render anything. Do you actually mean the Swagger tooling "renders"? |
@darrelmiller for info , I'm not trying to generate any code from the spec etc., all I'm trying to achieve is to describe the model of my API using Open API 2.0 (swagger 2.0). So I think I'm using incorrect terms - so swagger tooling it is (if that is what processes the YAML and renders as specification). |
@SaravanZ Swagger-UI is one tool that takes an OpenAPI description and renders HTML documentation of the API. If that's what you are using then I would recommend raising an issue there. |
Thanks @darrelmiller. I believe swagger editor that I'm using locally uses the same tooling , so I can raise it there. |
It is sad that circular reference could result in Java heap space error. |
Here's some info for people running into this issue. I ran into this issue as we are currently auto-generating a spec from Java code with circular definitions due to this type of structure. The use case is specified above: @tedepstein wrote:
API Reference API Reference tools have varying levels of support:
OpenAPI Generator I use the OpenAPI Generator to auto-generate Go client SDKs. Out of the box, I couldn't create a working Go client SDK, but Go supports circular references so I did some post processing and it now works. Read more here. |
I'm still not sure what to do about this. I can't mock my schema because of one circular dependency, even though its child is not required. How do I get around it? |
@delanym you need to ask that question in the repository for the tooling that you are using. This repository is for the specification itself, and this is not a problem with the specification. To reiterate using points @tedepstein wrote in an earlier comment:
Yes, this is why we (JSON Schema project) do not forbid this in the spec. This sort of things is appropriate for a linter. Just like a programming language compiler does not catch every problem, so you use a linter. The linter will often catch things that may or may not be a problem, and it can check for things that are too expensive to check in the compiler (or in the case of JSON Schema, the validator, code generator, etc.)
Yes to this as well. To understand why the general case of detecting this is hard, consider a combination of We're trying to encourage a larger ecosystem of linters :-) |
Hey everyone (and @grokify)! I'm a ReadMe dev that recently worked on this issue. We do support circular reference specs now. For an immediate example, see check out this link. Here's another example (click on circular reference in the dropdown). The nitty-gritty details on rendering an OpenAPI spec is that when we do detect a circular reference within a spec, we attempt to render. When it is a |
Syntactically, it seems possible to construct an infinite circular reference using Definitions Objects.
Obviously, such a reference could never actually be called or returned. I can't find any conclusive answer on this in the specs. The editor at http://editor.swagger.io/ seems to accept it as valid syntax, but produces an
undefined
Schema.How should such a situation be treated?
Example
The text was updated successfully, but these errors were encountered: