@@ -18,6 +18,7 @@ import (
18
18
type swaggerComment struct {
19
19
summary string
20
20
id string
21
+ tags string
21
22
22
23
method string
23
24
router string
@@ -40,14 +41,19 @@ func TestAllEndpointsDocumented(t *testing.T) {
40
41
route = route [:len (route )- 1 ]
41
42
}
42
43
43
- c := findSwaggerCommentByMethodAndRoute (swaggerComments , method , route )
44
- assert .NotNil (t , c , "Missing @Router annotation for: [%s] %s" , method , route )
45
- if c == nil {
46
- return nil // do not fail next assertion for this route
47
- }
44
+ t .Run (method + " " + route , func (t * testing.T ) {
45
+ t .Parallel ()
46
+
47
+ c := findSwaggerCommentByMethodAndRoute (swaggerComments , method , route )
48
+ assert .NotNil (t , c , "Missing @Router annotation" )
49
+ if c == nil {
50
+ return // do not fail next assertion for this route
51
+ }
48
52
49
- assertConsistencyBetweenRouteIDAndSummary (t , * c )
50
- assertSuccessOrFailureDefined (t , * c )
53
+ assertConsistencyBetweenRouteIDAndSummary (t , * c )
54
+ assertSuccessOrFailureDefined (t , * c )
55
+ assertRequiredAnnotations (t , * c )
56
+ })
51
57
return nil
52
58
})
53
59
}
@@ -103,6 +109,9 @@ func parseSwaggerComment(commentGroup *ast.CommentGroup) swaggerComment {
103
109
c .hasSuccess = true
104
110
} else if strings .Contains (text , "@Failure " ) {
105
111
c .hasFailure = true
112
+ } else if strings .Contains (text , "@Tags " ) {
113
+ args := strings .SplitN (text , " " , 3 )
114
+ c .tags = args [2 ]
106
115
}
107
116
}
108
117
return c
@@ -130,3 +139,9 @@ func assertConsistencyBetweenRouteIDAndSummary(t *testing.T, comment swaggerComm
130
139
func assertSuccessOrFailureDefined (t * testing.T , comment swaggerComment ) {
131
140
assert .True (t , comment .hasSuccess || comment .hasFailure , "At least one @Success or @Failure annotation must be defined" )
132
141
}
142
+
143
+ func assertRequiredAnnotations (t * testing.T , comment swaggerComment ) {
144
+ assert .NotEmpty (t , comment .id , "@ID must be defined" )
145
+ assert .NotEmpty (t , comment .summary , "@Summary must be defined" )
146
+ assert .NotEmpty (t , comment .tags , "@Tags must be defined" )
147
+ }
0 commit comments