@@ -16,9 +16,10 @@ import (
16
16
)
17
17
18
18
type SwaggerComment struct {
19
- summary string
20
- id string
21
- tags string
19
+ summary string
20
+ id string
21
+ security string
22
+ tags string
22
23
23
24
method string
24
25
router string
@@ -93,6 +94,9 @@ func parseSwaggerComment(commentGroup *ast.CommentGroup) SwaggerComment {
93
94
} else if strings .HasPrefix (text , "@Tags " ) {
94
95
args := strings .SplitN (text , " " , 2 )
95
96
c .tags = args [1 ]
97
+ } else if strings .HasPrefix (text , "@Security " ) {
98
+ args := strings .SplitN (text , " " , 2 )
99
+ c .security = args [1 ]
96
100
}
97
101
}
98
102
return c
@@ -118,6 +122,8 @@ func VerifySwaggerDefinitions(t *testing.T, router chi.Router, swaggerComments [
118
122
assertSuccessOrFailureDefined (t , * c )
119
123
assertRequiredAnnotations (t , * c )
120
124
assertGoCommentFirst (t , * c )
125
+ assertURLParamsDefined (t , * c )
126
+ assertSecurityDefined (t , * c )
121
127
})
122
128
return nil
123
129
})
@@ -170,3 +176,15 @@ func assertGoCommentFirst(t *testing.T, comment SwaggerComment) {
170
176
}
171
177
}
172
178
}
179
+
180
+ func assertURLParamsDefined (t * testing.T , comment SwaggerComment ) {
181
+ }
182
+
183
+ func assertSecurityDefined (t * testing.T , comment SwaggerComment ) {
184
+ if comment .router == "/updatecheck" ||
185
+ comment .router == "/buildinfo" ||
186
+ comment .router == "/" {
187
+ return // endpoints do not require authorization
188
+ }
189
+ assert .Equal (t , "CoderSessionToken" , comment .security , "@Security must be equal CoderSessionToken" )
190
+ }
0 commit comments