topfans/backend/gen-swagger.sh
2026-04-07 22:29:48 +08:00

50 lines
1.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Swagger 文档生成脚本
# 用途:为 Gateway 服务生成 Swagger API 文档
set -e
# 进入 gateway 目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/gateway"
echo "======================================"
echo "开始生成 Swagger 文档"
echo "======================================"
# 检查 swag 是否已安装
if ! command -v swag &> /dev/null; then
echo "❌ swag 未安装!"
echo "请安装 swag"
echo " go install github.com/swaggo/swag/cmd/swag@latest"
echo ""
echo "安装完成后,请确保 \$GOPATH/bin 在 PATH 中:"
echo " export PATH=\$PATH:\$(go env GOPATH)/bin"
exit 1
fi
echo "✅ swag 版本: $(swag --version)"
echo ""
# 添加 GOPATH/bin 到 PATH
export PATH="$PATH:$(go env GOPATH)/bin"
# 生成 Swagger 文档
echo "📝 正在生成 Swagger 文档..."
swag init --parseDependency --parseInternal \
--parseDepth 1 \
--output ./docs
echo ""
echo "✅ Swagger 文档生成完成!"
echo ""
echo "生成的文件:"
echo " - docs/docs.go"
echo " - docs/swagger.json"
echo " - docs/swagger.yaml"
echo ""
echo "访问 Swagger UI"
echo " http://localhost:3000/swagger/index.html"
echo ""