@zapier/spectral-api-ruleset

1.2.0 • Public • Published

@zapier/spectral-api-ruleset

Node package for linting API schemas using Spectral.

OwnershipFeaturesInstallationUsageDevelopmentTesting


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-ruleset

For some reason, installing the CLI globally and running spectral lint or npx spectral lint always fails to find the package. Adding the CLI as a local dependency and then running pnpm exec spectral lint does 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.yaml

or

pnpm exec spectral lint your-schema.yaml --ruleset .spectral.yaml

or

spectral lint your-schema.yaml --ruleset https://unpkg.com/@zapier/spectral-api-ruleset@{VERSION}/.spectral.yaml

depending 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.xml

For 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_requests

See Continuous Integration docs and our own openapi:lint guideance in the Engineering Index for more details.

Development

Setup

  1. Install dependencies:
pnpm install
  1. Run tests:
pnpm test
  1. Build the package:
pnpm run build
  1. Validate the package:
pnpm run validate

Adding Rules

You can add rules to .spectral.yaml. See the Rules docs for details.

  • Provide the correct severity (error for minimal OpenAPI standard compliance, warn for "shoulds" for existing and new APIs, info for "where we want NEW APIs to be").
  • Provide a clear description, as well as a documentationUrl that 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.ts for all new rules.

Testing

This project uses Vitest for testing. To run the tests:

pnpm test

Publishing

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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.0631latest
0.0.3-11canary
0.0.0-rc11next

Version History

VersionDownloads (Last 7 Days)Published
1.2.0631
1.1.052
1.0.216
1.0.11
1.0.02
0.0.675
0.0.51
0.0.41
0.0.31
0.0.3-11
0.0.3-01
0.0.21
0.0.2-21
0.0.2-11
0.0.2-01
0.0.11
0.0.01
0.0.0-rc11

Package Sidebar

Install

npm i @zapier/spectral-api-ruleset

Weekly Downloads

643

Version

1.2.0

License

none

Unpacked Size

15.3 kB

Total Files

3

Last publish

