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.xmlGotchas
- Use a
dredd.ymlhooksfile to seed data or auth before requests run. - Dredd needs concrete example values in the spec; endpoints without examples are skipped.
Related guides
How to Fuzz an OpenAPI Spec With Schemathesis in CIRun property-based API tests in GitHub Actions with Schemathesis, generating cases from an OpenAPI schema and…
How to Lint an OpenAPI Spec With Spectral in CILint an OpenAPI or AsyncAPI document in GitHub Actions with Spectral, enforcing style and correctness rules s…
How to Give API Tests a Real Database With Service Containers in CIBack API tests with a real Postgres in GitHub Actions using a service container with health checks, so integr…