feat: 初始化零工后端代码
This commit is contained in:
37
gig-poc/infrastructure/scripts/freeze-openapi.sh
Executable file
37
gig-poc/infrastructure/scripts/freeze-openapi.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
|
||||
PROJECT_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)
|
||||
OUTPUT_PATH="${1:-$PROJECT_DIR/docs/openapi.json}"
|
||||
API_PORT="${API_PORT:-8000}"
|
||||
|
||||
mkdir -p "$(dirname "$OUTPUT_PATH")"
|
||||
|
||||
if PYTHONPATH="$PROJECT_DIR/apps/api" python3 - "$OUTPUT_PATH" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
from app.main import app
|
||||
|
||||
output = sys.argv[1]
|
||||
spec = app.openapi()
|
||||
with open(output, "w", encoding="utf-8") as f:
|
||||
json.dump(spec, f, ensure_ascii=False, indent=2)
|
||||
f.write("\n")
|
||||
print(f"OpenAPI 已固化到: {output}")
|
||||
PY
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "本机缺少 API 依赖,尝试从已运行 API 导出..."
|
||||
if curl -fsS "http://127.0.0.1:${API_PORT}/openapi.json" -o "$OUTPUT_PATH"; then
|
||||
echo "OpenAPI 已固化到: $OUTPUT_PATH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "本机 API 端口不可用,尝试通过 Docker 运行 API 镜像离线导出..."
|
||||
docker compose -f "$PROJECT_DIR/infrastructure/docker-compose.yml" run --rm api \
|
||||
python -c "import json; from app.main import app; print(json.dumps(app.openapi(), ensure_ascii=False, indent=2))" \
|
||||
> "$OUTPUT_PATH"
|
||||
echo "OpenAPI 已固化到: $OUTPUT_PATH"
|
||||
Reference in New Issue
Block a user