OpenAPI-TS for Typescript Client Generation #18
chasetmartin
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Pros and Cons Discussion for Using OpenAPI-TS for TypeScript Client Generation
Introduction/Problem/Context
Building a refine.dev application with frequent API changes can be challenging when keeping the frontend in sync with the backend, having to update Interface files manually.
The goal for integrating OpenAPI-TS would be to partially automate type and client updates by running a code generation script whenever the OpenAPI spec changes on the backend, while maintaining manual control over when and how these updates are integrated.
@hey-api/openapi-ts
is an OpenAPI-to-TypeScript code generation tool that can produce TypeScript type definitions and a fully-typed API client (SDK) from an OpenAPI 3.x spec. It supports OpenAPI v2, v3.0, v3.1 and offers flexible plugins for different runtimes (Fetch, Axios, Next.js, etc.) and validations (e.g., Zod schemas). Essentially, it can auto-generate files for your API’s types and endpoint calls, ensuring the frontend Refine data provider stays aligned with the backend API contract.⭐️ Pros of Using OpenAPI-TS for Client Generation
Up-to-Date Type Safety and Consistency
Reduced Manual Effort and Boilerplate
npm run openapi-ts
.Reliable and Well-Supported Tooling
-OpenAPI-TS
Comprehensive Type Coverage
Ready-to-Use API Client Functions
addEntity(data)
for API calls.⛔️ Cons of Using OpenAPI-TS with Client Generation
Initial Setup & Learning Curve
openapi.json
(this part is handled by FastAPI)Generated Code Maintenance
Integration with Refine Data Layer
dataProvider
manually (although that should just be one file)Naming and Style Concerns
operationId
s or path structure.operationId
s, naming may be cryptic or verbose.Handling Complex API Features
any
or generate overly broad types.Frequent Updates and Workflow Overhead
More Thoughts
Adopting automatic TypeScript client generation means the API spec is the single source of truth. It ensures type consistency, could improve developer velocity during times when the api is changing quickly, and could prevent integration bugs.
A good consistent workflow would be critical: OpenAPI spec changes > TS client generation/update > front end updates > commit and merge
Beta Was this translation helpful? Give feedback.
All reactions