| [3a89adb] | 1 | #!/usr/bin/env bash
|
|---|
| 2 | ####
|
|---|
| 3 | # Save as openapi-generator-cli on your PATH. chmod u+x. Enjoy.
|
|---|
| 4 | #
|
|---|
| 5 | # This script will query github on every invocation to pull the latest released version
|
|---|
| 6 | # of openapi-generator.
|
|---|
| 7 | #
|
|---|
| 8 | # If you want repeatable executions, you can explicitly set a version via
|
|---|
| 9 | # OPENAPI_GENERATOR_VERSION
|
|---|
| 10 | # e.g. (in Bash)
|
|---|
| 11 | # export OPENAPI_GENERATOR_VERSION=3.1.0
|
|---|
| 12 | # openapi-generator-cli.sh
|
|---|
| 13 | # or
|
|---|
| 14 | # OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli.sh
|
|---|
| 15 | #
|
|---|
| 16 | # This is also helpful, for example, if you want want to evaluate a SNAPSHOT version.
|
|---|
| 17 | #
|
|---|
| 18 | # NOTE: Jars are downloaded on demand from maven into the same directory as this script
|
|---|
| 19 | # for every 'latest' version pulled from github. Consider putting this under its own directory.
|
|---|
| 20 | ####
|
|---|
| 21 | set -o pipefail
|
|---|
| 22 |
|
|---|
| 23 | for cmd in {mvn,jq,curl}; do
|
|---|
| 24 | if ! command -v ${cmd} > /dev/null; then
|
|---|
| 25 | >&2 echo "This script requires '${cmd}' to be installed."
|
|---|
| 26 | exit 1
|
|---|
| 27 | fi
|
|---|
| 28 | done
|
|---|
| 29 |
|
|---|
| 30 | function latest.tag {
|
|---|
| 31 | local uri="https://api.github.com/repos/${1}/releases"
|
|---|
| 32 | local ver=$(curl -s ${uri} | jq -r 'first(.[]|select(.prerelease==false)).tag_name')
|
|---|
| 33 | if [[ $ver == v* ]]; then
|
|---|
| 34 | ver=${ver:1}
|
|---|
| 35 | fi
|
|---|
| 36 | echo $ver
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | ghrepo=openapitools/openapi-generator
|
|---|
| 40 | groupid=org.openapitools
|
|---|
| 41 | artifactid=openapi-generator-cli
|
|---|
| 42 | ver=${OPENAPI_GENERATOR_VERSION:-$(latest.tag $ghrepo)}
|
|---|
| 43 |
|
|---|
| 44 | jar=${artifactid}-${ver}.jar
|
|---|
| 45 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|---|
| 46 |
|
|---|
| 47 | if [ ! -f ${DIR}/${jar} ]; then
|
|---|
| 48 | repo="central::default::https://repo1.maven.org/maven2/"
|
|---|
| 49 | if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then
|
|---|
| 50 | repo="central::default::https://oss.sonatype.org/content/repositories/snapshots"
|
|---|
| 51 | fi
|
|---|
| 52 | mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:get \
|
|---|
| 53 | -DremoteRepositories=${repo} \
|
|---|
| 54 | -Dartifact=${groupid}:${artifactid}:${ver} \
|
|---|
| 55 | -Dtransitive=false \
|
|---|
| 56 | -Ddest=${DIR}/${jar}
|
|---|
| 57 | fi
|
|---|
| 58 |
|
|---|
| 59 | java -ea \
|
|---|
| 60 | ${JAVA_OPTS} \
|
|---|
| 61 | -Xms512M \
|
|---|
| 62 | -Xmx1024M \
|
|---|
| 63 | -server \
|
|---|
| 64 | -jar ${DIR}/${jar} "$@"
|
|---|