The classic story: the backend renames a field, updates the OpenAPI spec, every test passes, the PR gets merged... and the frontend breaks in production because it was still reading the old name.

Unit tests can't catch this, because each side is correct in its own universe. The bug lives in the contract between them. So I built rift, an open source (MIT) CI tool that compares the OpenAPI/Swagger spec of your backend with the TypeScript code of your frontend, and fails the PR when they diverge.

rift failing a PR with a drifted contract

How it works

  1. Extractor (Node + ts-morph): statically analyzes your .ts/.tsx files, finds fetch and axios calls, resolves their URLs, and figures out which response fields the frontend actually reads.
  2. Core (Java 21): loads the spec with swagger-parser and compares it against what the frontend consumes.
  3. Reporters: plain text, JSON, and GitHub annotations that show up directly on the lines of the PR.

No running app, no extra tests, no contract files to maintain by hand. The spec you already have is the source of truth.

What it detects

  • MISSING_ENDPOINT: the frontend calls an endpoint that is not in the spec
  • MISSING_FIELD: the frontend reads a response field the spec doesn't declare
  • ORPHAN_ENDPOINT: the spec declares an endpoint nobody consumes

The rift check CLI accepts --min-confidence and --fail-on, so you decide how strict your CI should be.

The design decision that matters most: don't guess

Static URL analysis is full of ambiguous cases: a prefix coming from a variable, an unknown HTTP method, a dynamically built URL. In those cases rift does not guess. Path matching has confidence levels (strong or weak), and when it isn't sure, it stays quiet instead of producing a false positive. A CI tool that fails PRs for no reason loses the team's trust within two weeks, and then it gets turned off.

Limitations

I'd rather be upfront about these (they are also documented in the repo):

  • Only fetch and axios, in .ts and .tsx files for now
  • Fields are only checked when they are read in the same function as the call, and only at the first level
  • If the spec has no properties for a response, rift doesn't judge its fields

What's next

The next item on the roadmap is following the response body when a function returns it to its caller, which would widen field coverage a lot.

Feedback welcome

If you have a separate backend and frontend, I'd love for you to try it on your project. Issues, criticism and ideas are very welcome, and a ⭐ on the repo helps it reach more people:

https://github.com/thomasbatista/rift