philosowaffle / vs-openapi-designer

OpenApi Designer Extension for VS Code
https://marketplace.visualstudio.com/items?itemName=philosowaffle.openapi-designer
GNU General Public License v3.0
15 stars 2 forks source link

Unstable after circular reference #27

Open avelinob opened 5 years ago

avelinob commented 5 years ago

Unstable (i.e. wont pick up new files or preview new files) after a YAML OAS 3 with external references, where in one of those external references, has a anyOf: array with two options: string or a reference back to self. Uninstalling and re-installing does not help.

Example:

openapi.yaml

---
openapi: 3.0.0
# etc
components:
  schemas:
    StuffDefinition:
      $ref: 'stuff.yaml#/schemas/Stuff

stuff.yaml

schemas:
  Stuff:
    type: object
    properties:
       mistake:
           type: array
           items:
              anyOf:
             - type: string
               description: supposed to be a  composite  reference of to an existing object
             - $ref: '#/schemas/Stuff'
               description: supposed to be an inline subordinate object
Adeynack commented 5 years ago

I think my problem is the same as @avelinob 's, so I will describe it here instead of creating a new issue.

Here is my schema definition.

    Foo:
      type: object
      properties:
        name:
          type: string
        sub-foos:
          type: array
          items:
            type: object

If I select OpenAPI Designer > Preview in side panel, it works fine.

If I reference foo as the type of sub-foos, which is legal in OAS, I get an error in the preview and it loads the default Pet Store example. Also, the auto-complete does not list Foo when trying to $ref it inside of itself.

    Foo:
      type: object
      properties:
        name:
          type: string
        sub-foos:
          type: array
          items:
            $ref: '#/components/schemas/Foo'

Here is what I get then:

image

philosowaffle commented 5 years ago

If anyone has any bandwidth can you validate this type of circular reference works in the official https://editor.swagger.io/? Primarily, this extension just wraps the official editor so its helpful to know how the official editor behaves given a circular reference.