-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·59 lines (50 loc) · 2.13 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
#!/usr/bin/env bash
GENERATOR_IMAGE=registry.gitlab.com/tokend/openapi-go-generator:69f004b58152c83f007b593cc13e94b81d7200da
GENERATED="${GOPATH}/src/gitlab.com/MarkCherepovskyi/KeyStorage/resources"
OPENAPI_DIR="${GOPATH}/src/gitlab.com/MarkCherepovskyi/KeyStorage/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)
docker run -v "${OPENAPI_DIR}":/openapi -v "${GENERATED}":/generated "${GENERATOR_IMAGE}" generate -pkg "${PACKAGE_NAME}" --raw-formats-as-types
goimports -w ${GENERATED}
}
parseArgs "$@"
#echo ${OPENAPI_DIR} ${GENERATED} ${GENERATOR_IMAGE} ${PACKAGE_NAME}
generate