85 lines
3.1 KiB
Bash
Executable File
85 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Comprehensive script to generate TypeScript types from FastAPI OpenAPI schema.
|
|
# This script coordinates between the server and frontend containers to:
|
|
# 1. Ensure the server is running and ready
|
|
# 2. Generate OpenAPI schema from the running FastAPI server
|
|
# 3. Generate TypeScript types from the schema
|
|
# 4. Ensure frontend container dependencies are installed
|
|
|
|
set -e
|
|
|
|
echo "🚀 Starting OpenAPI TypeScript generation process..."
|
|
|
|
# Change to the project directory
|
|
cd "$(dirname "$0")"
|
|
|
|
echo "📋 Step 1: Ensuring server container is running and ready..."
|
|
docker compose up -d server
|
|
|
|
# Load environment variables
|
|
source .env
|
|
|
|
# Build health check URL from environment variables
|
|
HEALTH_URL="${PUBLIC_SERVER_URL}${PUBLIC_URL}/api/system/health"
|
|
echo "🔍 Using health check URL: $HEALTH_URL"
|
|
|
|
# Wait for server to be ready
|
|
echo "⏳ Waiting for server to be ready..."
|
|
max_retries=30
|
|
retry_count=0
|
|
while [ $retry_count -lt $max_retries ]; do
|
|
# Use curl with SSL verification disabled for self-signed certs
|
|
if docker compose exec server curl -f -k "$HEALTH_URL" >/dev/null 2>&1; then
|
|
echo "✅ Server is ready!"
|
|
break
|
|
fi
|
|
retry_count=$((retry_count + 1))
|
|
echo " Attempt $retry_count/$max_retries - Server not ready yet, waiting..."
|
|
sleep 2
|
|
done
|
|
|
|
if [ $retry_count -eq $max_retries ]; then
|
|
echo "❌ Server failed to become ready within timeout"
|
|
echo "📋 Server logs:"
|
|
docker compose logs server --tail=20
|
|
exit 1
|
|
fi
|
|
|
|
echo "📋 Step 2: Generating OpenAPI schema from running FastAPI server..."
|
|
docker compose exec server uv run python3 generate_schema_simple.py
|
|
docker compose cp server:/client/openapi-schema.json ./client/openapi-schema.json
|
|
|
|
echo "📋 Step 3: Ensuring frontend container is running..."
|
|
docker compose up -d client
|
|
|
|
echo "📋 Step 4: Installing/updating frontend dependencies..."
|
|
docker compose exec client npm install --legacy-peer-deps
|
|
|
|
echo "📋 Step 5: Generating TypeScript types from OpenAPI schema..."
|
|
docker compose exec client npx openapi-typescript openapi-schema.json -o src/api-types.ts
|
|
|
|
echo "📋 Step 6: Automatically updating API client and evolution checker..."
|
|
docker compose exec client node update-api-client.js
|
|
|
|
echo "📋 Step 7: Running TypeScript type checking..."
|
|
docker compose exec client npm run type-check
|
|
|
|
echo "📋 Step 8: Testing dynamic path usage..."
|
|
docker compose exec client npm run test-dynamic-paths
|
|
|
|
echo "📋 Step 9: Running API evolution check..."
|
|
docker compose exec client node check-api-evolution.js
|
|
|
|
echo "✅ TypeScript generation and API client update complete!"
|
|
echo "📄 Generated files:"
|
|
echo " - client/openapi-schema.json (OpenAPI schema)"
|
|
echo " - client/src/api-types.ts (TypeScript types)"
|
|
echo ""
|
|
echo "📄 Updated files:"
|
|
echo " - client/src/api-client.ts (automatically updated with new endpoints)"
|
|
echo " - client/src/api-evolution-checker.ts (updated known endpoints)"
|
|
echo ""
|
|
echo "💡 Usage in your React components:"
|
|
echo " import { apiClient, adminApi, healthApi } from './api-client';"
|
|
echo " import type { LobbyModel, SessionModel } from './api-client';"
|