vs-swagger-viewer icon indicating copy to clipboard operation
vs-swagger-viewer copied to clipboard

Unable to reference a local yaml file.

Open lalaqc opened this issue 7 years ago • 6 comments

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

Example:

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

lalaqc avatar Apr 28 '17 18:04 lalaqc

I have the same problem

MinjieTao avatar May 27 '17 03:05 MinjieTao

Same...

mfeitoza avatar Dec 14 '17 00:12 mfeitoza

any workaround for the problem

ikarm avatar Jan 09 '18 09:01 ikarm

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

tim-digitised avatar May 27 '18 20:05 tim-digitised

Seems related to #45

cassioconti avatar Jan 17 '19 20:01 cassioconti

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.

skwasniak avatar Feb 25 '22 15:02 skwasniak