Flagsmith / Flagsmith/flagsmith

Auto-generate Typescript types from OpenAPI schema

Open
#6,627 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

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/responses` and `common/types/requests` can start consuming the types
- [ ] Bonus: create the [claude command](https://github.com/Flagsmith/flagsmith/pull/6486/changes#r2667886590)

Typescript generated file should look like:

```ts
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[]; ...}
}
}
```

```ts
// 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']
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.