Skip to content

OpenAPI snippets and external file validation extension for VSCode

Notifications You must be signed in to change notification settings

proohit/openapi-snippets

Repository files navigation

OpenApi Snippets

Usage

snippet-preview

snippets

currently supported snippets:

Prefix Content
pathget GET path object
pathgetparam GET path object with request parameters
pathpost POST path object
pathput PUT path object
pathputparam PUT path object with request parameters
pathdelete DELETE path object
pathdeleteparam DELETE path object with request parameters
schemaObject Schema object
propertyObject Property object for properties of a schema
contentType Several content types

Validation

JSON and YAML/YML files are being validated according to their respective usage (e.g. Schema Objects). For schema specifications, see OpenApi Specification v3

Note: For IntelliSense to validate the files, filenames have to match their respective schema:

File name pattern Example
`[components/schemas/* *-schema].(json,yaml,yml)`
`[paths/* *-path].(json,yaml,yml)`

You can navigate through predefined anchor points with TAB key. This only works right after inserting a snippet.

Note: For YAML/YML files to be supported, the YAML Extension has to be installed!

Keybindings

You can configure custom keybindings for the snippets. For this, open the keybindings.json file of VS Code (Shortcut Ctrl+K Ctrl+S, then click on the Open Keyboard Shortcuts (JSON) button in the upper right corner). For any keybinding, use this template and edit the fields which are marked by <<>>:

for json files:

{
  "key": "<<Your desired shortcut>>",
  "command": "editor.action.insertSnippet",
  "when": "editorTextFocus",
  "args": {
    "langId": "json",
    "name": "<<Snippet prefix>>"
  }
}

for yaml files:

{
  "key": "<<Your desired shortcut>>",
  "command": "editor.action.insertSnippet",
  "when": "editorTextFocus",
  "args": {
    "langId": "yaml",
    "name": "<<Snippet prefix>>"
  }
}

For name you can use any snippet prefix.

Installation

Just download and install it from VS Marketplace. There are no more settings, so the extension is ready to use after installation. It fully works with and extends OpenAPI (Swagger) Editor