forked from mailchimp/mailchimp-client-lib-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-sdks
executable file
·112 lines (90 loc) · 3.37 KB
/
generate-sdks
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
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
# adapted from https://github.com/square/connect-api-specification/blob/master/generate-sdks
set -eu
target_language="${1:-}"
target_product="${2:-}"
generate_for_language() {
sdk_name="${2}-${1}"
output_dir="./swagger-out/$2-$1"
config_dir="./swagger-config/$2/$1"
templates_dir="${config_dir}/templates"
# copy .swagger-codegen-ignore template
mkdir -p $output_dir
ignore_template="${templates_dir}/.swagger-codegen-ignore"
if [ -f "${ignore_template}" ]; then
cp $ignore_template "${output_dir}/.swagger-codegen-ignore"
fi
# select codegen build for first pass
# note — for marketing-javascript, we need to first generate the sdks
# on 2.4.7, and subsequently regenerate the APIs only on 2.4.12
# to fix an issue w/ parameters not showing up.
codegen_build="swagger-codegen-cli-2.4.12.jar"
if [ "${sdk_name}" == "marketing-javascript" ]; then
codegen_build="swagger-codegen-cli-2.4.7.jar"
fi
swagger_cmd="java -jar ./codegen/${codegen_build}"
# generate client library
$swagger_cmd generate \
--input-spec "./spec/$2.json" \
--lang "$1" \
--config "${config_dir}/config.json" \
--template-dir $templates_dir \
--output $output_dir \
-DapiTests=false
# handle marketing-javascript
if [ "${sdk_name}" == "marketing-javascript" ]; then
codegen_build="swagger-codegen-cli-2.4.12.jar"
swagger_cmd="java -jar ./codegen/${codegen_build}"
$swagger_cmd generate \
--input-spec "./spec/$2.json" \
--lang "$1" \
--config "${config_dir}/config.json" \
--template-dir $templates_dir \
--output $output_dir \
-DapiTests=false \
-Dapis
fi
# clean-up SDK output
rm -rf "${output_dir}/.swagger-codegen"
rm -rf "${output_dir}/.swagger-codegen-ignore"
output_root="${output_dir}"
if [ "${sdk_name}" == "marketing-php" ]; then
output_root="${output_root}/MailchimpMarketing"
rm -rf "${output_root}/lib/Model"
# Copy additional files
cp "${templates_dir}/ApiClient.php" "${output_root}/lib/ApiClient.php"
fi
if [ "${sdk_name}" == "transactional-php" ]; then
output_root="${output_root}/MailchimpTransactional"
rm -rf "${output_root}/lib/Model"
# Copy additional files
cp "${templates_dir}/ApiClient.php" "${output_root}/lib/ApiClient.php"
fi
if [ "${sdk_name}" == "marketing-python" ]; then
rm -rf "${output_root}/mailchimp_marketing/models"
fi
# add additional files to client root dir
cp ./LICENSE "${output_root}"
cp ./CHANGELOG.md "${output_root}/CHANGELOG.md"
rm -f -r "${output_root}/.github"
mkdir "${output_root}/.github"
cp ./sdk_pull_request_template.md "${output_root}/.github/PULL_REQUEST_TEMPLATE.md"
}
if [ -n "$target_language" ] && [ -n "$target_product" ]
then
generate_for_language "$target_language" "$target_product"
elif [ -n "$target_language" ]
then
generate_for_language "$target_language" "transactional"
generate_for_language "$target_language" "marketing"
else
products=$(ls swagger-config)
for prod in $products
do
languages=$(ls "swagger-config/${prod}")
for lang in $languages
do
generate_for_language "$lang" "${prod}"
done
done
fi