arjun-g / vs-swagger-viewer

Swagger Viewer lets you preview and validate Swagger 2.0 and OpenAPI files as you type in Visual Studio Code.
MIT License
170 stars 47 forks source link

Unable to reference a local yaml file. #14

Open lalaqc opened 7 years ago

lalaqc commented 7 years ago

Cannot reference an object type specified in another local yaml file.

Example:

Persons:     type: array     items:       $ref: "person.yaml#/Person"

MinjieTao commented 7 years ago

I have the same problem

mfeitoza commented 6 years ago

Same...

ikarm commented 6 years ago

any workaround for the problem

tim-digitised commented 6 years ago

Hey guys - I was having the same problem, but not with this particular extension, but just in general. Ended up finding and using this: https://github.com/mohsen1/multi-file-swagger-example and then wrote a small node app to monitor my files and update when ever changes are made.

Hope this helps

cassioconti commented 5 years ago

Seems related to #45

skwasniak commented 2 years ago

any workaround for the problem

The only one I can think of is to compile a single file as in the Step 6 of this article (https://davidgarcia.dev/posts/how-to-split-open-api-spec-into-multiple-files/).

UPDATE:

Make sure to have the correct paths, which are file specific. So assuming you have the following file structure:

api/
├── definitions
│   └── Pet.yaml
├── main.yaml
└── paths
    └── cmd
        └── getPetById.yaml

In the main file you will write:

# main.yaml
...
paths:
    /pets/{petId}:
      $ref: "definitions/Pet.yaml"
...
definitions:
  Pet:
    $ref: "paths/cmd/getPetById.yaml"

And in the Pet.yaml (notice the relative path to Pet.yaml!):

# getPetById.yaml
  responses:
    "200":
      description: "Successful operation"
      schema:
          $ref: "../../main.yaml#/definitions/Pet"

You can use swagger-cli to validate the file, and see better error descriptions.