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

recursive model definitions causes crash #728

Closed
matssk opened this issue May 7, 2015 · 13 comments
Closed

recursive model definitions causes crash #728

matssk opened this issue May 7, 2015 · 13 comments

Comments

@matssk
Copy link

matssk commented May 7, 2015

If you have a model with a self reference, the code generator crashes:

definitions:
  pet:
    required:
      - id
      - name
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string
      tag:
        type: string
      children:
        type: array
        items: 
          $ref: '#/definitions/pet'
@wing328
Copy link
Contributor

wing328 commented May 7, 2015

Are you suggesting it should throw an exception with a proper error message instead ?

@matssk
Copy link
Author

matssk commented May 7, 2015

I'm suggesting it could generate valid code instead. It is not impossible, in my manually implemented client library I have some code like this.

@wing328
Copy link
Contributor

wing328 commented May 7, 2015

For the client library you mentioned, may I know what programming language did you use ? I'm not sure if all programming languages support circular references.

@matssk
Copy link
Author

matssk commented May 8, 2015

C# and Java. Both have no problems with something like this

public class Pet {
   private Pet pet;
}

@wing328
Copy link
Contributor

wing328 commented May 8, 2015

For the models with circular reference, does it work in swagger-ui? Just want to know if other swagger tools already support models with circular reference.

@matssk
Copy link
Author

matssk commented May 8, 2015

Yes, and the swagger-editor added support for it a couple months ago.

@fehguy
Copy link
Contributor

fehguy commented May 13, 2015

I thought this was fixed, but I believe it's simple to do in XmlExampleGenerator.java

fehguy added a commit that referenced this issue May 21, 2015
Fixed #728: Handling of recursive model definitions has been improved.
@webron
Copy link
Contributor

webron commented May 22, 2015

Fixed in develop_2.0.

@JohnGalt1717
Copy link

The better solution is that the UIs and processors need to handle this properly instead of endlessly looping.

@wing328
Copy link
Contributor

wing328 commented Mar 9, 2016

@JohnGalt1717 are you referring to swagger-ui?

@JohnGalt1717
Copy link

Yes, among others. The problem is there code that doesn't cache entries and just link it back up again instead of just following the path blindly. (And their latest code as the same issue)

@wing328
Copy link
Contributor

wing328 commented Mar 9, 2016

Ok. Please open the issue in https://github.com/swagger-api/swagger-ui instead.

@JohnGalt1717
Copy link

Already done. But I was just making a point that this isn't really an issue here, it's a UI and parsing issue on the other side.

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

No branches or pull requests

5 participants