Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
feature: install the swagger if it has not been installed
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed Aug 2, 2019
1 parent 0da3300 commit 6f03ff7
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions hack/generate-swagger-models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,60 @@ set -o nounset
set -o errexit
set -o pipefail

# Get the absolute path of this file
DIR="$( cd "$( dirname "$0" )" && pwd )"

# Here is details of the swagger binary we use.
# $ swagger version
# version: 0.19.0
SWAGGER_VERSION=v0.19.0

. ./env.sh

# swagger::check_version checks the command and the version.
swagger::check_version() {
local has_installed version

has_installed="$(command -v swagger || echo false)"
if [[ "${has_installed}" = "false" ]]; then
echo false
return
fi

version="$(swagger version | head -n 1 | cut -d " " -f 2)"
if [[ "${SWAGGER_VERSION}" != "${version}" ]]; then
echo false
return
fi
echo true
}

# swagger::install installs the swagger binary.
swagger::install() {
has_installed="$(swagger::check_version)"
if [[ "${has_installed}" = "true" ]]; then
echo "swagger-${SWAGGER_VERSION} has been installed."
return
fi

echo ">>>> start to install swagger-${SWAGGER_VERSION} <<<<"

local url
url="https://github.com/go-swagger/go-swagger/releases/download/${SWAGGER_VERSION}/swagger_${GOOS}_${GOARCH}"
wget --quiet -O /usr/local/bin/swagger "${url}"
chmod +x /usr/local/bin/swagger
}

# swagger::generate generate the code by go-swagger.
swagger::generate() {
swagger generate model -f "$DIR/../apis/swagger.yml" -t "$DIR/../apis" -m types
}

main() {
swagger::install
swagger::generate
}

main

# Get the absolute path of this file
DIR="$( cd "$( dirname "$0" )" && pwd )"

swagger generate model -f "$DIR/../apis/swagger.yml" -t "$DIR/../apis" -m types

0 comments on commit 6f03ff7

Please sign in to comment.