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
171 stars 47 forks source link

Refresh preview when saving other files. #106

Open CSpy163 opened 2 years ago

CSpy163 commented 2 years ago

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.

skwasniak commented 2 years ago

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 commented 2 years ago

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