@stoplight/spectral-documentation
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

Spectral Documentation Ruleset

NPM Downloads Stoplight Forest

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.

Installation

npm install --save -D @stoplight/spectral-documentation
npm install --save -D @stoplight/spectral-cli

Usage

Create a local ruleset that extends the ruleset. In its most basic form this just tells Spectral what ruleset you want to use, but it will allow you to customise things, add your own rules, turn bits off if its causing trouble.

cd ~/src/<your-api>

echo 'extends: ["@stoplight/spectral-documentation"]' > .spectral.yaml

If you're using VS Code or Stoplight Studio then the NPM modules will not be available. Instead you can use the CDN hosted version:

echo 'extends: ["https://unpkg.com/@stoplight/spectral-documentation/dist/ruleset.mjs"]' > .spectral.yaml

Note: You need to use the full URL with CDN hosted rulesets because Spectral cannot follow redirects through extends.

Next, use Spectral CLI to lint against your OpenAPI description. Don't have any OpenAPI? Record some HTTP traffic to make OpenAPI and then you can switch to API Design-First going forwards.

spectral lint api/openapi.yaml

You should see some output like this:

/Users/phil/src/protect-earth-api/api/openapi.yaml
  44:17      warning  no-path-versioning #/paths/~1v1 contains a version number. API paths SHOULD NOT have versioning in the path. It SHOULD be in the server URL instead.  paths./v1

Now you have some things to work on for your API. Thankfully these are only at the warning severity, and that is not going to fail continuous integration (unless you want them to).

There are a bunch of other rulesets you can use, or use for inspiration for your own rulesets and API Style Guides.

🎉 Thanks

  • Phil Sturgeon - Made some of these fairly opinionated but probably reasonable rules.

📜 License

This repository is licensed under the MIT license.

🌲 Sponsor

If you would like to thank us for creating Spectral, we ask that you buy the world a tree.

Package Sidebar

Install

npm i @stoplight/spectral-documentation

Weekly Downloads

3,404

Version

1.3.1

License

MIT

Unpacked Size

113 kB

Total Files

28

Last publish

Collaborators

  • sb-akshaythakar
  • sb-rohitdesai
  • sb-yogeshjadhav
  • sb-venkatyadavilli
  • sb-ankitapal
  • sb-harshitajadhav
  • sb-maitheelideshpande
  • sb-thakurrohit
  • mzheng_sb
  • troydm
  • naumanali__
  • mmurphy_stoplight
  • clanzo
  • kaylachun
  • brendarearden
  • danielwhite-stoplight
  • ed-stoplight
  • vazha
  • chohmann
  • wmhilton
  • mallachari
  • p0lip
  • paulatulis
  • ksoviero-stoplight
  • mmarti21
  • stoplight-devops
  • stoplight-spectral-bot