@@ -9,31 +9,31 @@ ALLOW_ALPHA=$3
99OAS_API_VERSIONS=$4
1010
1111if [[ -z ${OAS_REPO_NAME} ]]; then
12- echo " Repo name is empty, default public OAS repo name will be used."
13- OAS_REPO_NAME=" stackit-api-specifications"
12+ echo " Repo name is empty, default public OAS repo name will be used."
13+ OAS_REPO_NAME=" stackit-api-specifications"
1414fi
1515
1616if [[ ! ${OAS_REPO} || -d ${OAS_REPO} ]]; then
17- echo " Repo argument is empty, default public OAS repo will be used."
18- OAS_REPO=" https://github.com/stackitcloud/${OAS_REPO_NAME} .git"
17+ echo " Repo argument is empty, default public OAS repo will be used."
18+ OAS_REPO=" https://github.com/stackitcloud/${OAS_REPO_NAME} .git"
1919fi
2020
2121if [[ -z ${OAS_API_VERSIONS} ]]; then
22- echo " No API version passed, using ${ROOT_DIR} /api-versions-lock.json"
23- OAS_API_VERSIONS=" ${ROOT_DIR} /api-versions-lock.json"
22+ echo " No API version passed, using ${ROOT_DIR} /api-versions-lock.json"
23+ OAS_API_VERSIONS=" ${ROOT_DIR} /api-versions-lock.json"
2424fi
2525
2626# Create temp directory to clone OAS repo
2727work_dir=$( mktemp -d)
2828if [[ ! ${work_dir} || -d {work_dir} ]]; then
29- echo " ! Unable to create temporary directory"
30- exit 1
29+ echo " ! Unable to create temporary directory"
30+ exit 1
3131fi
3232trap " rm -rf ${work_dir} " EXIT # Delete temp directory on exit
3333
3434if [ -d " ${ROOT_DIR} /oas" ]; then
35- echo " OAS folder found. Will be removed"
36- rm -r " ${ROOT_DIR} /oas"
35+ echo " OAS folder found. Will be removed"
36+ rm -r " ${ROOT_DIR} /oas"
3737fi
3838
3939# Move oas to root level
@@ -43,80 +43,81 @@ git clone "${OAS_REPO}" --quiet
4343
4444for service_dir in ${work_dir} /${OAS_REPO_NAME} /services/* ; do
4545
46- max_version_dir=" "
47- max_version=-1
48- service=$( basename " $service_dir " )
46+ max_version_dir=" "
47+ max_version=-1
48+ service=$( basename " $service_dir " )
4949
50- apiVersion=$( jq -r -f <( cat << EOF
50+ apiVersion=$( jq -r -f <(
51+ cat << EOF
5152if has("${service} ") then ."${service} " else "main" end
5253EOF
53- ) ${OAS_API_VERSIONS} )
54- if [ " ${apiVersion} " != " main" ]; then
55- echo " Using ${apiVersion} for ${service} "
56- fi
57- cd ${work_dir} /${OAS_REPO_NAME} > /dev/null
58- git checkout -q $apiVersion || (echo " version ${apiVersion} does not exist, using main instead" && git checkout -q main)
59- cd - > /dev/null
60-
61- # Prioritize GA over Beta over Alpha versions
62- # GA priority =999, Beta priority >=500, Alpha priority <500 and >=1
63- max_version_priority=1
64-
65- for dir in ${service_dir} /* ; do
66- version=$( basename " $dir " )
67- current_version_priority=999
68- # Check if directory name starts with 'v'
69- if [[ ${version} == v* ]]; then
70- # Remove the 'v' prefix
71- version=${version# v}
72- # Check if version is alpha
73- if [[ ${version} == * alpha* ]]; then
74- # To support initial integrations of the IaaS API in an Alpha state, we will temporarily use it to generate an IaaS Alpha SDK module
75- # This check can be removed once the IaaS API moves all endpoints to Beta
76- if [[ ${service} == " iaas" ]]; then
77- mv -f ${dir} /* .json ${ROOT_DIR} /oas/iaasalpha.json
78- continue
79- fi
80- if [[ ${ALLOW_ALPHA} != " true" ]]; then
81- continue
82- fi
83-
84- current_version_priority=1
85-
86- # check if the version is e.g. "v2alpha2"
87- if [[ ${version} =~ alpha([0-9]+)$ ]]; then
88- alphaVersion=" ${BASH_REMATCH[1]} "
89- current_version_priority=$(( alphaVersion+ current_version_priority))
90- fi
91-
92- # Remove 'alpha' suffix
93- version=${version% alpha* }
94- fi
95- # Check if version is beta
96- if [[ ${version} == * beta* ]]; then
97- current_version_priority=500
98-
99- # check if the version is e.g. "v2beta2"
100- if [[ ${version} =~ beta([0-9]+)$ ]]; then
101- betaVersion=" ${BASH_REMATCH[1]} "
102- current_version_priority=$(( betaVersion+ current_version_priority))
103- fi
104-
105- # Remove 'beta' suffix
106- version=${version% beta* }
107- fi
108- # Compare versions, prioritizing GA over Beta over Alpha versions
109- if [[ $(( version )) -gt ${max_version} || ( $(( version)) -eq ${max_version} && ${current_version_priority} -gt ${max_version_priority} ) ]]; then
110- max_version=$(( version))
111- max_version_dir=${dir}
112- max_version_priority=${current_version_priority}
113- fi
114- fi
115- done
116-
117- if [[ -z ${max_version_dir} ]]; then
118- echo " No elegible OAS found for ${service_dir} "
119- continue
120- fi
121- mv -f ${max_version_dir} /* .json ${ROOT_DIR} /oas
54+ ) ${OAS_API_VERSIONS} )
55+ if [ " ${apiVersion} " != " main" ]; then
56+ echo " Using ${apiVersion} for ${service} "
57+ fi
58+ cd ${work_dir} /${OAS_REPO_NAME} > /dev/null
59+ git checkout -q $apiVersion || (echo " version ${apiVersion} does not exist, using main instead" && git checkout -q main)
60+ cd - > /dev/null
61+
62+ # Prioritize GA over Beta over Alpha versions
63+ # GA priority =999, Beta priority >=500, Alpha priority <500 and >=1
64+ max_version_priority=1
65+
66+ for dir in ${service_dir} /* ; do
67+ version=$( basename " $dir " )
68+ current_version_priority=999
69+ # Check if directory name starts with 'v'
70+ if [[ ${version} == v* ]]; then
71+ # Remove the 'v' prefix
72+ version=${version# v}
73+ # Check if version is alpha
74+ if [[ ${version} == * alpha* ]]; then
75+ # To support initial integrations of the IaaS API in an Alpha state, we will temporarily use it to generate an IaaS Alpha SDK module
76+ # This check can be removed once the IaaS API moves all endpoints to Beta
77+ if [[ ${service} == " iaas" ]]; then
78+ mv -f ${dir} /* .json ${ROOT_DIR} /oas/iaasalpha.json
79+ continue
80+ fi
81+ if [[ ${ALLOW_ALPHA} != " true" ]]; then
82+ continue
83+ fi
84+
85+ current_version_priority=1
86+
87+ # check if the version is e.g. "v2alpha2"
88+ if [[ ${version} =~ alpha([0-9]+)$ ]]; then
89+ alphaVersion=" ${BASH_REMATCH[1]} "
90+ current_version_priority=$(( alphaVersion + current_version_priority))
91+ fi
92+
93+ # Remove 'alpha' suffix
94+ version=${version% alpha* }
95+ fi
96+ # Check if version is beta
97+ if [[ ${version} == * beta* ]]; then
98+ current_version_priority=500
99+
100+ # check if the version is e.g. "v2beta2"
101+ if [[ ${version} =~ beta([0-9]+)$ ]]; then
102+ betaVersion=" ${BASH_REMATCH[1]} "
103+ current_version_priority=$(( betaVersion + current_version_priority))
104+ fi
105+
106+ # Remove 'beta' suffix
107+ version=${version% beta* }
108+ fi
109+ # Compare versions, prioritizing GA over Beta over Alpha versions
110+ if [[ ( $(( version)) -ge ${max_version} && ${current_version_priority} -ge ${max_version_priority} ) ]]; then
111+ max_version=$(( version))
112+ max_version_dir=${dir}
113+ max_version_priority=${current_version_priority}
114+ fi
115+ fi
116+ done
117+
118+ if [[ -z ${max_version_dir} ]]; then
119+ echo " No elegible OAS found for ${service_dir} "
120+ continue
121+ fi
122+ mv -f ${max_version_dir} /* .json ${ROOT_DIR} /oas
122123done
0 commit comments