Files
fast-next-template/frontend/scripts/generate-api-client.sh
Felipe Cardoso 19ecd04a41 Add foundational API client, UI components, and state management setup
- Created `generate-api-client.sh` for OpenAPI-based TypeScript client generation.
- Added `src/lib/api` with Axios-based API client, error handling utilities, and placeholder for generated types.
- Implemented Zustand-based `authStore` for user authentication and token management.
- Integrated reusable UI components (e.g., `Dialog`, `Select`, `Textarea`, `Sheet`, `Separator`, `Checkbox`) using Radix UI and utility functions.
- Established groundwork for client-server integration, state management, and modular UI development.
2025-10-31 21:46:03 +01:00

75 lines
2.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Configuration
API_BASE_URL="${NEXT_PUBLIC_API_BASE_URL:-http://localhost:8000}"
API_URL="$API_BASE_URL/api/v1/openapi.json"
OUTPUT_DIR="./src/lib/api/generated"
echo -e "${YELLOW}🔧 API Client Generation${NC}"
echo -e "${YELLOW}========================${NC}"
echo ""
echo -e "API URL: ${GREEN}$API_URL${NC}"
echo -e "Output Directory: ${GREEN}$OUTPUT_DIR${NC}"
echo ""
# Check if backend is running
echo -e "${YELLOW}📡 Checking backend availability...${NC}"
if curl -s -f "$API_BASE_URL/health" > /dev/null 2>&1 || curl -s -f "$API_URL" > /dev/null 2>&1; then
echo -e "${GREEN}✓ Backend is reachable${NC}"
else
echo -e "${RED}✗ Backend is not reachable at $API_BASE_URL${NC}"
echo -e "${YELLOW} Make sure the backend is running:${NC}"
echo -e " cd ../backend && uvicorn app.main:app --reload"
exit 1
fi
# Fetch OpenAPI spec
echo -e "${YELLOW}📥 Fetching OpenAPI specification...${NC}"
if ! curl -s -f "$API_URL" -o /tmp/openapi.json; then
echo -e "${RED}✗ Failed to fetch OpenAPI spec from $API_URL${NC}"
exit 1
fi
echo -e "${GREEN}✓ OpenAPI spec fetched successfully${NC}"
# Create output directory
echo -e "${YELLOW}📁 Creating output directory...${NC}"
mkdir -p "$OUTPUT_DIR"
echo -e "${GREEN}✓ Output directory ready${NC}"
# Generate TypeScript client
echo -e "${YELLOW}⚙️ Generating TypeScript API client...${NC}"
if npx @hey-api/openapi-ts \
--input /tmp/openapi.json \
--output "$OUTPUT_DIR" \
--client axios \
--name ApiClient \
--useOptions true \
--exportSchemas true; then
echo -e "${GREEN}✓ API client generated successfully${NC}"
else
echo -e "${RED}✗ Failed to generate API client${NC}"
exit 1
fi
# Clean up
rm /tmp/openapi.json
echo ""
echo -e "${GREEN}✅ API client generation complete!${NC}"
echo -e "${YELLOW}📝 Generated files:${NC}"
echo -e " - $OUTPUT_DIR/index.ts"
echo -e " - $OUTPUT_DIR/schemas/"
echo -e " - $OUTPUT_DIR/services/"
echo ""
echo -e "${YELLOW}💡 Next steps:${NC}"
echo -e " Import in your code:"
echo -e " ${GREEN}import { ApiClient } from '@/lib/api/generated';${NC}"
echo ""