influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.6k stars 3.54k forks source link

Swagger.yml: TypeError: Converting circular structure to JSON #16519

Open russorat opened 4 years ago

russorat commented 4 years ago

Ran our swagger through this and saw the following error message:

https://apitools.dev/swagger-parser/online/?url=https%3A%2F%2Fraw.githubusercontent.com%2Finfluxdata%2Finfluxdb%2Fmaster%2Fhttp%2Fswagger.yml

This API is valid, but it cannot be shown because it contains circular references

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'properties' -> object with constructor 'Object'
    |     property 'checks' -> object with constructor 'Object'
    --- property 'items' closes the circle
    at JSON.stringify (<anonymous>)
    at toText (https://apitools.dev/swagger-parser/online/js/bundle.min.js:17:291033)
    at Function.editors.addResult (https://apitools.dev/swagger-parser/online/js/bundle.min.js:17:292169)
    at Function.editors.showResult (https://apitools.dev/swagger-parser/online/js/bundle.min.js:17:291450)
    at https://apitools.dev/swagger-parser/online/js/bundle.min.js:17:295981
    at Array.forEach (<anonymous>)
    at https://apitools.dev/swagger-parser/online/js/bundle.min.js:17:295961
imogenkinsman commented 4 years ago

The user impact isn't significant - we probably shouldn't have any circular references, but it's allowed by the spec and looks like this is an issue that has existed for over a year in our swagger.

So, it's worth looking into and fixing this, but not top priority.

There are multiple places where we have circular references. For example, the Field object is recursive:

    Field:
      type: object
      properties:
        value:
          description: >-
            value is the value of the field.  Meaning of the value is implied by
            the `type` key
          type: string
        type:
          description: >-
            `type` describes the field type. `func` is a function. `field` is a field reference.
          type: string
          enum:
            - func
            - field
            - integer
            - number
            - regex
            - wildcard
        alias:
          description: >-
            Alias overrides the field name in the returned response.  Applies only
            if type is `func`
          type: string
        args:
          description: Args are the arguments to the function
          type: array
          items:
            $ref: '#/components/schemas/Field'

The one raised by that tool looks like it may be from HealthCheck:

    HealthCheck:
      type: object
      required:
        - name
        - status
      properties:
        name:
          type: string
        message:
          type: string
        checks:
          type: array
          items:
            $ref: "#/components/schemas/HealthCheck"
        status:
          type: string
          enum:
            - pass
            - fail
ealdwairi commented 3 years ago

have you found a solution?