2021-01-07 21:45:32 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eo pipefail
|
|
|
|
|
2022-11-17 11:35:54 +00:00
|
|
|
# install statik on the docker image
|
|
|
|
go install github.com/rakyll/statik
|
|
|
|
|
|
|
|
# create temporary folder to store intermediate results from `buf generate`
|
2021-01-07 21:45:32 +00:00
|
|
|
mkdir -p ./tmp-swagger-gen
|
2022-11-17 11:35:54 +00:00
|
|
|
|
|
|
|
# create swagger files on an individual basis w/ `buf generate` (needed for `swagger-combine`)
|
|
|
|
proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
|
2021-01-07 21:45:32 +00:00
|
|
|
for dir in $proto_dirs; do
|
2022-11-17 11:35:54 +00:00
|
|
|
# generate swagger files (filter query files)
|
|
|
|
query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \))
|
|
|
|
if [[ ! -z "$query_file" ]]; then
|
|
|
|
buf generate --template proto/buf.gen.swagger.yaml $query_file
|
|
|
|
fi
|
2021-01-07 21:45:32 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# combine swagger files
|
|
|
|
# uses nodejs package `swagger-combine`.
|
|
|
|
# all the individual swagger files need to be configured in `config.json` for merging
|
|
|
|
swagger-combine ./client/docs/config.json -o ./client/docs/swagger-ui/swagger.yaml -f yaml --continueOnConflictingPaths true --includeDefinitions true
|
|
|
|
|
|
|
|
# clean swagger files
|
|
|
|
rm -rf ./tmp-swagger-gen
|
2021-04-19 07:10:57 +00:00
|
|
|
|
2022-11-17 11:35:54 +00:00
|
|
|
# generate binary for static server (use -f flag to replace current binary)
|
|
|
|
statik -f -src=./client/docs/swagger-ui -dest=./client/docs
|