-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use forked openapi generator repo (#4343)
- Loading branch information
1 parent
b7f2df6
commit 63b5ef7
Showing
4 changed files
with
52 additions
and
1,183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
#!/bin/bash | ||
# Script for calling OpenAPI Generato (generate clients, servers, and documentation from OpenAPI 2.0/3.x documents) or | ||
# fetch the associated templates for Python client generation. Which function is called is determined by the 'RUN_FCN' environment variable. | ||
# Setting 'RUN_FCN'="OPENAPI_GENERATOR_CLI" calls the generator and setting 'RUN_FCN'="FETCH_TEMPLATES" fetches the python client templates | ||
# Script for calling OpenAPI Generator (generate clients, servers, and documentation from OpenAPI 2.0/3.x documents). | ||
|
||
# OpenAPI Generator: generate clients, servers, and documentation from OpenAPI 2.0/3.x documents | ||
# | ||
|
@@ -24,52 +22,69 @@ | |
# https://hub.docker.com/r/openapitools/openapi-generator-cli | ||
# | ||
|
||
# fetch_openapi_generator_templates | ||
# usage: fetch_openapi_generator_templates <dir to place the templates in> | ||
|
||
OPENAPI_GENERATOR_VERSION=v4.2.3 | ||
|
||
openapi_generator_cli(){ | ||
|
||
fetch_openapi_generator_templates(){ | ||
CURDIR=$(pwd) | ||
TMPDIR=$1 | ||
cd ${TMPDIR} | ||
|
||
echo "Cloning openapi-generator into ${TMPDIR} to get templates..." | ||
git clone [email protected]:ITISFoundation/openapi-generator.git | ||
cd openapi-generator | ||
git checkout openapi-generator-${OPENAPI_GENERATOR_VERSION} | ||
git status | ||
git pull | ||
echo "Done fetching templates..." | ||
|
||
cd ${CURDIR} | ||
} | ||
|
||
|
||
openapi_generator_cli_generate(){ | ||
TMPDIR=$(mktemp -d) | ||
USERID=$(stat --format=%u "$PWD") | ||
GROUPID=$(stat --format=%g "$PWD") | ||
HOST_TEMPL_DIR=${TMPDIR}/openapi-generator/modules/openapi-generator/src/main/resources/python | ||
CONTAINER_TEMPL_DIR=/tmp/openapi_templates | ||
|
||
# to mount a directory (e.g. to find custom templates, define the DOCKER_MOUNT environment variable) | ||
docker_mount="" | ||
if [ -v DOCKER_MOUNT ]; then | ||
docker_mount="-v ${DOCKER_MOUNT}" | ||
fetch_openapi_generator_templates "${TMPDIR}" | ||
if [ ! -d "${HOST_TEMPL_DIR}" ]; then | ||
echo "Templates could not be correctly fetched from Github" | ||
exit 1 | ||
fi | ||
|
||
( | ||
exec docker run --rm \ | ||
-v ${HOST_TEMPL_DIR}:${CONTAINER_TEMPL_DIR} \ | ||
--user "$USERID:$GROUPID" \ | ||
--volume "$PWD:/local" \ | ||
openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_VERSION} "$@" \ | ||
--template-dir=${CONTAINER_TEMPL_DIR} | ||
) | ||
|
||
rm -fr "${TMPDIR}" | ||
} | ||
|
||
openapi_generator_cli(){ | ||
USERID=$(stat --format=%u "$PWD") | ||
GROUPID=$(stat --format=%g "$PWD") | ||
|
||
exec docker run --rm \ | ||
${docker_mount} \ | ||
--user "$USERID:$GROUPID" \ | ||
--volume "$PWD:/local" \ | ||
openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_VERSION} "$@" | ||
} | ||
|
||
fetch_openapi_generator_templates(){ | ||
TEMPLATE_DIR=$1 | ||
TMPDIR=$(mktemp -d) | ||
|
||
echo "Fetching openapi generator templates from github..." | ||
wget -O ${TMPDIR}/openapi_zip.zip "https://github.com/OpenAPITools/openapi-generator/archive/refs/tags/${OPENAPI_GENERATOR_VERSION}.zip" | ||
unzip -q ${TMPDIR}/openapi_zip.zip -d ${TMPDIR} | ||
|
||
echo "Overwriting templates in this repo..." | ||
rm -r ${TEMPLATE_DIR} | ||
mkdir ${TEMPLATE_DIR} | ||
cd ${TMPDIR} | ||
openapi_dir=$(ls . | grep openapi-generator) | ||
cd ${openapi_dir} | ||
cp -r ./modules/openapi-generator/src/main/resources/python/* ${TEMPLATE_DIR} | ||
|
||
rm -r ${TMPDIR} | ||
echo "Done!" | ||
} | ||
generate=false | ||
if [[ $1 == "generate" ]]; then | ||
echo "Found generate input. Will fetch templates from [email protected]:ITISFoundation/openapi-generator.git" | ||
generate=true | ||
fi | ||
|
||
if [[ "${RUN_FCN}" == "OPENAPI_GENERATOR_CLI" ]]; then | ||
openapi_generator_cli "$@" | ||
elif [[ "${RUN_FCN}" == "FETCH_TEMPLATES" ]]; then | ||
fetch_openapi_generator_templates "$@" | ||
if ${generate}; then | ||
openapi_generator_cli_generate "$@" | ||
else | ||
echo "The environment variable 'RUN_FCN' must be defined when calling this bash script" | ||
openapi_generator_cli "$@" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.