@zapier/spectral-api-ruleset
v2.13.0
Published
Spectral ruleset for Zapier API Guidelines.
Downloads
41,381
Readme
Ownership
#team-staff-engineering owns the API Design Guidelines and these spectral rules that help teams align with them.
MRs are always welcome!
Versioning Philosophy
This ruleset ships in two major version lines:
1.x — Leveling up existing APIs
The 1.x series (latest: 1.9.0) was designed to help existing API services incrementally improve their alignment with Zapier's API Design Guidelines. Rules used warn and info severities to surface issues without blocking CI pipelines, giving teams time to address them.
Existing services can stay on 1.x. There is no requirement to upgrade — 1.x will continue to receive backported rule additions where appropriate.
2.x — Strict standards for new APIs
The 2.x series is for new API services that should come out of the box fully aligned with all key API Design Guidelines. All rules are elevated to error severity (except rate-limit/503 rules which remain info since those concerns may be handled upstream by a proxy, load balancer, or WAF).
Key differences from 1.x:
- All rules are errors — linting violations fail CI by default
- Auth schemes tightened — only
anonymousServiceJwt,serviceAndUserJwt, andOAuthare allowed (legacy schemes likeuserJwt,apiKey,zapierSessionrequire an exemption) - Public API gateway requirement — APIs must pass the 2.x ruleset to be promoted to public status via
api.zapier.com
New services should adopt 2.x. Zapier's API service templates will ship with 2.x lint rules configured.
Which version should I use?
| Scenario | Version |
|----------|---------|
| Existing service, already linting with 1.x | Stay on 1.9.0 (upgrade when ready) |
| New API service | Use 2.x |
| API being promoted to public via api.zapier.com | Must pass 2.x rules |
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.
Exemptions
Some rules in this ruleset can be exempted on a case-by-case basis with approval from #team-staff-engineering. Below are the available exemptions and how to use them.
Sorting Parameter Exemption
The zapier-sorting-parameter rule requires using order_by instead of sort_by or ordering for sorting parameters. If you need to use an alternative parameter name, you can request an exemption.
paths:
/test:
get:
parameters:
- name: sort_by
in: query
x-zapier-sorting-parameter-exempt: true
description: Field to sort byExclusionary Filter Exemptions
Two rules keep exclusionary filters (?exclude_zap_ids=1,2) consistent, and a third blocks the Django ORM lookup style they replace:
zapier-no-orm-lookup-parameter— no__in a query parameter name. Exempt withx-zapier-orm-lookup-exempt: true.zapier-exclusion-parameter-naming— exclusions must be spelledexclude_<plural field>. Exempt withx-zapier-exclusion-exempt: true.zapier-exclusion-parameter-shape— an array-valuedexclude_*parameter must setstyle: formandexplode: false. Exempt withx-zapier-exclusion-exempt: true.
A legacy Django-style exclusion parameter trips the first two rules at once, so exempting it fully takes both flags:
paths:
/test:
get:
parameters:
- name: owner_id__not_in
in: query
x-zapier-orm-lookup-exempt: true
x-zapier-exclusion-exempt: true
description: Owner IDs to filter out (pending rename to exclude_owner_profile_ids)Version in Paths Exemption
The zapier-single-major-version-in-paths rule requires all paths to contain a major version (e.g., /v1/). If you need paths without versioning, you can request an exemption.
paths:
/no-version-but-exempt:
x-zapier-version-in-paths-exempt: true
get:
description: This path is exempt from versioning requirementAuth Scheme Exemption
The zapier-allowed-auth-schemes rule requires using one of the allowed authentication schemes for new APIs (anonymousServiceJwt, serviceAndUserJwt, or OAuth). If you need to use a different scheme (e.g., legacy userJwt, apiKey, or custom HMAC signatures), you can request an exemption.
components:
securitySchemes:
hmacSignature:
type: apiKey
in: header
name: X-Signature
x-zapier-auth-scheme-exempt: true
description: Legacy HMAC signature schemeRequired Scopes Exemption
The scope rules enforce the granular scope convention (<resource>[:<subresource>][:<action>], actions read | write | delete | run):
zapier-required-scopes-present— operations secured byserviceAndUserJwtat the operation level must declare a non-emptyx-zapier-required-scopes.zapier-required-scopes-present-inherited— the same requirement for operations that inheritserviceAndUserJwtfrom the root-levelsecurityarray (OpenAPI security inheritance) without overriding it.zapier-scope-name-format/zapier-scope-action-vocabulary— scope names must follow the convention. Checked everywhere a scope name can appear:x-zapier-required-scopesentries, inline security-requirement scopes (operation- and root-level) on the approved schemes, andoauth2security-scheme flow scope definitions.
OAuth-secured operations are not required to carry x-zapier-required-scopes because the OAuth2 security scheme declares scopes natively — but their scope names are still checked for format/vocabulary. If an operation legitimately cannot declare convention-compliant scopes (e.g. an internal-facing operation in a shared spec, or a legacy off-pattern scope pending rename), add x-zapier-required-scopes-exempt: true to the operation to skip the presence and naming rules for that operation.
Two structural companions are not exemptable, because they flag things that are always mistakes rather than policy choices: zapier-required-scopes-valid (wherever the extension appears on an operation it must be a non-empty array of non-empty strings) and zapier-required-scopes-operation-level (the extension and the exempt flag are only honored on the operation object — declared at the path-item or root level they are silently ignored by tooling, so the rule rejects them there).
paths:
/v1/legacy/zaps:
get:
# The exempt flag alone suppresses the presence and naming rules. The
# x-zapier-required-scopes below is only shown to illustrate a legacy
# off-pattern scope being carried through — it is not required for the
# exemption to take effect.
x-zapier-required-scopes-exempt: true
operationId: listZaps
x-zapier-required-scopes:
- zap:allDevelopment
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. In 2.x, all rules should beerrorunless the rule covers something that may be handled upstream (e.g., rate limiting, service unavailability), in which case useinfo. - 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.
