Skip to content

Instantly share code, notes, and snippets.

@Jyosua
Created August 16, 2024 06:49
Show Gist options
  • Save Jyosua/7d0faa2c2ebe14a5ee4e630e1ad2d007 to your computer and use it in GitHub Desktop.
Save Jyosua/7d0faa2c2ebe14a5ee4e630e1ad2d007 to your computer and use it in GitHub Desktop.
Bash script for quick standalone installations of Swagger UI
#!/bin/bash
echo "Downloading the latest Swagger UI release..."
LATEST_VERSION=$(curl -s https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | grep '"tag_name"' | cut -d '"' -f 4)
echo "The latest release version is: $LATEST_VERSION"
ZIP_FILE="swagger-ui-$LATEST_VERSION.zip"
curl -L -o "$ZIP_FILE" "https://github.com/swagger-api/swagger-ui/archive/refs/tags/$LATEST_VERSION.zip"
if [[ -z "$ZIP_FILE" ]]; then
echo "Failed to download the zip file or no zip file found. Exiting."
exit 1
else
echo "Zip file downloaded successfully: $ZIP_FILE"
fi
unzip "$ZIP_FILE"
mv swagger-ui-*/dist ./
rm -rf swagger-ui-*
rm "$ZIP_FILE"
echo "Enter the path to your OpenAPI 3.0 spec (json or yaml):"
read -r openapi_path
sed -i '' "s@https://petstore.swagger.io/v2/swagger.json@$openapi_path@g" dist/swagger-initializer.js
mv dist swagger
echo "Setup complete. If you move the swagger folder, you may need to change the OpenAPI spec path again in swagger-initializer.js"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment