cleaner typescript client generation

This commit is contained in:
2026-04-30 15:10:51 -04:00
parent ced59b9379
commit 90a1de3f05
4 changed files with 28 additions and 5 deletions
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
"""Dump the FastAPI OpenAPI schema to a JSON file without starting the server."""
import json
import sys
from pathlib import Path
from app.main import app
# Add the backend directory to the path so we can import app.main
backend_dir = Path(__file__).parent.parent
sys.path.insert(0, str(backend_dir))
def main():
output_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("openapi.json")
schema = app.openapi()
output_path.write_text(json.dumps(schema, indent=2))
print(f"OpenAPI schema written to {output_path}")
if __name__ == "__main__":
main()
+1 -1
View File
@@ -13,4 +13,4 @@ import type { ClientOptions as ClientOptions2 } from './types.gen';
*/
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
export const client = createClient(createConfig<ClientOptions2>({ baseUrl: 'http://localhost:8000' }));
export const client = createClient(createConfig<ClientOptions2>());
+1 -1
View File
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts
export type ClientOptions = {
baseUrl: 'http://localhost:8000' | (string & {});
baseUrl: `${string}://${string}` | (string & {});
};
/**
+3 -3
View File
@@ -63,10 +63,10 @@ db-migrate message:
# --- Code Generation ---
# Generate the TypeScript API client from the FastAPI OpenAPI spec
generate-client:
generate-client: db-upgrade
@echo "Generating TypeScript API client..."
# Ensure backend is running first: `just backend`
cd frontend && npx @hey-api/openapi-ts -i http://localhost:8000/openapi.json -o src/lib/api -c @hey-api/client-fetch
@cd backend && uv run python scripts/generate_openapi.py /tmp/tapehoard_openapi.json
@cd frontend && npx @hey-api/openapi-ts -i /tmp/tapehoard_openapi.json -o src/lib/api -c @hey-api/client-fetch
# --- Docker ---