A flexible JSON/YAML linter, with out of the box support for OpenAPI v2/v3 and AsyncAPI v2.
- Create custom rules to lint JSON or YAML objects
- Ready-to-use rules to validate and lint:
- OpenAPI v2 and v3 documents
- AsyncAPI v2 documents
- Use JSON path to apply rules to specific parts of your objects
- Built-in set of functions to help create custom rules. Functions include pattern checks, parameter checks, alphabetical ordering, a specified number of characters, provided keys are present in an object, etc.
- Create custom functions for advanced use cases
- Validate JSON with Ajv
Spectral is 100% free and open-source, under Apache License 2.0.
npm install -g @stoplight/spectral
# OR
yarn global add @stoplight/spectral
Find more installation methods in our documentation.
This package is Treeware so if you would like to thank us for creating it, we ask that you buy the world a tree.
Take a look at our getting started documentation, then peek through some of our guides:
- Different Workflows - When and where should you use Spectral? Editors, Git-hooks, Continuous Integration, GitHub Actions, wherever you like!
- Using the command-line interface - Quickest way to get going with Spectral is in the CLI.
- Using the JavaScript API - Access the raw power of Spectral via the JS, or hey, TypeScript if you want.
- Custom Rulesets - Don't like our rules? Throw em out and make your own.
- Custom Functions - Rules can do absolutely anything, just write a little code.
Ajv is a JSON Schema validator, and Spectral is a JSON/YAML linter. Instead of just validating against JSON Schema, it can be used to write rules for any sort of JSON/YAML object, which could be JSON Schema, or OpenAPI, or anything similar. Spectral does expose a schema
function that you can use in your rules to validate all or part of the target object with JSON Schema (we even use Ajv used under the hood for this), but that's just one of many functions.
No problem! A hosted version of Spectral comes free with the Stoplight platform. Sign up for a free account here.
Speccy was a great inspiration for Spectral, but was designed to work only with OpenAPI v3. Spectral can apply rules to any JSON/YAML object (including OpenAPI v2/v3 and AsyncAPI). It's mostly been abandoned now, and is JavaScript not TypeScript.
- Stoplight Studio uses Spectral to validate and lint OpenAPI documents.
- Spectral GitHub Action, lints documents in your repo, built by Vincenzo Chianese.
- VS Code Spectral, all the power of Spectral without leaving VS Code.
If you are interested in contributing to Spectral, check out CONTRIBUTING.md.
- Mike Ralphson for kicking off the Spectral CLI and his work on Speccy
- Jamund Ferguson for JUnit formatter
- Sindre Sorhus for Stylish formatter
- Julian Laval for HTML formatter
- @nulltoken for a whole bunch of amazing features
If you need help using Spectral or have a support question, please use GitHub Discussions. It's also a great place to share your rulesets, or tools that leverage Spectral.
If you have a bug or feature request, please create an issue.