A flexible JSON linter with out of the box support for OpenAPI v2 and v3
1M+
The easiest way to install spectral is to use either npmâ :
npm install -g @stoplight/spectral-cli
Or yarnâ :
yarn global add @stoplight/spectral-cli
There are also additional installation optionsâ .
docker run --rm -it -v $(pwd):/tmp stoplight/spectral lint --ruleset "/tmp/.spectral.yaml" "/tmp/file.yaml"
The Docker image sends a lightweight anonymous telemetry ping on startup (version + platform) to help us understand adoption. To opt out, set DO_NOT_TRACK=1 or SCARF_NO_ANALYTICS=true:
docker run --rm -it -e DO_NOT_TRACK=1 -v $(pwd):/tmp stoplight/spectral lint --ruleset "/tmp/.spectral.yaml" "/tmp/file.yaml"
Spectral, being a generic YAML/JSON linter, needs a ruleset to lint files. A ruleset is a JSON, YAML, or JavaScript/TypeScript file (often the file is called .spectral.yaml for a YAML ruleset) that contains a collection of rules, which can be used to lint other JSON or YAML files such as an API description.
To get started, run this command in your terminal to create a .spectral.yaml file that uses the Spectral predefined rulesets based on OpenAPI, Arazzo or AsyncAPI:
echo 'extends: ["spectral:oas", "spectral:asyncapi", "spectral:arazzo"]' > .spectral.yaml
If you would like to create your own rules, check out the Custom Rulesetsâ page.
Use this command if you have a ruleset file in the same directory as the documents you are linting:
spectral lint myapifile.yaml
Use this command to lint with a custom ruleset, or one that's located in a different directory than the documents being linted:
spectral lint myapifile.yaml --ruleset myruleset.yaml
Once you've had a look through the getting started material, some of these guides can help you become a power user.
If you need help using Spectral or have any questions, you can use GitHub Discussionsâ , or visit the Stoplight Community Forumâ . These communities are a great place to share your rulesets, or show off tools that use Spectral.
If you have a bug or feature request, create an issue for itâ .
Stoplight has a set of Spectral rulesets that were created to help users get started with Stoplight's Style Guides. You can find them on API Stylebookâ , and you can download the source Spectral file by selecting a style guide on the project sidebar and selecting Export -> Spectral File(s) on the top-right. A few noteworthy style guides are:
There are also rulesets created by many companies to improve their APIs. You can use these as is to lint your OpenAPI descriptions, or use these as a reference to learn more about what rules you would want in your own ruleset:
$ref (probably to minimize conflicts), naming conventions for Operation IDs, and all sorts of other handy OpenAPI tips.application/json.Check out some additional style guides here:
If you're using Spectral for an interesting use case, create an issue with details on how you're using it. We'll add it to a list here. Spread the goodness đ
If you are interested in contributing to Spectral, check out CONTRIBUTING.mdâ .
Spectral is 100% free and open-source, under Apache License 2.0â .
If you would like to thank Stoplight for creating Spectral, buy the world a treeâ .
Content type
Image
Digest
sha256:a07aa4455âĻ
Size
67.1 MB
Last updated
about 2 months ago
docker pull stoplight/spectral