Drift check for OpenAPI
openapi-drift reads the routes your NestJS, Express, Fastify, Hono or Spring code declares straight from the source files, compares them with the document, and fails the build when they disagree, in either direction. No running server, no network, no AI, no build of your project: it runs in CI or as a GitHub Action on the pull request.
$ openapi-drift check --spec openapi.yaml --source src --prefix /api openapi.yaml: 10 operations under /api src: 9 routes under /api In the code, not in the document (2): GET /api/health (src/health.controller.ts:6) DELETE /api/users/{id} (src/users/users.controller.ts:26) — the path exists with GET, PATCH In the document, not in the code (3): POST /api/orders (createOrder) — the path exists with GET PATCH /api/orders/{orderId} (updateOrder) — the path exists with PUT GET /api/users/{id}/avatar (getAvatar) Path parameters named differently (1, not a failure): GET /api/orders/{id}/items: document {id}, code {orderId} (src/orders/orders.controller.ts:11) 5 drifts.
Everything built on the document is only as good as the document: generated tests, client SDKs, mocks, the reviewer reading it. A document that drifts from the code makes all of them wrong without anyone noticing.
Routes the code serves but the document does not describe, and operations the document promises but no route serves.
NestJS decorators, Express, Fastify and Hono calls and Spring annotations are read from the source text. Nothing is installed or started, so it runs in a second on any CI runner.
/users/{id} and /Users/:userId are the same route; the different parameter names are a note, not a
failure.
| NestJS |
@Controller('users'), @Controller({ path }), @Controller(['a', 'b']) with
@Get, @Post, @Put, @Patch, @Delete, @Head,
@Options, @All. The global prefix (setGlobalPrefix) and URI versions are read from the
code; --prefix is for a value the source does not show.
|
|---|---|
| Express |
app.get('/x', ...), router.post(...), app.route('/x').get().post(),
app.all, with routers mounted by app.use('/prefix', router) in the same file or imported from
another.
|
| Fastify |
fastify.get('/x', ...) and the other verbs, fastify.route({ method, url }), each under the prefixes
of the plugins given to register, in the same file or imported from another.
|
| Hono |
app.get('/x', ...) and the other verbs, app.on(method, path), chains, under
basePath('/api') and the prefixes of app.route('/users', users), in the same file or imported from
another. :id{[0-9]+} and :id? are {id}.
|
| Spring |
Java and Kotlin: @GetMapping, @PostMapping, @PutMapping, @PatchMapping,
@DeleteMapping and @RequestMapping on a @RestController or @Controller,
under the class's own @RequestMapping.
|
| Document |
OpenAPI 3.x or Swagger 2.0, YAML or JSON, in one file or split into files ($ref: ./paths/users.yaml). The base
path of servers[0].url, with the defaults of its variables (basePath in Swagger 2.0), is applied.
openapi-drift lint lists the document's own problems first.
|
The action writes the Markdown report to the job summary and exposes the number of drifts; fail-on chooses which
direction fails the job. Each drift is also an annotation on its line of the pull request (annotations, on by
default), and sarif writes a SARIF log for GitHub code scanning, where alerts stay open until the drift is fixed.
- uses: vannt-dev/openapi-drift@v0
id: drift
with:
spec: openapi.yaml
source: src
prefix: /api # optional
fail-on: any # or spec, code, none
sarif: openapi-drift.sarif # optional, for code scanning
- uses: github/codeql-action/upload-sarif@v4
if: always() && steps.drift.outputs.sarif != ''
with:
sarif_file: ${{ steps.drift.outputs.sarif }}
Node.js 22.18 or newer.
$ npm install -g openapi-drift $ openapi-drift check --spec openapi.yaml --source src $ openapi-drift routes --source src # what the code declares $ openapi-drift lint --spec openapi.yaml # the document's own problems $ openapi-drift check --spec openapi.yaml --source src --format sarif --output drift.sarif $ openapi-drift check --spec openapi.yaml --source src --format github # annotations in a workflow