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

Refresh preview when saving other files.

Open CSpy163 opened this issue 3 years ago • 2 comments

https://davidgarcia.dev/posts/how-to-split-open-api-spec-into-multiple-files/

From the article above, openapi's config file can split into multiple files, how can i refresh the top openapi.yaml preview when i save it's reference file?

Sorry for my poor English.

CSpy163 avatar Nov 28 '21 09:11 CSpy163

Hi, it looks like the plugin does not support multiple files. The view is not refreshed, and the plugin does not display errors. I think as of now the only workaround is to compile one files using swagger-cli as mentioned in the article you have linked.

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.

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

This is a duplicate of https://github.com/arjun-g/vs-swagger-viewer/issues/14.

skwasniak avatar Feb 25 '22 15:02 skwasniak