-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerate-sdk.sh
More file actions
executable file
·101 lines (89 loc) · 3.12 KB
/
generate-sdk.sh
File metadata and controls
executable file
·101 lines (89 loc) · 3.12 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
#!/bin/bash
# This script clones the SDK repo and updates it with the generated API modules
# Pre-requisites: Java, goimports, Go
set -eo pipefail
# Parameters
GIT_HOST=$1
GIT_USER_ID=$2
GIT_REPO_ID=$3
SDK_REPO_URL=$4
LANGUAGE=$5
SDK_BRANCH=$6
# Global variables
ROOT_DIR=$(git rev-parse --show-toplevel)
GENERATOR_PATH="${ROOT_DIR}/scripts/bin"
LANGUAGE_GENERATORS_FOLDER_PATH="${ROOT_DIR}/scripts/generate-sdk/languages/"
# Renovate: datasource=github-tags depName=OpenAPITools/openapi-generator versioning=semver
# Check parameters and set defaults if not provided
if [[ -z ${GIT_HOST} ]]; then
echo "GIT_HOST not specified, default will be used."
GIT_HOST="github.com"
fi
if [[ -z ${GIT_USER_ID} ]]; then
echo "GIT_USER_ID not specified, default will be used."
GIT_USER_ID="stackitcloud"
fi
if [[ -z ${LANGUAGE} ]]; then
echo "LANGUAGE not specified, default will be used."
LANGUAGE="go"
fi
if [[ -z ${SDK_BRANCH} ]]; then
echo "SDK_BRANCH not specified, main branch will be used."
SDK_BRANCH=main
fi
# Check dependencies
if type -p java >/dev/null; then
:
else
echo "Java not installed, unable to proceed."
exit 1
fi
if [ ! -d ${ROOT_DIR}/oas ]; then
echo "\"oas\" folder not found in root. Please add it manually or run \"make download-oas\"."
exit 1
fi
# Choose generator version depending on the language
# Renovate: datasource=github-tags depName=OpenAPITools/openapi-generator versioning=semver
case "${LANGUAGE}" in
go)
GENERATOR_VERSION="v6.6.0" # There are issues with GO SDK generation in version v7
;;
python)
# Renovate: datasource=github-tags depName=OpenAPITools/openapi-generator versioning=semver
GENERATOR_VERSION="v7.14.0"
;;
*)
echo "SDK language not supported."
exit 1
;;
esac
GENERATOR_VERSION_NUMBER="${GENERATOR_VERSION:1}"
# Download OpenAPI generator if not already downloaded
jar_path="${GENERATOR_PATH}/openapi-generator-cli.jar"
if [ -e ${jar_path} ] && [ $(java -jar ${jar_path} version) == ${GENERATOR_VERSION_NUMBER} ]; then
:
else
echo "Downloading OpenAPI generator (version ${GENERATOR_VERSION})..."
mkdir -p ${GENERATOR_PATH}
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${GENERATOR_VERSION_NUMBER}/openapi-generator-cli-${GENERATOR_VERSION_NUMBER}.jar -O ${jar_path} --quiet
echo "Download done."
fi
# Generate SDK for the specified language
case "${LANGUAGE}" in
go)
echo -e "\n>> Generating the Go SDK..."
source ${LANGUAGE_GENERATORS_FOLDER_PATH}/${LANGUAGE}.sh
# Usage: generate_go_sdk GENERATOR_PATH GIT_HOST GIT_USER_ID [GIT_REPO_ID] [SDK_REPO_URL]
generate_go_sdk "${jar_path}" "${GIT_HOST}" "${GIT_USER_ID}" "${GIT_REPO_ID}" "${SDK_REPO_URL}" "${SDK_BRANCH}"
;;
python)
echo -e "\n>> Generating the Python SDK..."
source ${LANGUAGE_GENERATORS_FOLDER_PATH}/${LANGUAGE}.sh
# Usage: generate_python_sdk GENERATOR_PATH GIT_HOST GIT_USER_ID [GIT_REPO_ID] [SDK_REPO_URL] [SDK_BRANCH]
generate_python_sdk "${jar_path}" "${GIT_HOST}" "${GIT_USER_ID}" "${GIT_REPO_ID}" "${SDK_REPO_URL}" "${SDK_BRANCH}"
;;
*)
echo "! SDK language not supported."
exit 1
;;
esac