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

Circular references should be allowed as per Swagger 2.0 API Spec. #62

Open
SimplicityGuy opened this issue Apr 27, 2016 · 8 comments
Open

Comments

@SimplicityGuy
Copy link
Contributor

SimplicityGuy commented Apr 27, 2016

Other codegen tools support circular references. See swagger-api/swagger-codegen#728.

I this this issue with the following yml:

  Node:
    description: Generic node.
    type: object
    properties:
      type:
        description: Type or label of the node.
        type: string
      properties:
        description: Node specific dictionary of key/value pairs.
        type: object
        additionalProperties:
          type: string
      relationships:
        descriptions: Relationships this node has with other nodes.
        type: array
        items:
          $ref: '#/definitions/Relationship'
  Relationship:
    description: Relationship that one node has with another.
    type: object
    properties:
      type:
        description: Type of relationship between nodes.
        type: string
      properties:
        description: Relationship specific dictionary of key/value pairs.
        type: object
        additionalProperties:
          type: string
      node:
        $ref: '#/definitions/Node'

Exception:

Traceback (most recent call last):
  File "/usr/local/bin/swagger_py_codegen", line 11, in <module>
    sys.exit(generate())
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/swagger_py_codegen/command.py", line 77, in generate
    swagger = Swagger(data)
  File "/usr/local/lib/python2.7/site-packages/swagger_py_codegen/parser.py", line 29, in __init__
    self._references_sort()
  File "/usr/local/lib/python2.7/site-packages/swagger_py_codegen/parser.py", line 67, in _references_sort
    raise ValueError(msg)
ValueError: $ref circular references found!
@SimplicityGuy
Copy link
Contributor Author

There is a test case test_swagger_ref_count_04 that I believe is erroneous. There is nothing in the Swagger spec that disallows nested definitions or definitions that refer back onto themselves.

@SimplicityGuy
Copy link
Contributor Author

Another reference: swagger-api/swagger-codegen#728

@ubyjvovk
Copy link

I don't think developers are paying any more attention. You can get around this by first using json-refs (install from npm) to first resolve all refs, and then generate from the resulting json

@SimplicityGuy
Copy link
Contributor Author

I believe I have a fix for both this issue and #57. I need to do some more testing on it as it changes a fundamental portion of the parser.

@SimplicityGuy
Copy link
Contributor Author

Well, scratch that. That local fix passed unit tests, but failed when running the tool. I'm going to try to address #57 and #62 with looking at #63.

@ciacicode
Copy link

On my own installation I edited parser.py at least to give some debugging information on the source of the circular reference to fix it. Giving a more meaningful error message helped me overcome this problem. Up for a pull request?

@Fredell
Copy link

Fredell commented Feb 14, 2018

I just wanted to add that the solution presented by Nicklas Møller Jepsen, solved the issues for me. I was working with scaffold entities (EF) with circular references and had the problem with freezing Swagger UI.
I think Nicklas solution is really neat.

@lone1y-51
Copy link

lone1y-51 commented Apr 16, 2018

I got a similar problem

 /employee/findById:
    get:
      tags:
      - "employee"
      summary: "Finds enployee by id"
      operationId: "findById"
      produces:
      - "application/json"
      parameters:
      - name: "id"
        in: "query"
        description: "Employee id"
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
          schema:
            $ref: "#/definitions/Employee"
        400:
          description: "Invalid status value"
definitions:
  Employee:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      petId:
        type: "integer"
        format: "int64"
      quantity:
        type: "integer"
        format: "int32"
      shipDate:
        type: "string"
        format: "date-time"
      status:
        type: "string"
        description: "Order Status"
        enum:
        - "placed"
        - "approved"
        - "delivered"
      complete:
        type: "boolean"
        default: false
    xml:
      name: "Order"

this $ref not avivalid

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

5 participants