-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate-api.sh
executable file
·71 lines (62 loc) · 1.9 KB
/
generate-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
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
#!/bin/bash
echo "Generating UAPI from OpenAPI spec"
# Check if argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <openapi-spec-file>"
exit 1
fi
# Check if openapi-generator is installed
if ! command -v openapi-generator &> /dev/null
then
echo "openapi-generator could not be found"
echo "Please install openapi-generator-cli"
echo "https://openapi-generator.tech/docs/installation"
exit
fi
# Clearing old generated files
echo "clearing old generated files"
find ./api -name "*.go" -type f -delete
# Generate UAPI
openapi-generator generate \
-i $1 \
-g go \
-o ./api \
--package-name api \
--git-user-id "yohan460" \
--git-repo-id "go-jamf-api" \
--global-property=apiTests=false \
--type-mappings=integer=int64 \
--additional-properties=packageName=api,enumClassPrefix=true,structPrefix=true,generateInterfaces=true,isGoSubmodule=true \
--skip-validate-spec
returncode=$?
echo "Return code: $returncode"
if [[ "${returncode}" != "0" ]]; then
echo "Failed to generate UAPI"
exit 1
fi
# Perform cleanup
rm ./api/git_push.sh
rm ./api/go.mod
rm ./api/go.sum
rm ./api/.gitignore
# Patch the defaultValue generation
echo "Patching defaultValue generation"
find ./api -type f -name "*.go" -exec sed -i '' 's/var defaultValue \[\]\(.*\) = \[\(.*\)\]/defaultValue := []\1{\2}/g' {} \;
returncode=$?
if [[ "${returncode}" != "0" ]]; then
echo "Failed to patch defaultValue generation"
exit 1
fi
# Patch the generic object generation
echo "Patching generic object generation"
find ./api -type f -name "*.go" -exec sed -i '' 's/MapmapOfStringinterface[\{][\}]/Generic/g' {} \;;
returncode=$?
if [[ "${returncode}" != "0" ]]; then
echo "Failed to patch generic object generation"
exit 1
fi
# Patch reserved go file name suffixes
echo "Patching reserved go file name suffixes"
for file in api/*ios.go; do
mv "$file" "${file%ios.go}ios_.go"
done