(commentGroup *ast.CommentGroup)
| 82 | } |
| 83 | |
| 84 | func parseSwaggerComment(commentGroup *ast.CommentGroup) SwaggerComment { |
| 85 | c := SwaggerComment{ |
| 86 | raw: commentGroup.List, |
| 87 | parameters: []parameter{}, |
| 88 | successes: []response{}, |
| 89 | failures: []response{}, |
| 90 | } |
| 91 | for _, line := range commentGroup.List { |
| 92 | // "// @<annotationName> [args...]" -> []string{"//", "@<annotationName>", "args..."} |
| 93 | splitN := strings.SplitN(strings.TrimSpace(line.Text), " ", 3) |
| 94 | if len(splitN) < 3 { |
| 95 | continue // comment prefix without any content |
| 96 | } |
| 97 | |
| 98 | if !strings.HasPrefix(splitN[1], "@") { |
| 99 | continue // not a swagger annotation |
| 100 | } |
| 101 | |
| 102 | annotationName := splitN[1] |
| 103 | annotationArgs := splitN[2] |
| 104 | args := strings.Split(splitN[2], " ") |
| 105 | |
| 106 | switch annotationName { |
| 107 | case "@Router": |
| 108 | c.router = args[0] |
| 109 | c.method = args[1][1 : len(args[1])-1] |
| 110 | case "@Success", "@Failure": |
| 111 | var r response |
| 112 | if len(args) > 0 { |
| 113 | r.status = args[0] |
| 114 | } |
| 115 | if len(args) > 1 { |
| 116 | r.kind = args[1] |
| 117 | } |
| 118 | if len(args) > 2 { |
| 119 | r.model = args[2] |
| 120 | } |
| 121 | |
| 122 | if annotationName == "@Success" { |
| 123 | c.successes = append(c.successes, r) |
| 124 | } else if annotationName == "@Failure" { |
| 125 | c.failures = append(c.failures, r) |
| 126 | } |
| 127 | case "@Param": |
| 128 | p := parameter{ |
| 129 | name: args[0], |
| 130 | kind: args[1], |
| 131 | } |
| 132 | c.parameters = append(c.parameters, p) |
| 133 | case "@Summary": |
| 134 | c.summary = annotationArgs |
| 135 | case "@ID": |
| 136 | c.id = annotationArgs |
| 137 | case "@Tags": |
| 138 | c.tags = annotationArgs |
| 139 | case "@Security": |
| 140 | c.security = annotationArgs |
| 141 | case "@Accept": |
no outgoing calls
no test coverage detected