Collaborators

  • jason.brandt-zapier
  • ben.mcadams-zapier
  • kunal.mahajan-zapier
  • lstensager
  • diomer
  • eumie.jhong-zapier
  • mahsa.khoshab-zapier
  • matthew.hockenbury-zapier
  • kit.burgess-zapier
  • jake.talgard-zapier
  • jonathan.wise-zapier
  • isidro.hernandez-zapier
  • daniel.vagg-zapier
  • mason.geloso-zapier
  • lisa.orr
  • rafal.wilinski-zapier
  • anna.hadnagy-zapier
  • chris.lee-zapier
  • zackary.higgins-zapier
  • rahul.es-zapier
  • jake.lear-zapier
  • service-account-appsec
  • michael.gill-zapier
  • sara.gomez-zapier
  • cameron.phillips-zapier
  • joe.smith-zapier
  • olajide.ayinla-zapier
  • charan.mahesan-zapier
  • james.miltenberger-zapier
  • dan.middleton-zapier
  • jake.moghtader-zapier
  • treesrule14
  • aispurostrangepixels
  • carlos.bazana-zapier
  • diego.rodriguez.vzq
  • myless91
  • heather.osborn-zapier
  • nicholas.civili-zapier
  • lukas.toma-zapier
  • husaina.wardhawala-zapier
  • lisa.zapier
  • david.jardine-zapier
  • david.graves-zapier
  • ana.krivokapic-zapier
  • jacob.blakely-zapier
  • ryan.detzel-zapier
  • brody-zapier
  • ben.rugg-zapier
  • nicole.hardson-hurley-zapier
  • bryce.seagervandyk-zapier
  • christophe.coutzoukis-zapier
  • jessica.winters-zapier
  • cameron.barnes-zapier
  • wojciech.matuszewski-zapier
  • ankit.gordhandas-zapier
  • chrys.swingler-zapier
  • ryan.vennell-zapier
  • benjamin.kempe-zapier
  • ali.tycast-zapier
  • jelani.jackson-zapier
  • jdotcee
  • jeanny.sy
  • james.hong-zapier
  • dennis.kailikia-zapier
  • tom.leung-zapier
  • service-account-renovate
  • erin.williams-zapier
  • nolan.little-zapier
  • nik.danilov-zapier
  • michal.wysocki-zapier
  • tomasz.piechota-zapier
  • nate.moore-zapier
  • corbin.schwartz-zapier
  • andrew.kordampalos-zapier
  • jonathan.harrell-zapier
  • jc.coto-zapier
  • andrew.gosnell-zapier
  • amber.diehl-zapier
  • vivian.lau-zapier
  • osarhomiyeke.iyere-zapier
  • kristen.keller-zapier
  • blzapier
  • tal.peretz-zapier
  • shanan.holm-zapier
  • vj.clasgens-zapier
  • marina.hand
  • aubry.stewart-zapier
  • aleks.ozolins-zapier
  • abraham.duran-zapier
  • abdullah.umar-zapier
  • rohit.tripathi-zapier
  • mike.lambert-zapier
  • ted.schmidt-zapier
  • laura.giles-zapier
  • nitish.upadhyay-zapier
  • catherine.murray-zapier
  • ken.ng-zapier
  • omar.delossantos-zapier
  • ryan.laxson-zapier
  • pedro.louro-zapier
  • zac.jones-zapier
  • brandon.parker-zapier
  • alec.hinh-zapier
  • maggie.cody-zapier
  • mary.rising-zapier
  • harrison.jackson-zapier
  • matthew.kiernander-zapier
  • philip.ng-zapier
  • daniel.shepard-zapier
  • sharvari.desai-zapier
  • jenna.macdonald-zapier
  • rval-zapier
  • ryan.dunnewold-zapier
  • ashley.isles-zapier
  • service-account-catalog
  • tazrafiq
  • jayson.kadlecek-zapier
  • ismail.latona-zapier
  • kasey.cowley-zapier
  • sarah.hernandez-zapier
  • aaron.kosel-zapier
  • iris.huang-zapier
  • zapier-interfaces
  • vitor.balocco-zapier
  • scott.woodend-zapier
  • emily.harris-zapier
  • sandy.brydon-zapier
  • brian.wendt-zapier
  • ron.swanson-zapiertest
  • dilan-zapier
  • katestamzap
  • jhk2020
  • percy_at_zapier
  • tupelo8
  • dewayne-zapier
  • sarahstory
  • raquel.zapier
  • danielheidornzap
  • alex.black
  • katesowles
  • jacquelynmccray
  • schlickmann
  • cody.landry
  • hgascoigne
  • ahsanhassan
  • kaushib
  • nkroeker_zap
  • recamilio
  • andyzapier
  • ariella-zapier
  • valeriia.shpiner
  • rchinerman
  • miklossimon
  • amickael-zap
  • sethetter
  • yohana-heringer
  • rebecca.davis.zapier
  • ben.clapp.zapier
  • mattplachter
  • mirrenzap
  • lizzyzap
  • colemaclean
  • sdelosrios95
  • magweaver
  • joseph-corona-zapier
  • nickaccuardizapier
  • raul.negron
  • normanroa
  • fernando.velascosalazar
  • manasseh_zapier
  • davidwin-zap
  • gabebravo
  • annader-zapier
  • aparkin
  • abhi-kapoor
  • blakek
  • chasehamby
  • zoeykim-zapier
  • djeebus
  • xavierh-zapier
  • kalenwessel
  • lev.glick
  • greg-zapier
  • david.zapier
  • joel.taddei
  • robert.lewis
  • plorry
  • ilari.scheinin
  • msholty
  • poterekm
  • fgrafa
  • dayne-taitt
  • josuezap
  • pwhamman
  • omar.raza
  • adampie
  • erikamontani
  • standielpls
  • loveena.vattenky
  • jasehackman
  • tims256
  • zapetc
  • chaodonghu
  • emma-hays
  • michaelann
  • jdaudier
  • joaopimentel
  • ryanmrubin
  • ter0
  • rghazali
  • rsiemens
  • casshill13
  • eliang
  • noahmanger
  • kola-er
  • codebycaleb
  • calebpeterson
  • jordyvd
  • victoravasiloaei
  • lukecjohnson
  • zapier-engineering
  • stevemolitor
  • jdeal
  • bcooksey
  • bryanhelmig
  • robgolding
  • fokkezb
  • sam.plant
  • michaelgilley
  • mlukso
  • mikekuchera
  • joanne
  • juanv
  • ibrahem.zayed
  • muyiwa.olurin
  • jamesacarr
  • mikeknoop
  • josh.newman
  • parsenz
  • larryt
  • rhubbard
  • jacobsowles
  • jacebrowning
  • stacietaylorcima
  • hitchcockwill
  • renaekathleen
  • chelsea.weber
  • reganstarrzapier
  • cyberwitch
  • veebers
  • thomir
  • shalgrim
  • season.huang
  • chris.vanderkolk.zapier
  • nickm0501
  • kaycee
  • owarij
  • brian.corbin
  • darko.ronic.zapier
  • kredlear
  • numichuu
  • justin.zapier
  • chelschubb
  • skylershaw
  • daniel-frazier
  • aaclarker-zap
  • tiffanie
  • errorific
  • ezerwx
  • lijenni
  • jasonkotenko
  • wernertc
  • cortega_zp
  • tkcranny
  • brandon.myers.zapier
  • matthewwalters
  • kat.nestor
  • andya-zapier
  • iansco
  • will.wiggins
  • rondiege
  • annaulyanova
  • bskaurud
  • kaitrin.cox
  • jeansimon
  • rocioar
  • milkram
  • mburni
  • peterbritnell
  • guivasconcelos-zapier
  • carolinezapier
  • emmaielle
  • jeanetteu
  • ismael.mendonca
  • bbohen
  • sugatmahanti
  • nicole.thomas
  • agscala
  • jordanraleigh
  • josh.barber
  • kamalsingh.naruka
  • robertscl
  • wavebeem
  • laurenmbeatty
  • ankush_zapier
  • ihor.horak
  • maxwellgbrown
  • hanz.cortes
  • alejandro-lagos