Files
openapi-generator/bin/generate-samples.sh
William Cheng cc045ab53c Fix output of bin/generate-samples.sh in tmux (#22772)
* bin/generate-samples: Remove warning about sleep

The sleep itself has been commented out for a long time (commit
04fa53b692 from September 2023, to be specific).

Signed-off-by: Stephen Finucane <stephen@that.guru>

* bin/generate-samples: Fix output on tmux

Commit 23dae2bcd8 reworked this script to start capturing exceptions
but the mechanism used was crude and broke output on tmux, since
`/dev/pts/0` is hardcoded to a specific pseudo-terminal but each tmux
pane gets its own pts. Rework this to use files instead.

Signed-off-by: Stephen Finucane <stephen@that.guru>

* update error message, trigger build failur

* trigger build failure

* Revert "trigger build failure"

This reverts commit 29536fab8a1f1980f393b36421341492079764a0.

* add back null check

---------

Signed-off-by: Stephen Finucane <stephen@that.guru>
Co-authored-by: Stephen Finucane <stephen@that.guru>
2026-01-22 19:01:42 +08:00

73 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# this bash script generates all samples.
# it ensures that all changes are committed into the 'samples/' folder
# shellcheck disable=SC2155
declare cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare root="$(cd "$cwd" && cd ../ && pwd)"
declare executable="${root}/modules/openapi-generator-cli/target/openapi-generator-cli.jar"
if [ ! -f "$executable" ]; then
(cd "${root}" && mvn -B --no-snapshot-updates clean package -DskipTests=true -Dmaven.javadoc.skip=true -Djacoco.skip=true)
fi
export JAVA_OPTS="${JAVA_OPTS} -ea -server -Duser.timezone=UTC"
export BATCH_OPTS="${BATCH_OPTS:-}"
files=()
args=()
end_option=false
while [[ $# -gt 0 ]]; do
key="$1"
if [ "--" == "$key" ]; then
end_option=true
else
if [[ "$end_option" = true ]]; then
args+=("$1")
else
files+=("$1")
fi
fi
shift
done
header="# START SCRIPT: $0
This script generates all configs under bin/configs by default.
You may generate a targeted script or set of scripts using glob patterns.
For example:
$0 bin/configs/java-*
You may generate a single config with additional options if you use -- to
separate the single config file from the generator arguments.
For example:
$0 bin/configs/java-vertx.yaml -- --global-property debugModels=true
"
echo "$header"
tmpfile=$(mktemp)
trap "rm -f $tmpfile" EXIT
if [[ ${#files[@]} -eq 1 && "${files[0]}" != *'*'* ]]; then
# shellcheck disable=SC2086
# shellcheck disable=SC2068
java ${JAVA_OPTS} -jar "$executable" generate -c ${files[0]} ${args[@]} 2>&1 | tee "$tmpfile"
retcode=${PIPESTATUS[0]}
else
if [ ${#files[@]} -eq 0 ]; then
files=("${root}"/bin/configs/*.yaml)
fi
# shellcheck disable=SC2086
# shellcheck disable=SC2068
java ${JAVA_OPTS} -jar "$executable" batch ${BATCH_OPTS} --includes-base-dir "${root}" --fail-fast -- ${files[@]} 2>&1 | tee "$tmpfile"
retcode=${PIPESTATUS[0]}
fi
if [[ $retcode -ne 0 ]] || grep -q -i "at org.openapitools" "$tmpfile"; then
echo "Found exception(s) when running the generator(s) to update the samples."
exit 1
fi