The Spectral VS Code Extension brings the power of Spectral to your favorite editor.
Spectral is a flexible object linter with out of the box support for OpenAPI v2 and v3.
- Lint-on-save
- Lint-on-type
- Custom ruleset support (
spectral
or.spectral
files with.json
,.yaml
or.yml
extensions) - Intellisense for custom ruleset editing
- Support for JSON and YAML input
Visual Studio Code version 1.37 or higher.
- Install from the Visual Studio Code Marketplace
- Install via the CLI:
code --install-extension stoplight.spectral
- Create a
.vsix
bundle using vsce (npm install -g vsce
) withvsce package
andcode --install-extension {vsix filename}
- Clone the GitHub repository
- Run
yarn
- Open the folder where you cloned the repository in VS Code
- Start the included debugging configuration
Please run yarn run lint
and yarn run test
before creating any pull-requests.
This extension contributes the following settings:
spectral.lintOnSaveTimeout
: Delay in ms before linting, default:2000
spectral.defaultRuleset
: Default ruleset URI, default:spectral:oas
spectral.clampRanges
: Minimize range highlighted by errors and warnings, default:true
If you open a single file in VS Code (as opposed to opening a folder or
workspace), then Spectral rulesets (.?spectral.{yml|yaml|json}
files) will
not be found, even if they are in the same directory. This is due to the use
of the recommended/performant VS Code APIs for finding and watching files,
which are exclusively workspace-based.