Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stoplight/spectral-url-versioning

Package Overview
Dependencies
Maintainers
24
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/spectral-url-versioning

There's no one right way to version, but there's a lot of objectively bad ways you want to avoid.

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
24
Created
Source

Spectral API Versioning Ruleset

NPM Downloads Stoplight Forest

API versioning can be a scary topic but there are a few easy wins that are always best avoided when using OpenAPI to describe an API, like not squashing multiple global versions into a single file.

Installation

npm install --save -D @stoplight/spectral-url-versioning
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-url-versioning"]' > .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-url-versioning/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.

Keywords

FAQs

Package last updated on 04 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc