@zapier/spectral-api-ruleset

1.0.2 • 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

or

pnpm exec spectral lint your-schema.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

See CONTRIBUTING, also for information on how we use @changesets/cli to version and publish.

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 src/index.ts. See the Alternative JS Ruleset Format docs for details.

We're using the JS format so that the package ruleset can also be used in JavaScript.

  • Provide the correct severity (error for musts and warn for shoulds).
  • Provide a clear description, as well as a documentationUrl that points to the relevant guide.
  • Provide a message, which in most cases should just be {{error}}.
  • Prefer Core Functions over Custom Functions.
  • Include a unit test for any custom functions you add to src/functions.
  • Update tests/schema.yaml to meet all rules (run pnpm run test:spectral to verify).
  • Add failing schemas to tests/__fixtures__ and run pnpm test integrations --updateSnapshot to update test/__snapshots__/integration.test.ts.snap and verify the found issues.

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @zapier/spectral-api-ruleset

Weekly Downloads

122

Version

1.0.2

License

none

Unpacked Size

11.8 kB

Total Files

3

Last publish

Collaborators

  • 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
  • alex.hovancik-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
  • mdgreenwald
  • 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