Skip to content

Commit 5f1bf7a

Browse files
fix: openapi-ts
1 parent 841e175 commit 5f1bf7a

8 files changed

Lines changed: 677 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,40 @@ jobs:
1010
web:
1111
name: Web
1212
runs-on: ubuntu-latest
13-
defaults:
14-
run:
15-
working-directory: apps/web
1613

1714
steps:
1815
- uses: actions/checkout@v4
1916

17+
- uses: astral-sh/setup-uv@v5
18+
with:
19+
enable-cache: true
20+
cache-dependency-glob: apps/api/uv.lock
21+
22+
- name: Export OpenAPI schema
23+
working-directory: apps/api
24+
run: uv sync --frozen && uv run python export_schema.py
25+
2026
- uses: actions/setup-node@v4
2127
with:
2228
node-version: 22
2329
cache: npm
2430
cache-dependency-path: apps/web/package-lock.json
2531

26-
- run: npm ci
32+
- name: Install dependencies
33+
working-directory: apps/web
34+
run: npm ci
2735

28-
- run: npm run lint
36+
- name: Generate API client
37+
working-directory: apps/web
38+
run: npm run codegen
2939

30-
- run: npm run build
40+
- name: Lint
41+
working-directory: apps/web
42+
run: npm run lint
43+
44+
- name: Build
45+
working-directory: apps/web
46+
run: npm run build
3147

3248
api:
3349
name: API

apps/api/export_schema.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Export the OpenAPI schema to a JSON file for client codegen."""
2+
3+
import json
4+
from pathlib import Path
5+
6+
from main import app
7+
8+
schema = app.openapi()
9+
out = Path(__file__).resolve().parent.parent.parent / "docs" / "schema" / "openapi.json"
10+
out.parent.mkdir(parents=True, exist_ok=True)
11+
out.write_text(json.dumps(schema, indent=2) + "\n")
12+
print(f"Schema written to {out}")

apps/web/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ yarn-error.log*
3939
# typescript
4040
*.tsbuildinfo
4141
next-env.d.ts
42+
43+
# generated api client
44+
/src/api

apps/web/openapi-ts.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "@hey-api/openapi-ts";
2+
3+
export default defineConfig({
4+
input: "../../docs/schema/openapi.json",
5+
output: {
6+
path: "src/api",
7+
format: "prettier",
8+
},
9+
plugins: ["@hey-api/client-fetch"],
10+
});

0 commit comments

Comments
 (0)