This plugin is a wrapper for the tool Spectral, a linter for OpenApi schemas. It is a fork of https://github.com/SchwarzIT/spectral-intellij-plugin
-
Using IDE built-in plugin system:
Settings/Preferences > Plugins > Marketplace > Search for "Spectral Linter" > Install Plugin
-
Manually:
Install it manually using Settings/Preferences > Plugins > ⚙️ > Install plugin from disk...
This plugin it is required to have the spectral CLI installed on your system. For windows it is recommended to install the binary without going through Nodejs.
Warning Should you still want to use the spectral package via NodeJs on Windows then you must check "Use node package on Windows" in the plugin settings. This is necessary for the node packages to work and will have a performance cost.
If you don't have it installed yet make sure to follow this guide: Installing Spectral
Note: The CLI needs to be in your path and executable from the command line.
Automatic linting of your OpenApi specifications and highlighting in your editor
Specify your own ruleset in the plugins settings, under Preferences -> Tools -> Spectral -> Ruleset.
There you can specify a file on your local machine or just paste the URL of a ruleset available on the internet e.g.: Zalando Ruleset.
Examples:
- Link to a hosted ruleset:
https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/zalando.yml
- Local ruleset relative to Project base-path:
.spectral.yaml
- Fully-qualified path:
/Users/user/.spectral.yaml
Select the files that will be linted. By default, every file called "openapi.json", "openapi.yml" or "openapi.yaml" within the Project root will be matched for linting by the plugin when it's opened.
You can adjust this in the settings under Preferences -> Tools -> Spectral Linter -> Included path patterns. All paths are relative to the project's root directory unless absolute.
Examples:
openapi.json
: Matches the file called "openapi.json" inside the root directory of the projectcomponents/**/*.yaml
: Matches all files inside the project subdirectory "components" that end with ".yaml"/Users/user/code/**/openapi*.yaml
: Matches all YAML files within the absolute path "/Users/mick/code" that start with "openapi" and end with ".yaml"
Note: Each file must also be recognised by the IDE as a JSON or YAML file - that is with a suitable File Type association. If it is detected as a plain text (or any other type) it will be ignored.
Spectral offers the possibility to add file based overrides as described here. These don't work by default. If you want to make use of them, then you need to check "Use file level overrides" in the plugin settings.
Warning If turned on, this has a important caveat; you need to save the file for the linting output to match your changes again.
./gradlew verifyPlugin
./gradlew buildPlugin
./gradlew runIdeForUiTests
./gradlew publishPlugin
Plugin based on the IntelliJ Platform Plugin Template.