Skip to content
Latchkey

How to Validate an API Against Its Spec With Dredd in CI

Dredd replays every example in an API description against the running server and flags mismatches.

Give dredd the description file and the base URL. It sends each documented request and compares the real response to the spec.

Steps

  • Install with npm install -g dredd.
  • Start the API and wait for it to be ready.
  • Run dredd <spec> <base-url> and let a non-zero exit fail the job.

Workflow

.github/workflows/ci.yml
jobs:
  dredd:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm install -g dredd
      - run: |
          npm start &
          npx wait-on http://localhost:3000/health
      - run: dredd openapi.yaml http://localhost:3000 --reporter junit --output results/dredd.xml

Gotchas

  • Use a dredd.yml hooks file to seed data or auth before requests run.
  • Dredd needs concrete example values in the spec; endpoints without examples are skipped.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →