From 52078a0c1489889fd078cd47cc352458ddbfbd14 Mon Sep 17 00:00:00 2001 From: Rankgice <95294110+Rankgice@users.noreply.github.com> Date: Fri, 2 May 2025 15:06:03 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20the=20issue=20of=20generating=20swagger?= =?UTF-8?q?=20@doc=20"xxx"=20that=20fails,=20and=20use=20th=E2=80=A6=20(#4?= =?UTF-8?q?816)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: lxr --- tools/goctl/api/swagger/annotation.go | 13 +++++++++++++ tools/goctl/api/swagger/path.go | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/goctl/api/swagger/annotation.go b/tools/goctl/api/swagger/annotation.go index 09f31097e..fe3d9f799 100644 --- a/tools/goctl/api/swagger/annotation.go +++ b/tools/goctl/api/swagger/annotation.go @@ -69,3 +69,16 @@ func getListFromInfoOrDefault(properties map[string]string, key string, def []st } return resp } + +func getFirstUsableString(def ...string) string { + if len(def) == 0 { + return "" + } + for _, val := range def { + str := util.Unquote(val) + if len(str) != 0 { + return str + } + } + return "" +} diff --git a/tools/goctl/api/swagger/path.go b/tools/goctl/api/swagger/path.go index 9c55c7265..06da98bcb 100644 --- a/tools/goctl/api/swagger/path.go +++ b/tools/goctl/api/swagger/path.go @@ -77,7 +77,7 @@ func spec2Path(info apiSpec.Info, group apiSpec.Group, route apiSpec.Route) spec Produces: getListFromInfoOrDefault(route.AtDoc.Properties, "produces", []string{applicationJson}), Schemes: getListFromInfoOrDefault(route.AtDoc.Properties, "schemes", []string{schemeHttps}), Tags: getListFromInfoOrDefault(group.Annotation.Properties, "tags", []string{""}), - Summary: getStringFromKVOrDefault(route.AtDoc.Properties, "summary", ""), + Summary: getStringFromKVOrDefault(route.AtDoc.Properties, "summary", getFirstUsableString(route.AtDoc.Text, route.Handler)), Deprecated: getBoolFromKVOrDefault(route.AtDoc.Properties, "deprecated", false), Parameters: parametersFromType(route.Method, route.RequestType), Responses: jsonResponseFromType(info, route.ResponseType),