-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgen_all_specs_and_push.sh
More file actions
executable file
·58 lines (41 loc) · 2.22 KB
/
gen_all_specs_and_push.sh
File metadata and controls
executable file
·58 lines (41 loc) · 2.22 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
#!/bin/sh
echo "*** IMPORTANT NOTE ***"
echo "This script assumes you're using the latest version of swagger-codegen 2.3 and have built it locally."
echo "This script will regenerate the JSON definitions ONLY at all levels, also generating the swagger-spec.js updates for swagger-ui."
echo "This script *DOES* COMMIT AND PUSH CODE!"
#capture path to local swagger codegen
#/Users/dwasyluk/Development/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar
read -p "Enter path to swagger-codegen-cli: " CODEGEN
#capture commit message to be used on swagger-ui
read -p "Enter swagger-ui commit message: " SWAGGER_UI_MSG
#capture commit message to be used on syscoin-api
read -p "Enter syscoin-api commit message: " SYSCOIN_API_MSG
#verify before generating
echo "Does this look correct:"
echo "Swagger codegen: ${CODEGEN}"
echo "swagger-ui msg: ${SWAGGER_UI_MSG}"
echo "syscoin-api msg: ${SYSCOIN_API_MSG}"
read -p "Continue? (Y/N): " confirm && [[ ${confirm} == [yY] || ${confirm} == [yY][eE][sS] ]] || exit 1
echo "Generating server JSON spec..."
#create a temp folder to hold generated stuff
mkdir ./generated-temp
java -jar ${CODEGEN} generate -i swagger.yaml -l swagger -o ./generated-temp
#copy the generated .json file to the production code location
cp ./generated-temp/swagger.json ./swagger_generated.json
#generate the server side YAML version of the definitions
java -jar ${CODEGEN} generate -i swagger.yaml -l nodejs-server -o ./generated-temp
cp ./generated-temp/api/swagger.yaml ./server/nodejs/api/swagger.yaml #move the regenerated YAML to the nodjs dir
#remove all temp files
rm -rf ./generated-temp
echo "Server Spec JSON Generation complete."
#copy the new spec to swagger-ui as a JS var
echo "var swaggerSpec = " > ./swagger-ui/dist/swagger-spec.js
cat swagger_generated.json >> ./swagger-ui/dist/swagger-spec.js
#commit and push the changes thus far
( cd swagger-ui && git commit -m "${SWAGGER_UI_MSG}" dist/swagger-spec.js && git push origin dev )
git add swagger-ui
echo "Swagger-ui successfully updated via GIT"
#commit the nodejs server
git commit swagger.yaml swagger_generated.json server/nodejs/api/swagger.yaml swagger-ui -m "${SYSCOIN_API_MSG}"
git push
echo "All spec files regenerated and committed/pushed."