Download scripts/generate-types.sh from ag235772/Chimera: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/ag235772/Chimera/resolve/main/scripts/generate-types.sh
- Command line
-
hf download hf://spaces/ag235772/Chimera/scripts/generate-types.sh
-
curl -L -o generate-types.sh https://huggingface.co/spaces/ag235772/Chimera/resolve/main/scripts/generate-types.sh
2.3 kB
| # Generate TypeScript types from OpenAPI spec | |
| # Run this script from the project root: ./scripts/generate-types.sh | |
| set -e | |
| PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | |
| BACKEND_DIR="${PROJECT_ROOT}/chimera-zero-cost/backend" | |
| FRONTEND_DIR="${PROJECT_ROOT}/chimera-zero-cost/frontend" | |
| OUTPUT_DIR="${FRONTEND_DIR}/lib/api-generated" | |
| echo "π Generating TypeScript types from OpenAPI spec..." | |
| echo "Project root: ${PROJECT_ROOT}" | |
| # Check if backend is running, if not start it temporarily | |
| if ! curl -s http://localhost:7860/api/v1/health > /dev/null 2>&1; then | |
| echo "π¦ Starting backend temporarily for OpenAPI spec generation..." | |
| cd "${BACKEND_DIR}" | |
| python -m uvicorn app.main:app --host 0.0.0.0 --port 7860 & | |
| BACKEND_PID=$! | |
| echo "β³ Waiting for backend to start..." | |
| sleep 8 | |
| # Wait for health check | |
| for i in {1..30}; do | |
| if curl -s http://localhost:7860/api/v1/health > /dev/null 2>&1; then | |
| echo "β Backend is ready" | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| else | |
| echo "β Backend already running" | |
| BACKEND_PID="" | |
| fi | |
| # Generate OpenAPI spec | |
| echo "π₯ Fetching OpenAPI spec..." | |
| curl -s http://localhost:7860/openapi.json > "${BACKEND_DIR}/openapi.json" | |
| # Kill temp backend if we started it | |
| if [ -n "${BACKEND_PID}" ]; then | |
| echo "π Stopping temporary backend..." | |
| kill ${BACKEND_PID} 2>/dev/null || true | |
| fi | |
| # Generate TypeScript client | |
| echo "π§ Generating TypeScript client..." | |
| cd "${FRONTEND_DIR}" | |
| # Check if openapi-typescript-codegen is available | |
| if ! npx --version >/dev/null 2>&1; then | |
| echo "β npx not found. Please install Node.js" | |
| exit 1 | |
| fi | |
| npx openapi-typescript-codegen \ | |
| -i "${BACKEND_DIR}/openapi.json" \ | |
| -o "${OUTPUT_DIR}" \ | |
| --client axios \ | |
| --useOptions \ | |
| --exportServices \ | |
| --exportSchemas \ | |
| --httpClient axios \ | |
| --enumType string \ | |
| --name "ChimeraApi" \ | |
| --exportCore true \ | |
| --exportModels true \ | |
| --exportServices true | |
| # Clean up | |
| rm -f "${BACKEND_DIR}/openapi.json" | |
| echo "β TypeScript types generated in ${OUTPUT_DIR}" | |
| echo "" | |
| echo "π Next steps:" | |
| echo " 1. Update frontend/lib/api.ts to import from './api-generated'" | |
| echo " 2. Run 'npm run build' to verify types compile" | |
| echo " 3. Commit the generated types" |