-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-api.sh
executable file
·45 lines (28 loc) · 932 Bytes
/
gen-api.sh
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
#!/usr/bin/env bash
function isUrlAvail() {
q="$(curl $1 -o /dev/null -w '%{http_code}\n' -s)"
if [ "$q" == "200" ]; then
echo 1
else
echo 0
fi
}
export NODE_OPTIONS=--use-openssl-ca
exdir=$(dirname $(readlink -f "$BASH_SOURCE"))
source "$exdir"/src/app/frontend/.env.development
app_api_spec_url="https://$VITE_SERVERNAME/swagger/v1/swagger.json"
#-------- app (typescript)
app_api_avail="$(isUrlAvail "$app_api_spec_url")"
if [ "$app_api_avail" == "1" ]; then
APIFLD="$exdir"/src/app/frontend/api
rm -fr "$APIFLD"
mkdir "$APIFLD"
cd "$exdir"
npx @openapitools/openapi-generator-cli generate \
-i "$app_api_spec_url" \
-g typescript-axios \
-o "$APIFLD"
app_api_generated="1"
fi
#=================================================
if [ "$app_api_generated" != "1" ]; then echo "(W): skip typescript app api from $app_api_spec_url"; fi