MCPcopy Index your code
hub / github.com/coder/coder / assertSingleAnnotations

Function assertSingleAnnotations

coderd/coderdtest/swaggerparser.go:245–271  ·  view source on GitHub ↗
(t *testing.T, comments []SwaggerComment)

Source from the content-addressed store, hash-verified

243var uniqueAnnotations = []string{"@ID", "@Summary", "@Tags", "@Router"}
244
245func 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
273func findSwaggerCommentByMethodAndRoute(comments []SwaggerComment, method, route string) *SwaggerComment {
274 for _, c := range comments {

Callers 1

VerifySwaggerDefinitionsFunction · 0.85

Calls 1

EqualMethod · 0.45

Tested by

no test coverage detected