2016-05-24 23:21:50 -04:00
#!/usr/bin/env bash
set -euo pipefail
# GEN_DIR allows to share the entrypoint between Dockerfile and run-in-docker.sh (backward compatible)
2018-04-17 09:19:10 +02:00
GEN_DIR = ${ GEN_DIR :- /opt/openapi-generator }
2023-11-14 04:41:49 +01:00
JAVA_OPTS = ${ JAVA_OPTS :- "-DloggerPath=conf/log4j.properties" }
2016-05-24 23:21:50 -04:00
2018-04-17 09:19:10 +02:00
cli = " ${ GEN_DIR } /modules/openapi-generator-cli "
codegen = " ${ cli } /target/openapi-generator-cli.jar "
2016-05-24 23:21:50 -04:00
2018-06-10 07:33:00 -04:00
# We code in a list of commands here as source processing is potentially buggy (requires undocumented conventional use of annotations).
# A list of known commands helps us determine if we should compile CLI. There's an edge-case where a new command not added to this
# list won't be considered a "real" command. We can get around that a bit by checking CLI completions beforehand if it exists.
2020-10-06 02:11:30 +02:00
commands = "config-help,generate,batch,help,list,meta,validate,version"
2020-05-08 04:22:03 +01:00
if [ $# = = 0 ] ; then
2024-08-17 08:15:00 +02:00
echo "No command specified. Available commands:"
for i in $( echo $commands | sed "s/,/ /g" ) ; do
echo " $i "
done
exit
2020-05-08 04:22:03 +01:00
fi
2018-06-10 07:33:00 -04:00
# if CLI jar exists, check $1 against completions available in the CLI
if [ [ -f " ${ codegen } " && -n " $( java ${ JAVA_OPTS } -jar " ${ codegen } " completion | grep " ^ $1 \$ " ) " ] ] ; then
command = $1
shift
exec java ${ JAVA_OPTS } -jar " ${ codegen } " " ${ command } " " $@ "
2019-07-18 06:22:12 +01:00
elif [ [ -n " $( echo $commands | tr ',' '\n' | grep " ^ $1 \$ " ) " ] ] ; then
2018-06-10 07:33:00 -04:00
# If CLI jar does not exist, and $1 is a known CLI command, build the CLI jar and run that command.
2017-05-08 13:12:13 +03:00
if [ [ ! -f " ${ codegen } " ] ] ; then
2018-05-31 00:56:08 +02:00
( cd " ${ GEN_DIR } " && exec mvn -am -pl "modules/openapi-generator-cli" -Duser.home= $( dirname $MAVEN_CONFIG ) package)
2017-05-08 13:12:13 +03:00
fi
command = $1
shift
exec java ${ JAVA_OPTS } -jar " ${ codegen } " " ${ command } " " $@ "
else
2018-06-10 07:33:00 -04:00
# Pass args as linux commands. This allows us to do something like: docker run -it (-e…, -v…) image ls -la
2017-05-08 13:12:13 +03:00
exec " $@ "
fi