From eb91d17001c11246fefd6250478bb184fe9d6036 Mon Sep 17 00:00:00 2001
From: Jim Schubert <james.schubert@gmail.com>
Date: Sun, 10 Jun 2018 16:34:10 -0400
Subject: [PATCH 1/2] Adds a simple bash completion script

This works with any loading script named openapi-generator-cli.
That is, if you've installed via homebrew or created a script similar
to https://gist.github.com/jimschubert/ce241b0c78140e364f46914ef8ec4103

This script is relatively simple, relying on fallback to the recently
add "completion" command to the CLI project.

The script includes a possible extension to allow for per-language
options to autocomplete when the user is applying additional properties.
This work is currently commented out, as it may be simplified a bit in
the CLI first.
---
 scripts/openapi-generator-cli-completion.bash | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 scripts/openapi-generator-cli-completion.bash

diff --git a/scripts/openapi-generator-cli-completion.bash b/scripts/openapi-generator-cli-completion.bash
new file mode 100644
index 00000000000..96233fb22ed
--- /dev/null
+++ b/scripts/openapi-generator-cli-completion.bash
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+###
+# Provides completion assistance for openapi-generator-cli
+# Install
+# Mac:
+#    brew install bash-completion
+#    cp openapi-generator-cli-completion.bash `brew --prefix`/etc/bash_completion.d
+# Linux: many distributions include this automatically. Search for your distro-specific instructions.
+# When in doubt, try sourcing this file:
+#    type complete && source openapi-generator-cli
+#
+# see http://tldp.org/LDP/abs/html/tabexpansion.html
+###
+
+_openapi_generator_cli_completions() {
+  COMPREPLY=()
+  local IFS=$' \t\n'
+  local options=()
+
+  options+=("$($1 completion ${COMP_WORDS[@]:1})")
+
+  case "${COMP_WORDS[1]}" in
+    generate)
+      case "${COMP_WORDS[@]:2}" in
+        -l|--lang|-g|--generator-name)
+        # TODO: This is a nice-to-have and not required.
+        # Apply generator-specific options to additional properties. These can be queried via:
+        # openapi-generator-cli config-help -l YOUR_LANG | grep '^\t' | grep -v '^\t\s\s\s\s' | tr -d '\t'
+        # where YOUR_LANG would need to be evaluated as the value after the current switch.
+        # but rather than switching on 'generate' maybe switch on --additional-properties?
+        ;;
+      esac
+    ;;
+    *)
+    # ignore
+    ;;
+  esac
+
+  # printf '%s\n' "${options[@]}"
+  if [[ -n "${options[@]}" ]]; then
+    COMPREPLY=( $(compgen  -W "${options}" -- ${2}) )
+  fi
+}
+
+complete -F _openapi_generator_cli_completions openapi-generator-cli
-- 
GitLab


From 725c8c837e8442670a2da12c4bae2d607b01fe14 Mon Sep 17 00:00:00 2001
From: Jim Schubert <james.schubert@gmail.com>
Date: Sat, 7 Jul 2018 11:50:30 -0400
Subject: [PATCH 2/2] Add launcher script and "install" instructions

---
 README.md                          | 49 ++++++++++++++++++++++--
 bin/utils/openapi-generator-cli.sh | 60 ++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 bin/utils/openapi-generator-cli.sh

diff --git a/README.md b/README.md
index a43d7b2ad4c..a19c6d16223 100644
--- a/README.md
+++ b/README.md
@@ -129,16 +129,16 @@ You can find our released artefacts on maven central:
 
 If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
 
-JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.0/openapi-generator-cli-3.0.0.jar`
+JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.0/openapi-generator-cli-3.1.0.jar`
 
 For **Mac/Linux** users:
 ```sh
-wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.0/openapi-generator-cli-3.0.0.jar -O openapi-generator-cli.jar
+wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.0/openapi-generator-cli-3.1.0.jar -O openapi-generator-cli.jar
 ```
 
 For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
 ```
-Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.0/openapi-generator-cli-3.0.0.jar
+Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.0/openapi-generator-cli-3.1.0.jar
 ```
 
 After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
@@ -149,6 +149,49 @@ export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
 export PATH=${JAVA_HOME}/bin:$PATH
 ```
 
+### Launcher Script
+
+One downside to manual jar downloads is that you don't keep up-to-date with the latest released version. We have a Bash launcher script at [bin/utils/openapi-generator.cli.sh](./bin/utils/openapi-generator.cli.sh) which resolves this issue.
+
+To install the launcher script, copy the contents of the script to a location on your path and make the script executable.
+
+An example of setting this up (NOTE: Always evaluate scripts curled from external systems before executing them).
+
+```
+mkdir -p ~/bin/openapitools
+curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator.cli.sh > ~/bin/openapitools/openapi-generator-cli
+chmod u+x ~/bin/openapitools/openapi-generator-cli
+export PATH=$PATH:~/bin/openapitools/
+```
+
+Now, `openapi-generator-cli` is "installed". On invocation, it will query the GitHub repository for the most recently released version. If this matches the last downloaded jar,
+it will execute as normal. If a newer version is found, the script will download the latest release and execute it.
+
+If you need to invoke an older version of the generator, you can define the variable `OPENAPI_GENERATOR_VERSION` either ad hoc or globally. You can export this variable if you'd like to persist a specific release version.
+
+Examples:
+
+```
+# Execute latest released openapi-generator-cli
+openapi-generator-cli version
+
+# Execute version 3.1.0 for the current invocation, regardless of the latest released version
+OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli version
+
+# Execute version 3.1.0-SNAPSHOT for the current invocation
+OPENAPI_GENERATOR_VERSION=3.1.0-SNAPSHOT openapi-generator-cli version
+
+# Execute version 3.0.2 for every invocation in the current shell session
+export OPENAPI_GENERATOR_VERSION=3.0.2
+openapi-generator-cli version # is 3.0.2
+openapi-generator-cli version # is also 3.0.2
+
+# To "install" a specific version, set the variable in .bashrc/.bash_profile
+echo "export OPENAPI_GENERATOR_VERSION=3.0.2" >> ~/.bashrc
+source ~/.bashrc
+openapi-generator-cli version # is always 3.0.2, unless any of the above overrides are done ad hoc
+```
+
 ### [1.4 - Build Projects](#table-of-contents)
 
 To build from source, you need the following installed and available in your `$PATH:`
diff --git a/bin/utils/openapi-generator-cli.sh b/bin/utils/openapi-generator-cli.sh
new file mode 100644
index 00000000000..0f1016f9aed
--- /dev/null
+++ b/bin/utils/openapi-generator-cli.sh
@@ -0,0 +1,60 @@
+#!/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
+# of openapi-generator.
+#
+# If you want repeatable executions, you can explicitly set a version via
+#    OPENAPI_GENERATOR_VERSION
+# e.g. (in Bash)
+#    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. Consider putting this under its own directory.
+####
+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} "$@"
\ No newline at end of file
-- 
GitLab