Spectral CLI
$ spectral Official Low RiskSpectral CLI (@stoplight/spectral-cli) is a flexible, ruleset-driven JSON/YAML linter widely used as the CI governance gate for OpenAPI, AsyncAPI, Arazzo, and custom JSON Schema documents. Built-in --format json / sarif, --ruleset, and --fail-severity flags make it a gold standard for automated API design validation.
npm install -g @stoplight/spectral-cli spectral lint --format json evaluates API specs directly against repository .spectral.yaml rulesets in milliseconds.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Purpose-built for CI and agents: --format json, --format sarif, --quiet, --stdin-filepath, --display-only-failures, and --fail-severity.
- 11 built-in formatters including
json,sarif, andgithub-actions - Zero interactive prompts and deterministic severity-based exit codes
Strictly read-only linter that never modifies API specification files.
- Zero write/mutation side effects on source specs
- No credentials required
Available via npm (@stoplight/spectral-cli), npx, Docker, and standalone pkg binaries on GitHub releases.
npm install -g @stoplight/spectral-cliand standalone binaries
Industry-standard API governance linter covering OpenAPI, AsyncAPI, Arazzo, and custom JSON/YAML schemas.
- Extensible JSONPath-based custom rulesets (
.spectral.yaml)
Official Stoplight repository (stoplightio/spectral) maintained under Apache-2.0.
- Official Stoplight GitHub organization
Comprehensive Stoplight docs covering CLI flags, rulesets, and built-in OAS/AsyncAPI functions.
- Official docs at docs.stoplight.io/docs/spectral/
Security, Auth & Guardrails
No credentials required; pure local linter (remote $ref or ruleset URLs are fetched over HTTP only if referenced).
Free open-source software (Apache-2.0).
# Spectral CLI Agent Rules - Always run `spectral lint <spec> --format json --quiet` after editing OpenAPI or AsyncAPI files. - Respect the repository's `.spectral.yaml` / `.spectral.yml` ruleset rather than bypassing rules. - Use `--stdin-filepath` when linting unsaved spec snippets via stdin.
Agent-Ready Command Recipes
Safe Read-Only Queries
spectral lint openapi.yaml --format json --quiet
Validates openapi.yaml against .spectral.yaml (or default OAS rules) and outputs JSON diagnostics.
spectral lint "specs/*.yaml" --format sarif --fail-severity warn
Outputs SARIF results and exits non-zero on any warning or error across specs/*.yaml.
Strengths for Agents
- + Rich machine-readable formatters (
--format json,sarif,junit,github-actions) plus--quietand--fail-severity. - + Strictly read-only validation across OpenAPI, AsyncAPI, Arazzo, and arbitrary YAML/JSON.
- + Supports
--stdin-filepathfor fast in-memory spec linting and standalone binaries alongside npm.
Caveats & Pitfalls
- ! Custom JS functions inside
.spectral.yamlrulesets execute local Node code when present. - ! Lint-only tool—use
redocly bundleoropenapi-generator-clifor bundling and code generation.