-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-api-client.bat
More file actions
102 lines (85 loc) · 2.6 KB
/
generate-api-client.bat
File metadata and controls
102 lines (85 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
@echo off
setlocal
echo ========================================
echo VersionStack API Client Generator
echo ========================================
echo.
:: Configuration
set API_URL=http://localhost/api/openapi.json
set SPEC_FILE=openapi-spec.json
set OUTPUT_DIR=client\src\api\generated
:: Step 1: Start services with docker-compose
echo [1/6] Starting services...
docker-compose up -d --build backend nginx
if %ERRORLEVEL% neq 0 (
echo ERROR: Failed to start services
exit /b 1
)
:: Step 2: Wait for server to be ready (check for HTTP 200)
echo [2/6] Waiting for API to be ready...
set RETRIES=60
:wait_loop
timeout /t 2 /nobreak >nul
:: Use curl to check HTTP status code
for /f %%i in ('curl -s -o nul -w "%%{http_code}" %API_URL%') do set HTTP_CODE=%%i
if "%HTTP_CODE%"=="200" goto server_ready
set /a RETRIES-=1
echo Status: %HTTP_CODE% - Waiting... (%RETRIES% retries left)
if %RETRIES% gtr 0 goto wait_loop
echo ERROR: API did not become ready in time (last status: %HTTP_CODE%)
echo.
echo Showing backend logs:
docker-compose logs --tail=50 backend
docker-compose down
exit /b 1
:server_ready
echo API is ready! (HTTP %HTTP_CODE%)
:: Step 3: Download the OpenAPI spec to a file
echo [3/6] Downloading OpenAPI specification...
curl -s -o %SPEC_FILE% %API_URL%
if %ERRORLEVEL% neq 0 (
echo ERROR: Failed to download OpenAPI spec
docker-compose down
exit /b 1
)
:: Step 4: Create output directory
echo [4/6] Creating output directory...
if exist "%OUTPUT_DIR%" rmdir /s /q "%OUTPUT_DIR%"
mkdir "%OUTPUT_DIR%"
:: Step 5: Generate API client from local file
echo [5/6] Generating TypeScript API client...
call npx --yes @openapitools/openapi-generator-cli generate ^
-i %SPEC_FILE% ^
-g typescript-axios ^
-o %OUTPUT_DIR% ^
--additional-properties=supportsES6=true,npmVersion=9.0.0,typescriptThreePlus=true
set GEN_RESULT=%ERRORLEVEL%
:: Cleanup spec file
del %SPEC_FILE% 2>nul
if %GEN_RESULT% neq 0 (
echo ERROR: API client generation failed
docker-compose down
exit /b 1
)
:: Step 6: Cleanup
echo [6/6] Stopping containers...
docker-compose down
echo.
echo ========================================
echo Done! API client generated at:
echo %OUTPUT_DIR%
echo ========================================
echo.
echo Usage example:
echo.
echo import { AppsApi, AuthenticationApi, Configuration } from './api/generated';
echo.
echo const config = new Configuration({
echo basePath: '/api/v1',
echo accessToken: localStorage.getItem('token') ^|^| undefined,
echo });
echo.
echo const appsApi = new AppsApi(config);
echo const apps = await appsApi.appsList();
echo.
endlocal