(t *testing.T, comments []SwaggerComment)
| 243 | var uniqueAnnotations = []string{"@ID", "@Summary", "@Tags", "@Router"} |
| 244 | |
| 245 | func assertSingleAnnotations(t *testing.T, comments []SwaggerComment) { |
| 246 | for _, comment := range comments { |
| 247 | counters := map[string]int{} |
| 248 | |
| 249 | for _, line := range comment.raw { |
| 250 | splitN := strings.SplitN(strings.TrimSpace(line.Text), " ", 3) |
| 251 | if len(splitN) < 2 { |
| 252 | continue // comment prefix without any content |
| 253 | } |
| 254 | |
| 255 | if !strings.HasPrefix(splitN[1], "@") { |
| 256 | continue // not a swagger annotation |
| 257 | } |
| 258 | |
| 259 | annotation := splitN[1] |
| 260 | if _, ok := counters[annotation]; !ok { |
| 261 | counters[annotation] = 0 |
| 262 | } |
| 263 | counters[annotation]++ |
| 264 | } |
| 265 | |
| 266 | for _, annotation := range uniqueAnnotations { |
| 267 | v := counters[annotation] |
| 268 | assert.Equal(t, 1, v, "%s annotation for route %s must be defined only once", annotation, comment.router) |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | func findSwaggerCommentByMethodAndRoute(comments []SwaggerComment, method, route string) *SwaggerComment { |
| 274 | for _, c := range comments { |
no test coverage detected