Spectral

一个灵活的 JSON/YAML linter,用于创建自动化的样式指南,支持 OpenAPI v2 & v3。「A flexible JSON (and YAML) linter with out of the box support for OpenAPI v2 and v3」

Github星跟蹤圖

Spectral logo

CircleCI
NPM Downloads
Buy us a tree

A flexible JSON/YAML linter, with out of the box support for OpenAPI v2 and v3.

Demo of Spectral linting an OpenAPI document from the CLI

Spectral Features

  • Create custom rules to lint JSON or YAML objects
  • Ready to use rules to validate and lint OpenAPI v2 and v3 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

Installation

npm install -g @stoplight/spectral

# OR

yarn global add @stoplight/spectral

For more installation options, see Getting Started > Installation

Getting Started

After installation take a look at our getting started documentation.

FAQs

How is this different to AJV

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.

I want to lint my OpenAPI documents but don't want to implement Spectral right now.

No problem! A hosted version of Spectral comes free with the Stoplight platform. Sign up for a free account here.

What is the difference between Spectral and Speccy

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 and v3) through the use of JSONPath given parameters. Some rule types have been enhanced to be a little more flexible along with being able to create your own rules based on the built-in functions, and we've added the ability to define custom functions too.

Contributing

If you are interested in contributing to Spectral itself, check out our contributing docs to get started.

If you are using Spectral in your project and want to be listed in the examples section, we encourage you to open an issue.

Example Implementations

  • JSONPath Online Evaluator, a helpful tool to determine what given path you want
  • stoplightio/json, a library of useful functions for when working with JSON
  • stoplightio/yaml, a library of useful functions for when working with YAML, including parsing YAML into JSON, and a few helper functions such as getJsonPathForPosition or getLocationForJsonPath

Thanks

Support

If you have a bug or feature request, please create an issue.

If you need help using Spectral or have a support question, please use the Stoplight Community forum. We've created an open source category for these questions. It's also a great place to share your implementations.

If you want to discuss something in private, you can reach out to Stoplight support at support@stoplight.io.

主要指標

概覽
名稱與所有者stoplightio/spectral
主編程語言TypeScript
編程語言TypeScript (語言數: 5)
平台Linux, Mac, Windows
許可證Apache License 2.0
所有者活动
創建於2018-08-15 18:43:18
推送於2025-04-23 11:42:37
最后一次提交
發布數376
最新版本名稱@stoplight/spectral-ruleset-bundler-1.6.3 (發布於 )
第一版名稱v0.1.0-beta.1 (發布於 )
用户参与
星數2.7k
關注者數33
派生數257
提交數2.1k
已啟用問題?
問題數913
打開的問題數191
拉請求數1370
打開的拉請求數13
關閉的拉請求數305
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?