This repository is mentioned in my medium article.
This repository showcases an innovative approach to ensure API integrity between a Next.js server using tRPC and its corresponding clients. By auto-generating OpenAPI schemas based on the tRPC server, and then diffing these with previous versions, we can automatically detect and notify developers of breaking changes in the API.
In dynamic development environments, APIs often undergo changes. While some of these changes are benign, others can break client-server communication, especially in mobile applications. Promptly identifying such changes can save time, prevent bugs, and ensure a seamless user experience.
- Next.js with tRPC Integration: A foundational setup showcasing how tRPC can be used with Next.js.
- OpenAPI Auto-Generation: Automatically generate an OpenAPI schema based on the current tRPC setup. This schema acts as the source of truth for the API's current state.
- Diffing Mechanism with
openapi-diff
: By comparing the newly generated OpenAPI schema with a baseline (e.g., from the main branch), the system can detect and report changes in the API.
-
Clone the Repository
git clone https://github.com/Fralleee/trpc-breaking-changes-detection.git
-
Install Dependencies
Navigate to the project directory and install the necessary dependencies:
cd trpc-breaking-changes-detection pnpm install
-
Run the Next.js Server
pnpm run dev
-
Generate OpenAPI Schema
Instructions on how to generate the schema based on your current tRPC setup.
pnpm run generate-schema
-
Check for Breaking Changes
Start by creating a new branch and introducing either breaking or non-breaking modifications to the tRPC server. The automated action is configured to activate upon the creation of new pull requests, provided they are not set to draft status.
Feel free to raise issues or submit pull requests. Any contributions, big or small, are highly appreciated!