@@ -81,22 +81,22 @@ func authForPath(path string, superuserVarPaths map[string]bool) string {
8181
8282// route is a single discovered route entry.
8383type route struct {
84- method string
85- path string
86- handler string
87- queryParams []string
88- queryRequired map [string ]bool
89- headerParams []swaggerParamHint
90- cookieParams []swaggerParamHint
84+ method string
85+ path string
86+ handler string
87+ queryParams []string
88+ queryRequired map [string ]bool
89+ headerParams []swaggerParamHint
90+ cookieParams []swaggerParamHint
9191 formDataParams []swaggerParamHint
92- bodyRequired * bool
93- successCodes []int
94- failureCodes []int
95- markerGroup string
96- markerSummary string
97- markerAuth string
98- summary string
99- description string
92+ bodyRequired * bool
93+ successCodes []int
94+ failureCodes []int
95+ markerGroup string
96+ markerSummary string
97+ markerAuth string
98+ summary string
99+ description string
100100}
101101
102102type swaggerParamHint struct {
@@ -133,8 +133,13 @@ func scanFile(filePath string) ([]route, map[string]bool) {
133133 handlerSummaries := extractHandlerSummaries (string (data ))
134134 handlerDescriptions := extractHandlerDescriptions (string (data ))
135135
136+ defaultG := "/api/ext"
137+ if strings .HasPrefix (filepath .Base (filePath ), "server" ) {
138+ defaultG = "/api/servers"
139+ }
140+
136141 vars := map [string ]string {
137- "g" : "/api/ext" ,
142+ "g" : defaultG ,
138143 "se" : "" ,
139144 "r" : "" ,
140145 }
@@ -1140,6 +1145,24 @@ func summaryFrom(method, path string) string {
11401145 return strings .TrimSpace (action + " " + strings .Join (clean , " " ))
11411146}
11421147
1148+ func sanitizeContentText (raw string ) string {
1149+ text := strings .TrimSpace (raw )
1150+ if text == "" {
1151+ return ""
1152+ }
1153+ text = strings .ReplaceAll (text , ":" , " " )
1154+ text = strings .ReplaceAll (text , ":" , " " )
1155+ text = strings .Join (strings .Fields (text ), " " )
1156+ return text
1157+ }
1158+
1159+ func yamlQuotedScalar (raw string ) string {
1160+ text := strings .TrimSpace (raw )
1161+ text = strings .ReplaceAll (text , `\` , `\\` )
1162+ text = strings .ReplaceAll (text , `"` , `\"` )
1163+ return "\" " + text + "\" "
1164+ }
1165+
11431166func operationID (method , path string ) string {
11441167 clean := strings .ToLower (path )
11451168 clean = strings .ReplaceAll (clean , "/" , "_" )
@@ -1220,13 +1243,13 @@ func runGen() error {
12201243 out .WriteString ("tags:\n " )
12211244 for _ , tag := range tags {
12221245 name := strings .TrimSpace (tag .Group )
1223- desc := strings . TrimSpace (tag .Description )
1246+ desc := sanitizeContentText (tag .Description )
12241247 if name == "" {
12251248 continue
12261249 }
12271250 fmt .Fprintf (& out , " - name: %s\n " , name )
12281251 if desc != "" {
1229- fmt .Fprintf (& out , " description: %s\n " , desc )
1252+ fmt .Fprintf (& out , " description: %s\n " , yamlQuotedScalar ( desc ) )
12301253 }
12311254 }
12321255 out .WriteString ("\n " )
@@ -1284,14 +1307,12 @@ func runGen() error {
12841307 } else if strings .TrimSpace (op .markerSummary ) != "" {
12851308 resolvedSummary = strings .TrimSpace (op .markerSummary )
12861309 }
1310+ resolvedSummary = sanitizeContentText (resolvedSummary )
12871311 block = strings .Replace (block , " summary: " + summaryFrom (m , p ), " summary: " + resolvedSummary , 1 )
12881312 // Inject description after summary line if @Description is set
12891313 if strings .TrimSpace (op .description ) != "" {
1290- desc := strings .TrimSpace (op .description )
1291- // Escape for YAML: wrap in double quotes, escape inner quotes and backslashes
1292- desc = strings .ReplaceAll (desc , `\` , `\\` )
1293- desc = strings .ReplaceAll (desc , `"` , `\"` )
1294- block = strings .Replace (block , " summary: " + resolvedSummary + "\n " , " summary: " + resolvedSummary + "\n description: \" " + desc + "\" \n " , 1 )
1314+ desc := sanitizeContentText (op .description )
1315+ block = strings .Replace (block , " summary: " + resolvedSummary + "\n " , " summary: " + resolvedSummary + "\n description: " + yamlQuotedScalar (desc )+ "\n " , 1 )
12951316 }
12961317 out .WriteString (block )
12971318 }
0 commit comments