-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·66 lines (57 loc) · 2.27 KB
/
generate.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
#!/usr/bin/env bash
GENERATOR_IMAGE=registry.gitlab.com/tokend/openapi-go-generator:c59241b52b0e37bbbeb02a214ab5bfd07627aabc
[[ ! -x "$(command -v go 2>/dev/null)" ]] && echo "go is not installed" && exit 1
GENERATED="$PWD/resources"
OPENAPI_DIR="$PWD/docs/web_deploy"
PACKAGE_NAME=resources
function printHelp {
echo "usage: ./generate.sh [<flags>]
script to generate resources for api
Flags:
--package PACKAGE package name of generated stuff (first line of file, by default is 'resources')
--image IMAGE name of generator docker image (by default is openapi-generator)
-h, --help show this help
-p, --path-to-generate PATH path to put generated things (by default is resources)
-i, --input OPENAPI_DIR path to dir where openapi.yaml is stored (by default docs/web_deploy)"
}
function parseArgs {
while [[ -n "$1" ]]
do
case "$1" in
-h | --help)
printHelp && exit 0
;;
-p | --path-to-generate) shift
[[ ! -d $1 ]] && echo "path $1 does not exist or not a dir" && exit 1
GENERATED=$1
;;
--package) shift
[[ -z "$1" ]] && echo "package name not specified" && exit 1
PACKAGE_NAME=$1
;;
-i | --input) shift
[[ ! -f "$1/openapi.yaml" ]] && echo "file openapi.yaml does not exist in $1 or not a file" && exit 1
OPENAPI_DIR=$1
;;
--image) shift
[[ "$(docker images -q $1)" == "" ]] && echo "image $1 does not exist locally" && exit 1
GENERATOR_IMAGE=$1
;;
esac
shift
done
}
function generate {
(cd docs && npm run build)
if [[ ! -d "${GENERATED}" ]]; then
mkdir -p "${GENERATED}"
else
rm -rf "${GENERATED}"/*
fi
docker run --rm -v "${OPENAPI_DIR}":/openapi -v "${GENERATED}":/generated "${GENERATOR_IMAGE}" \
generate -pkg "${PACKAGE_NAME}" --raw-formats-as-types --meta-for-lists
goimports -w ${GENERATED}
}
parseArgs "$@"
#echo ${OPENAPI_DIR} ${GENERATED} ${GENERATOR_IMAGE} ${PACKAGE_NAME}
generate