@@ -94,24 +94,29 @@ func parseSwaggerComments(dir string) ([]swaggerComment, error) {
94
94
func parseSwaggerComment (commentGroup * ast.CommentGroup ) swaggerComment {
95
95
var c swaggerComment
96
96
for _ , line := range commentGroup .List {
97
- text := strings .TrimSpace (line .Text )
98
- if strings .Contains (text , "@Router " ) {
99
- args := strings .SplitN (text , " " , 4 )
100
- c .router = args [2 ]
101
- c .method = args [3 ][1 : len (args [3 ])- 1 ]
102
- } else if strings .Contains (text , "@Summary " ) {
103
- args := strings .SplitN (text , " " , 3 )
104
- c .summary = args [2 ]
105
- } else if strings .Contains (text , "@ID " ) {
97
+ splitN := strings .SplitN (strings .TrimSpace (line .Text ), " " , 2 )
98
+ if len (splitN ) < 2 {
99
+ continue // comment prefix without any content
100
+ }
101
+ text := splitN [1 ] // Skip the comment prefix (double-slash)
102
+
103
+ if strings .HasPrefix (text , "@Router " ) {
106
104
args := strings .SplitN (text , " " , 3 )
107
- c .id = args [2 ]
108
- } else if strings .Contains (text , "@Success " ) {
105
+ c .router = args [1 ]
106
+ c .method = args [2 ][1 : len (args [2 ])- 1 ]
107
+ } else if strings .HasPrefix (text , "@Summary " ) {
108
+ args := strings .SplitN (text , " " , 2 )
109
+ c .summary = args [1 ]
110
+ } else if strings .HasPrefix (text , "@ID " ) {
111
+ args := strings .SplitN (text , " " , 2 )
112
+ c .id = args [1 ]
113
+ } else if strings .HasPrefix (text , "@Success " ) {
109
114
c .hasSuccess = true
110
- } else if strings .Contains (text , "@Failure " ) {
115
+ } else if strings .HasPrefix (text , "@Failure " ) {
111
116
c .hasFailure = true
112
- } else if strings .Contains (text , "@Tags " ) {
113
- args := strings .SplitN (text , " " , 3 )
114
- c .tags = args [2 ]
117
+ } else if strings .HasPrefix (text , "@Tags " ) {
118
+ args := strings .SplitN (text , " " , 2 )
119
+ c .tags = args [1 ]
115
120
}
116
121
}
117
122
return c
0 commit comments