swagger-petstore icon indicating copy to clipboard operation
swagger-petstore copied to clipboard

How to split Path Item Object into seperate yaml file ?

Open DevDengChao opened this issue 2 years ago • 2 comments

As a real-world project gose on, the number of paths grows, and the single yaml file becomes bigger, which lead to a slow loading when the swagger-ui js is trying to load a full yaml file.

I'd like to known how to spilt Path Item Object into seperate yaml files, but also keeps the auto-complete suggestion provided by any IDE, is there any official suggestions / guides / examples ?

  • IDEA uses schema store's open api schema to provide auto-complete suggestion.

DevDengChao avatar Jan 18 '24 08:01 DevDengChao

To split the Path Item object into separate YAML files while maintaining autocomplete suggestions in IDEs like IDEA, you can follow these steps:

  1. Separate paths into individual files: create separate YAML files for each endpoint or groups of endpoints. For example, you could have files like user.yaml, product.yaml, order.yaml, etc., each containing the definitions for their respective paths.

  2. Utilize references: in your main Swagger YAML file, use references to these separate files containing path definitions. For instance:

paths: $ref: 'user.yaml' $ref: 'product.yaml' $ref: 'order.yaml'

  1. JSON references: you can also utilize JSON References to reference external files containing path definitions. This allows for a more flexible project structure and easier maintenance.

  2. configure IDE for autocomplete: Configure your IDE settings to point to the OpenAPI schema from schema store to enable autocomplete suggestions for your YAML files. This will allow the IDE to provide prompts for keywords, data structures, and other OpenAPI specification elements within your files.

For example, In IntelliJ IDEA you can find various settings for autocompletion and hints. Open the Settings window (File > Settings) and review the editor and autocompletion sections.

Here is the documentation - https://www.jetbrains.com/help/idea/auto-completing-code.html

IvanovIlya116 avatar May 14 '24 13:05 IvanovIlya116

@IvanovIlya116 Thanks, I'll give it a try.

DevDengChao avatar May 15 '24 01:05 DevDengChao