Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jimschubert
Last active July 7, 2018 04:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimschubert/ce241b0c78140e364f46914ef8ec4103 to your computer and use it in GitHub Desktop.
Save jimschubert/ce241b0c78140e364f46914ef8ec4103 to your computer and use it in GitHub Desktop.
Script for running openapi-generator-cli
#!/usr/bin/env bash
####
# Save as openapi-generator-cli on your PATH. chmod u+x. Enjoy.
#
# This script will query github on every invocation to pull the latest released version.
# If you want repeatable executions, you can explicitly set a version via
# OPENAPI_GENERATOR_VERSION
# e.g.
# export OPENAPI_GENERATOR_VERSION=3.1.0
# openapi-generator-cli.sh
# or
# OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli.sh
# This is also helpful, for example, if you want want to evaluate a SNAPSHOT version.
#
# NOTE: Jars are downloaded on demand from maven into the same directory as this script
# for every 'latest' version pulled from github.
####
set -o pipefail
for cmd in {mvn,python,curl}; do
if ! command -v ${cmd} > /dev/null; then
>&2 echo "This script requires '${cmd}' to be installed."
exit 1
fi
done
function latest.tag {
local uri="https://api.github.com/repos/${1}/tags"
curl -s ${uri} | python -c "import sys, json; print json.load(sys.stdin)[0]['name'][1:]"
}
ghrepo=openapitools/openapi-generator
groupid=org.openapitools
artifactid=openapi-generator-cli
ver=${OPENAPI_GENERATOR_VERSION:-$(latest.tag $ghrepo)}
jar=${artifactid}-${ver}.jar
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -f ${DIR}/${jar} ]; then
repo="central::default::https://repo1.maven.apache.org/maven2"
if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then
repo="central::default::https://oss.sonatype.org/content/repositories/snapshots"
fi
mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:get \
-DremoteRepositories=${repo} \
-Dartifact=${groupid}:${artifactid}:${ver} \
-Dtransitive=false \
-Ddest=${DIR}/${jar}
fi
java -ea \
${JAVA_OPTS} \
-Xms512M \
-Xmx1024M \
-server \
-jar ${DIR}/${jar} "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment