diff --git a/backend/scripts/generate_openapi.py b/backend/scripts/generate_openapi.py new file mode 100644 index 0000000..4a26f82 --- /dev/null +++ b/backend/scripts/generate_openapi.py @@ -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() diff --git a/frontend/src/lib/api/client.gen.ts b/frontend/src/lib/api/client.gen.ts index 49f87f3..cab3c70 100644 --- a/frontend/src/lib/api/client.gen.ts +++ b/frontend/src/lib/api/client.gen.ts @@ -13,4 +13,4 @@ import type { ClientOptions as ClientOptions2 } from './types.gen'; */ export type CreateClientConfig = (override?: Config) => Config & T>; -export const client = createClient(createConfig({ baseUrl: 'http://localhost:8000' })); +export const client = createClient(createConfig()); diff --git a/frontend/src/lib/api/types.gen.ts b/frontend/src/lib/api/types.gen.ts index 5f07c92..e6d7082 100644 --- a/frontend/src/lib/api/types.gen.ts +++ b/frontend/src/lib/api/types.gen.ts @@ -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 & {}); }; /** diff --git a/justfile b/justfile index 7b77f62..1853c41 100644 --- a/justfile +++ b/justfile @@ -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 ---