feat(swagger): add Chinese summaries and descriptions for routes
Replace generic "METHOD path" summaries with curated Chinese summaries and longer descriptions, surfaced in Swagger UI. Adds a parity test that fails when a new tenant-api route is wired up without a docs entry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,12 @@ func TestBuildOpenAPI_GeneratesUsableSpecFromGinRoutes(t *testing.T) {
|
||||
articlePath := paths["/api/tenant/articles/{id}"].(map[string]any)
|
||||
getArticle := articlePath["get"].(map[string]any)
|
||||
require.Equal(t, []map[string][]string{{"bearerAuth": []string{}}}, getArticle["security"])
|
||||
require.Equal(t, "文章详情", getArticle["summary"])
|
||||
require.NotEmpty(t, getArticle["description"])
|
||||
|
||||
loginPath := paths["/api/auth/login"].(map[string]any)
|
||||
loginPost := loginPath["post"].(map[string]any)
|
||||
require.Equal(t, "账号密码登录", loginPost["summary"])
|
||||
|
||||
params := getArticle["parameters"].([]map[string]any)
|
||||
require.Contains(t, parameterNames(params), "id")
|
||||
@@ -50,6 +56,18 @@ func TestEnabledForMode_DisablesReleaseOnly(t *testing.T) {
|
||||
require.True(t, EnabledForMode("debug"))
|
||||
}
|
||||
|
||||
func TestDocFor_FallsBackWhenMissing(t *testing.T) {
|
||||
doc := docFor("GET", "/api/some/unregistered/path")
|
||||
require.Equal(t, "GET /api/some/unregistered/path", doc.Summary)
|
||||
require.Empty(t, doc.Description)
|
||||
}
|
||||
|
||||
func TestDocFor_KnownRoute(t *testing.T) {
|
||||
doc := docFor("POST", "/api/auth/login")
|
||||
require.Equal(t, "账号密码登录", doc.Summary)
|
||||
require.NotEmpty(t, doc.Description)
|
||||
}
|
||||
|
||||
func parameterNames(params []map[string]any) []string {
|
||||
names := make([]string, 0, len(params))
|
||||
for _, param := range params {
|
||||
|
||||
Reference in New Issue
Block a user