Skip to content

๐Ÿ” OpenAPI Drift Guard โ€‹

AI-powered API contract drift detection โ€” catch breaking changes between OpenAPI spec and implementation before they reach production.

npm versionlicense

The Problem โ€‹

API specs and implementation code drift apart silently:

Spec: GET /users/{id} โ†’ returns User
Code: GET /users/:id  โ†’ returns UserDTO (extra fields, missing id)

Traditional testing catches runtime errors, but misses:

  • Missing endpoints in code
  • Extra undocumented endpoints
  • Schema mismatches (request/response)
  • Parameter type changes

The Solution โ€‹

OpenAPI Drift Guard detects drift through three layers:

LayerCapabilityOutput
Spec ParsingParse OpenAPI/Swagger into normalized endpointsNormalizedEndpoint[]
Code AnalysisExtract routes from frameworksNormalizedEndpoint[]
Drift DetectionCompare and classify severityDriftReport

Severity Levels โ€‹

SeverityMeaningExample
๐Ÿ”ด BreakingWill break clientsMissing endpoint, required field removed
๐ŸŸก WarningMay cause issuesOptional field removed, type changed
๐ŸŸข InfoNon-breakingExtra endpoint, new optional field

Key Features โ€‹

๐Ÿ” OpenAPI/Swagger Parsing โ€‹

Structured parsing with zero configuration:

  • OpenAPI 3.x โ€” JSON/YAML parsing with full schema support
  • Swagger 2.0 โ€” Automatic normalization to OpenAPI 3.0
  • $ref Resolution โ€” Recursive reference resolution
  • Unified Model โ€” NormalizedEndpoint for spec and code

๐Ÿง  Code Analysis โ€‹

  • Express/Fastify/Koa/NestJS/Hono route extraction
  • TypeScript type inference for request/response
  • Parameter extraction from route definitions

๐Ÿ”„ Interactive Commands โ€‹

In Claude Code, use natural language drift detection:

CommandPurpose
/validate <spec> <code>Full contract validation
/drift <endpoint>Endpoint drift detail
/contract <operationId>Operation contract check
/check-api <area>Area batch validation

Example Output โ€‹

/validate openapi.yaml src/

๐Ÿ” API Contract Drift Report:

  ๐Ÿ“‹ Spec: openapi.yaml (version 3.0.3)
  ๐Ÿ“‚ Impl: src/routes/*.ts

  ๐Ÿ”ด Breaking Changes (3):
    1. [DELETE /users/{id}] Endpoint removed from impl
    2. [POST /orders] Required field userId removed
    3. [GET /products] Response type changed (string โ†’ number)

  ๐ŸŸก Warnings (2):
    1. [PUT /users/{id}] New constraint added: minLength(5)
    2. [GET /products] Field deprecated without replacement

  ๐ŸŸข Info (1):
    1. [GET /products] Optional field tags added

  ๐Ÿ“Š Summary:
    Total drifts: 6 | Breaking: 3 | Warnings: 2 | Info: 1

Comparison โ€‹

DimensionSchema ValidationOpenAPI Drift Guard
TimingRuntimeDesign time
CoverageSingle requestFull API surface
Drift DetectionโŒ Noโœ… 8 drift types
Code AnalysisโŒ Noโœ… Framework-aware
Severity LevelsโŒ Noโœ… ๐Ÿ”ด๐ŸŸก๐ŸŸข classification

Get Started โ€‹

Choose your path:

bash
/plugin marketplace add saqqdy/openapi-drift-guard
/plugin install openapi-drift-guard

2. NPM Package โ€‹

bash
pnpm add openapi-drift-guard

3. CLI (Zero-Install) โ€‹

bash
npx openapi-drift-guard validate --spec ./openapi.yaml --code ./src

Project Status โ€‹

VersionThemeStatus
v0.1.0Spec parsing + Express analyzerโœ… Released
v0.2.0Multi-framework support๐Ÿ“‹ Planned
v0.3.0Claude Code Skill ready๐Ÿ“‹ Planned
v0.4.0CI/CD integration๐Ÿ“‹ Planned
v1.0.0Production-ready๐Ÿ“‹ Planned

See Roadmap for details.

License โ€‹

MIT โ€” use freely in personal and commercial projects.

MIT License