@@ -81,7 +81,7 @@ private static boolean isEmpty(OAuthScope[] scopes) {
81
81
return result ;
82
82
}
83
83
84
- public Optional < io .swagger .v3 .oas .annotations .security .SecurityRequirement []> getSecurityRequirements (
84
+ public io .swagger .v3 .oas .annotations .security .SecurityRequirement [] getSecurityRequirements (
85
85
HandlerMethod method ) {
86
86
// class SecurityRequirements
87
87
io .swagger .v3 .oas .annotations .security .SecurityRequirements classSecurity = ReflectionUtils
@@ -90,16 +90,16 @@ public Optional<io.swagger.v3.oas.annotations.security.SecurityRequirement[]> ge
90
90
io .swagger .v3 .oas .annotations .security .SecurityRequirements methodSecurity = ReflectionUtils
91
91
.getAnnotation (method .getMethod (), io .swagger .v3 .oas .annotations .security .SecurityRequirements .class );
92
92
93
- Set <io .swagger .v3 .oas .annotations .security .SecurityRequirement > allSecurityTags = new HashSet <>() ;
93
+ Set <io .swagger .v3 .oas .annotations .security .SecurityRequirement > allSecurityTags = null ;
94
94
95
95
if (classSecurity != null ) {
96
- allSecurityTags . addAll (Arrays .asList (classSecurity .value ()));
96
+ allSecurityTags = new HashSet <> (Arrays .asList (classSecurity .value ()));
97
97
}
98
98
if (methodSecurity != null ) {
99
- allSecurityTags . addAll ( Arrays .asList (methodSecurity .value ()));
99
+ allSecurityTags = addSecurityRequirements ( allSecurityTags , Arrays .asList (methodSecurity .value ()));
100
100
}
101
101
102
- if (allSecurityTags .isEmpty ()) {
102
+ if (CollectionUtils .isEmpty (allSecurityTags )) {
103
103
// class SecurityRequirement
104
104
List <io .swagger .v3 .oas .annotations .security .SecurityRequirement > securityRequirementsClassList = ReflectionUtils
105
105
.getRepeatableAnnotations (method .getBeanType (),
@@ -109,19 +109,21 @@ public Optional<io.swagger.v3.oas.annotations.security.SecurityRequirement[]> ge
109
109
.getRepeatableAnnotations (method .getMethod (),
110
110
io .swagger .v3 .oas .annotations .security .SecurityRequirement .class );
111
111
if (!CollectionUtils .isEmpty (securityRequirementsClassList )) {
112
- allSecurityTags . addAll ( securityRequirementsClassList );
112
+ allSecurityTags = addSecurityRequirements ( allSecurityTags , securityRequirementsClassList );
113
113
}
114
114
if (!CollectionUtils .isEmpty (securityRequirementsMethodList )) {
115
- allSecurityTags . addAll ( securityRequirementsMethodList );
115
+ allSecurityTags = addSecurityRequirements ( allSecurityTags , securityRequirementsMethodList );
116
116
}
117
117
}
118
118
119
- if (allSecurityTags .isEmpty ()) {
120
- return Optional .empty ();
121
- }
119
+ return (allSecurityTags != null ) ? allSecurityTags .toArray (new io .swagger .v3 .oas .annotations .security .SecurityRequirement [0 ]) : null ;
120
+ }
122
121
123
- return Optional .of (
124
- allSecurityTags .toArray (new io .swagger .v3 .oas .annotations .security .SecurityRequirement [0 ]));
122
+ private Set <io .swagger .v3 .oas .annotations .security .SecurityRequirement > addSecurityRequirements (Set <io .swagger .v3 .oas .annotations .security .SecurityRequirement > allSecurityTags , List <io .swagger .v3 .oas .annotations .security .SecurityRequirement > securityRequirementsClassList ) {
123
+ if (allSecurityTags == null )
124
+ allSecurityTags = new HashSet <>();
125
+ allSecurityTags .addAll (securityRequirementsClassList );
126
+ return allSecurityTags ;
125
127
}
126
128
127
129
public Optional <List <SecurityRequirement >> getSecurityRequirements (
0 commit comments