@zapier/spectral-api-ruleset
TypeScript icon, indicating that this package has built-in type declarations

1.4.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.

Readme

Keywords

none

Package Sidebar

Install

npm i @zapier/spectral-api-ruleset

Weekly Downloads

983

Version

1.4.0

License

none

Unpacked Size

23.7 kB

Total Files

10

Last publish

Collaborators

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