-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·67 lines (55 loc) · 2.25 KB
/
run.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
GENERATOR_IMAGE="openapitools/openapi-generator-cli:v6.6.0"
API="${1-isp}"
ENV="${2-prod}"
OPENAPI_SPEC=""
if [[ "$API" == "isp" ]]; then
OPENAPI_SPEC="http://api.istreamplanet.com/openapi.json"
if [[ $ENV == "stage" ]]; then
OPENAPI_SPEC="http://stage.api.istreamplanet.com/openapi.json"
fi
elif [[ "$API" == "isp-slate" ]]; then
OPENAPI_SPEC="http://api.istreamplanet.com/docs/slates/openapi.json"
if [[ $ENV == "stage" ]]; then
OPENAPI_SPEC="http://stage.api.istreamplanet.com/docs/slates/openapi.json"
fi
elif [[ "$API" == "isp-lifecycle" ]]; then
OPENAPI_SPEC="https://api.istreamplanet.com/state/openapi-3.0.json"
if [[ $ENV == "stage" ]]; then
OPENAPI_SPEC="http://stage.api.istreamplanet.com/state/openapi-3.0.json"
fi
else
>&2 echo "Unrecognized api $API. Valid options are: isp, isp-slate, isp-lifecycle"
>&2 echo ""
exit 1
fi
echo -e "Generating ${API} SDK against ${ENV} (${OPENAPI_SPEC})\n"
SCRIPT_DIR=${PWD}
# Recreate directory to ensure clean build
rm -rf "${API}"
mkdir "${API}"
# Copy required files to directory
cp ./prerequisites/.openapi-generator-ignore ./${API}/.openapi-generator-ignore
cp ./prerequisites/convenience._go ./${API}/convenience.go
cp ./prerequisites/${API}_client._go ./${API}/client.go
# Generate the SDK
docker run --rm \
--user $(id -u) \
-v ${SCRIPT_DIR}:/go-sdk \
"${GENERATOR_IMAGE}" generate \
-g go -c "go-sdk/.generator.yaml" \
-i "${OPENAPI_SPEC}" \
-o go-sdk/${API}
# Logicless templates are dumping extra quotes around enum values, so we've
# added some padding chars and now need to replace the padding + quotes.
# This is preferable to writing an entire huge Java project for a `trim`
# function in the template. I hate this. 🫣
sed -i.bak -E 's/@@@@"([^"]+)"@@@@/\1/g' ./${API}/*.go
# Logicless templates are dumping `example:"null"` on every field, so we've
# got to remove those.
sed -i.bak -E 's/ example:"null"//g' ./${API}/*.go
# Correct an error in the unit tests
sed -i.bak -E 's,"github.com/istreamlabs/go-sdk/isp","github.com/istreamlabs/go-sdk/isp-slate",g' ./isp-slate/**/*.go
sed -i.bak -E 's,"github.com/istreamlabs/go-sdk/isp","github.com/istreamlabs/go-sdk/isp-lifecycle",g' ./isp-lifecycle/**/*.go
# Cleanup all sed backups
find . -name '*.bak' -delete