-
Notifications
You must be signed in to change notification settings - Fork 468
Description
Following the implementation of spectacular, we have a simple way to generate a high-fidelity OpenAPI schema.
The frontend can now benefit from it by generating types directly from the schema and improve the type-safety of the application / accelerates development.
To be done:
- New backend makefile command to generate OpenAPI schema (
generate-openapi-schema) - New npm command to generate types from OpenAPI schema (
api-types-sync) -
common/types/responsesandcommon/types/requestscan start consuming the types - Bonus: create the claude command
Typescript generated file should look like:
It should look like:
export interface paths {
"/api/v1/projects/{project_pk}/segments/": {
get: {
parameters: { path: { project_pk: number } }
responses: { 200: { content: { "application/json": components["schemas"]["PaginatedSegmentList"] } } }
}
}
export interface components {
schemas: {
Segment: { id: number; name: string; rules: SegmentRule[]; ... } => Serializers become schema
SegmentCreate: { name: string; rules: SegmentRule[]; ...}
}
}
// common/types/responses.ts
export type Segment = components['schemas']['Segment']
export type FeatureState = components['schemas']['FeatureState']
export type Project = components['schemas']['Project']
// common/types/requests.ts
export type CreateSegmentBody = components['schemas']['SegmentCreate']