This commit is contained in:
51
scripts/update-swagger-ui.sh
Executable file
51
scripts/update-swagger-ui.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Usage: ./update-swagger-ui.sh [version]
|
||||
# Example: ./update-swagger-ui.sh v5.17.14
|
||||
# If no version is provided, defaults below is used.
|
||||
VERSION="${1:-v5.29.5}"
|
||||
|
||||
TARGET_DIR="server/router/swagger-ui-dist"
|
||||
TARBALL_URL="https://github.com/swagger-api/swagger-ui/archive/refs/tags/${VERSION}.tar.gz"
|
||||
|
||||
echo ">> Fetching Swagger UI ${VERSION} …"
|
||||
tmpdir="$(mktemp -d)"
|
||||
cleanup() { rm -rf "$tmpdir"; }
|
||||
trap cleanup EXIT
|
||||
|
||||
# Requirements check
|
||||
for cmd in curl tar; do
|
||||
command -v "$cmd" >/dev/null 2>&1 || { echo "ERROR: $cmd not found"; exit 1; }
|
||||
done
|
||||
|
||||
# Download & unpack
|
||||
curl -fsSL "$TARBALL_URL" | tar -xz -C "$tmpdir"
|
||||
SRC_DIR="${tmpdir}/swagger-ui-${VERSION#v}/dist"
|
||||
if [[ ! -d "$SRC_DIR" ]]; then
|
||||
echo "ERROR: Unpacked dist not found at $SRC_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Replace target
|
||||
rm -rf "$TARGET_DIR"
|
||||
mkdir -p "$TARGET_DIR"
|
||||
# Use cp -a for portability (avoids rsync dependency)
|
||||
cp -a "${SRC_DIR}/." "$TARGET_DIR/"
|
||||
|
||||
INDEX="${TARGET_DIR}/swagger-initializer.js"
|
||||
if [[ ! -f "$INDEX" ]]; then
|
||||
echo "ERROR: ${INDEX} not found after copy"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ">> Patching swagger-initializer.js to point at /swagger.json"
|
||||
|
||||
sed -i -E \
|
||||
-e 's#configUrl:[[:space:]]*["'\''"][^"'\''"]*["'\''"]#url: "/swagger.json"#' \
|
||||
-e 's#url:[[:space:]]*["'\''"][^"'\''"]*["'\''"]#url: "/swagger.json"#' \
|
||||
-e 's#urls:[[:space:]]*\[[^]]*\]#url: "/swagger.json"#' \
|
||||
-e '/url:[[:space:]]*"[^\"]*swagger\.json"[[:space:]]*,?$/a\ validatorUrl: null,' \
|
||||
"$INDEX"
|
||||
|
||||
echo ">> Done. Files are in ${TARGET_DIR}"
|
||||
Reference in New Issue
Block a user