feat(openapi): integrate springdoc and API integration guide

- add springdoc-openapi and expose /v3/api-docs, /v3/api-docs.yaml and Swagger UI
- keep API docs responses unwrapped by replacing the global return handler
- add Chinese @Tag/@Operation/@Parameter docs for file and async task controllers
- add docs/api-integration.md and local export scripts for AI agent consumption
- ignore local OpenAPI snapshots and force LF for shell scripts
This commit is contained in:
Timi
2026-11-25 01:23:30 +08:00
parent dc5f62fd93
commit aefc0ad205
17 changed files with 623 additions and 17 deletions
+50
View File
@@ -0,0 +1,50 @@
<#
.SYNOPSIS
导出本地 OpenAPI 文档。
.DESCRIPTION
从本地已启动的服务获取 /v3/api-docs.yaml(或 JSON),写入 docs 目录。
生成的文件已被 .gitignore 忽略,不会提交。
.PARAMETER BaseUrl
服务地址,默认 http://localhost:18092。
.PARAMETER OutFile
输出文件路径,默认 docs/openapi.local.yaml。
扩展名为 .json 时导出 JSON,否则导出 YAML。
.EXAMPLE
.\scripts\export-openapi.ps1
.EXAMPLE
.\scripts\export-openapi.ps1 -BaseUrl http://192.168.1.10:18092 -OutFile docs/openapi.local.json
#>
param(
[string]$BaseUrl = "http://localhost:18092",
[string]$OutFile
)
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrWhiteSpace($OutFile)) {
$OutFile = Join-Path (Split-Path -Parent $PSScriptRoot) "docs\openapi.local.yaml"
}
$BaseUrl = $BaseUrl.TrimEnd("/")
$OutFile = [System.IO.Path]::GetFullPath($OutFile)
$OutDir = Split-Path -Parent $OutFile
if (-not (Test-Path -LiteralPath $OutDir)) {
New-Item -ItemType Directory -Path $OutDir -Force | Out-Null
}
if ([System.IO.Path]::GetExtension($OutFile) -ieq ".json") {
$ApiPath = "/v3/api-docs"
} else {
$ApiPath = "/v3/api-docs.yaml"
}
$Url = "$BaseUrl$ApiPath"
Write-Host "Fetching $Url"
Invoke-WebRequest -Uri $Url -OutFile $OutFile -UseBasicParsing
Write-Host "OpenAPI exported to $OutFile"
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# 导出本地 OpenAPI 文档。
#
# 用法:
# scripts/export-openapi.sh [baseUrl] [outFile]
#
# 输出文件扩展名为 .json 时导出 JSON,否则导出 YAML。
# 生成的文件已被 .gitignore 忽略,不会提交。
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BASE_URL="${1:-http://localhost:18092}"
OUT_FILE="${2:-$ROOT_DIR/docs/openapi.local.yaml}"
BASE_URL="${BASE_URL%/}"
mkdir -p "$(dirname "$OUT_FILE")"
case "$OUT_FILE" in
*.json)
API_PATH="/v3/api-docs"
;;
*)
API_PATH="/v3/api-docs.yaml"
;;
esac
echo "Fetching ${BASE_URL}${API_PATH}"
curl -fsS "${BASE_URL}${API_PATH}" -o "$OUT_FILE"
echo "OpenAPI exported to $OUT_FILE"