Skip to content

Auto-generate Typescript types from OpenAPI schema #6627

@Zaimwa9

Description

@Zaimwa9

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/responses and common/types/requests can 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']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions