cleaner typescript client generation
This commit is contained in:
@@ -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()
|
||||
@@ -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,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 & {});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 ---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user