@zapier/spectral-api-ruleset v1.5.1
Ownership
#team-staff-engineering owns the API Design Guidelines and these spectral rules that help teams align with them.
MRs are always welcome!
Features
Provides a Spectral linting ruleset to lint OpenAPI schemas against Zapier's API Design Guidelines.
Installation
pnpm add -D @stoplight/spectral-cli
pnpm add -D @zapier/spectral-api-rulesetFor some reason, installing the CLI globally and running
spectral lintornpx spectral lintalways fails to find the package. Adding the CLI as a local dependency and then runningpnpm exec spectral lintdoes work.
Usage
CLI
There are a few ways you can use this ruleset in your projects.
You can load the ruleset in a few different ways with Spectral.
They support direct http access, via NPM, and via the local file system.
If you'd like to extend the ruleset and and even more specific rules for your API service, you can
create a local spectral.yaml that extends the ruleset:
extends:
- '@zapier/spectral-api-ruleset'Then run:
spectral lint your-schema.yaml --ruleset .spectral.yamlor
pnpm exec spectral lint your-schema.yaml --ruleset .spectral.yamlor
spectral lint your-schema.yaml --ruleset https://unpkg.com/@zapier/spectral-api-ruleset@{VERSION}/.spectral.yamldepending on whether you installed the CLI locally or globally.
See the Spectral CLI docs for more details.
CI
Use a GitLab job like the following:
openapi:lint:
stage: validate
before_script:
- mkdir spectral
script:
- pnpm exec spectral lint your-schema.yaml -o spectral/junit.xml -f junit
artifacts:
when: always
paths:
- spectral
reports:
junit: spectral/junit.xmlFor non-TypeScript projects, you can use the spectral docker image to avoid installing additional dependencies.
openapi:lint:
stage: test
image:
name: stoplight/spectral:6.11.0
entrypoint: [""]
script:
- spectral lint openapi.yaml
only:
- merge_requestsSee Continuous Integration docs and our own openapi:lint guideance in the Engineering Index for more details.
Development
Setup
- Install dependencies:
pnpm install- Run tests:
pnpm test- Build the package:
pnpm run build- Validate the package:
pnpm run validateAdding Rules
You can add rules to .spectral.yaml. See the Rules docs for details.
- Provide the correct
severity(errorfor minimal OpenAPI standard compliance,warnfor "shoulds" for existing and new APIs,infofor "where we want NEW APIs to be"). - Provide a clear
description, as well as adocumentationUrlthat points to the relevant guide or guide section. - Provide a
message, which in most cases should just be{{error}}. - Prefer Core Functions over Custom Functions.
- Include unit test(s) in
tests/spectral.test.tsfor all new rules.
Testing
This project uses Vitest for testing. To run the tests:
pnpm testPublishing
GitLab CI will automatically publish the package to NPM when a merge request is merged into the main branch.
Be sure to update the package version in package.json accordingly before merging.
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago