Zurück zum Ranking

stoplightio/spectral

TypeScriptstoplight.io/spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.

json-schemajsonpathopenapiopenapi3oasv3oasopenapi-specificationjson-lintjsonlintingswaggerhacktoberfest
Sterne-Wachstum
Sterne
3.2k
Forks
284
Wochenwachstum
Issues
241
1k2k3k
Okt. 2018Mai 2021Dez. 2023Juli 2026
Artefaktenpmnpm install spectral
README

Demo of Spectral linting an OpenAPI document from the CLI CircleCI npm Downloads Stoplight Forest

  • Custom Rulesets: Create custom rules to lint JSON or YAML objects
  • Ready-to-use Rulesets: Validate and lint OpenAPI v2 & v3.x, AsyncAPI, and Arazzo v1 Documents
  • API Style Guides: Automated API Style Guides using rulesets improve consistency across all your APIs
  • Ready-to-use Functions: 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.
  • Custom Functions: Create custom functions for advanced use cases

Overview

🧰 Installation

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

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"

💻 Usage

1. Create a local ruleset

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.

2. Lint

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

📖 Documentation

Once you've had a look through the getting started material, some of these guides can help you become a power user.

  • 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 - Need something more than the core rulesets provide? Fancy building your own API Style Guide? Learn how to create a custom ruleset.
  • Custom Functions - Handle more advanced rules, by writing a little JavaScript/TypeScript and calling it as a function.

ℹ️ Support

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.

🌎 Real-World Rulesets

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:

  • OWASP Top 10 - Set of rules to enforce OWASP security guidelines.
  • URL Style Guidelines - Set of rules to help developers make better and consistent endpoints.
  • Documentation - Scan an OpenAPI description to make sure you're leveraging enough of its features to help documentation tools like Stoplight Elements, ReDoc, and Swagger UI build the best quality API Reference Documentation possible.

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:

  • Adidas - Adidas were one of the first companies to release their API Style Guide in a written guide and a Spectral ruleset. Lots of good rules to try in here.
  • APIs You Won't Hate - An opinionated collection of rules based on advice in the APIs You Won't Hate community.
  • Azure - Ruleset and complimentary style guide for creating OpenAPI 2 or 3 definitions of Azure services.
  • Box - Lots of Custom Functions being used to enforce good practices that the Box API governance folks are interested in.
  • DigitalOcean - Keeping their OpenAPI nice and tidy, enforcing use of $ref (probably to minimize conflicts), naming conventions for Operation IDs, and all sorts of other handy OpenAPI tips.
  • Tranascom - Don't even think about using anything other than application/json.
  • Zalando - Based on Zalando's RESTFUL API Guidelines, covers a wide-range of API topics such as versioning standards, property naming standards, the default format for request/response properties, and more.

Check out some additional style guides here:

⚙️ Integrations

🏁 Help Others Utilize Spectral

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 🎉

👏 Contributing

If you are interested in contributing to Spectral, check out CONTRIBUTING.md.

🎉 Thanks

📜 License

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.

Ähnliche Repositories
fastapi/fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

PythonPyPIMIT Licensepythonjson
fastapi.tiangolo.com
100.8k9.7k
fastapi/full-stack-fastapi-template

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.

TypeScriptnpmMIT Licensepythonjson
44.4k8.8k
pydantic/pydantic

Data validation using Python type hints

PythonPyPIMIT Licensevalidationparsing
pydantic.dev/docs/validation
28.3k2.8k
fastapi/sqlmodel

SQL databases in Python, designed for simplicity, compatibility, and robustness.

PythonPyPIMIT Licensepythonsql
sqlmodel.tiangolo.com
18.2k873
rjsf-team/react-jsonschema-form

A React component for building Web forms from JSON Schema.

TypeScriptnpmApache License 2.0reactjson-schema
rjsf-team.github.io/react-jsonschema-form/
15.8k2.3k
ajv-validator/ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

TypeScriptnpmMIT Licensejson-schemavalidator
ajv.js.org
14.8k998
glideapps/quicktype

Generate types and converters from JSON, Schema, and GraphQL

TypeScriptnpmApache License 2.0jsontypescript
app.quicktype.io
13.8k1.2k
alibaba/formily

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3

TypeScriptnpmMIT Licensereactjson-schema
formilyjs.org
12.6k1.6k
alibaba/x-render

🚴‍♀️ Very easy to use process form table chart solution.

TypeScriptnpmjavascriptreact
xrender.fun
7.9k1.1k
joelittlejohn/jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc

JavaMavenApache License 2.0javajson-schema
jsonschema2pojo.org
6.4k1.7k
samchon/typia

Super-fast/easy runtime validators and serializers via transformation

TypeScriptnpmMIT Licensejsonstringify
typia.io
5.9k223
microsoft/typespec

JavaMavenMIT Licenseopenapi3json-schema
typespec.io
5.8k375