1717import org .slf4j .Logger ;
1818import org .slf4j .LoggerFactory ;
1919
20+ import javax .validation .constraints .Size ;
2021import java .io .IOException ;
2122import java .lang .annotation .Annotation ;
2223import java .lang .reflect .Type ;
2324import java .util .ArrayList ;
24- import java .util .Arrays ;
2525import java .util .LinkedHashMap ;
2626import java .util .List ;
2727import java .util .Map ;
2828import java .util .Optional ;
2929
30+ import static io .swagger .v3 .core .util .ValidationAnnotationsUtils .JAVAX_SIZE ;
31+ import static io .swagger .v3 .core .util .ValidationAnnotationsUtils .applySizeConstraint ;
32+
3033public class ParameterProcessor {
34+
35+ private static final String VALUE_METHOD = "value" ;
36+ private static final String FORM_PARAMETER = "form" ;
37+
3138 static Logger LOGGER = LoggerFactory .getLogger (ParameterProcessor .class );
3239
3340 public static Parameter applyAnnotations (Parameter parameter , Type type , List <Annotation > annotations , Components components , String [] classTypes , String [] methodTypes , JsonView jsonViewAnnotation ) {
@@ -150,24 +157,24 @@ public static Parameter applyAnnotations(
150157 for (Annotation annotation : annotations ) {
151158 if (annotation .annotationType ().getName ().equals ("javax.ws.rs.FormParam" )) {
152159 try {
153- String name = (String ) annotation .annotationType ().getMethod ("value" ).invoke (annotation );
160+ String name = (String ) annotation .annotationType ().getMethod (VALUE_METHOD ).invoke (annotation );
154161 if (StringUtils .isNotBlank (name )) {
155162 parameter .setName (name );
156163 }
157164 } catch (Exception e ) {
158165 }
159166 // set temporarily to "form" to inform caller that we need to further process along other form parameters
160- parameter .setIn ("form" );
167+ parameter .setIn (FORM_PARAMETER );
161168 } else if (annotation .annotationType ().getName ().endsWith ("FormDataParam" )) {
162169 try {
163- String name = (String ) annotation .annotationType ().getMethod ("value" ).invoke (annotation );
170+ String name = (String ) annotation .annotationType ().getMethod (VALUE_METHOD ).invoke (annotation );
164171 if (StringUtils .isNotBlank (name )) {
165172 parameter .setName (name );
166173 }
167174 } catch (Exception e ) {
168175 }
169176 // set temporarily to "form" to inform caller that we need to further process along other form parameters
170- parameter .setIn ("form" );
177+ parameter .setIn (FORM_PARAMETER );
171178 }
172179 }
173180
@@ -243,27 +250,21 @@ public static Parameter applyAnnotations(
243250
244251 } else if (annotation .annotationType ().getName ().equals ("javax.ws.rs.PathParam" )) {
245252 try {
246- String name = (String ) annotation .annotationType ().getMethod ("value" ).invoke (annotation );
253+ String name = (String ) annotation .annotationType ().getMethod (VALUE_METHOD ).invoke (annotation );
247254 if (StringUtils .isNotBlank (name )) {
248255 parameter .setName (name );
249256 }
250- } catch (Exception e ) {
257+ } catch (Exception ignored ) {
251258 }
252- } else if (annotation .annotationType ().getName ().equals ("javax.validation.constraints.Size" )) {
259+ } else if (annotation .annotationType ().getName ().equals (JAVAX_SIZE )) {
253260 try {
254261 if (parameter .getSchema () == null ) {
255262 parameter .setSchema (new ArraySchema ());
256263 }
257264 if (isArraySchema (parameter .getSchema ())) {
258265 Schema as = parameter .getSchema ();
259- Integer min = (Integer ) annotation .annotationType ().getMethod ("min" ).invoke (annotation );
260- if (min != null ) {
261- as .setMinItems (min );
262- }
263- Integer max = (Integer ) annotation .annotationType ().getMethod ("max" ).invoke (annotation );
264- if (max != null ) {
265- as .setMaxItems (max );
266- }
266+ Size size = (Size ) annotation ;
267+ applySizeConstraint (as , size );
267268 }
268269
269270 } catch (Exception e ) {
@@ -296,7 +297,7 @@ public static Parameter applyAnnotations(
296297 }
297298
298299 public static boolean isArraySchema (Schema schema ) {
299- return "array" . equals (schema . getType ()) || ( schema . getTypes () != null && schema . getTypes (). contains ( "array" ) );
300+ return SchemaTypeUtils . isArraySchema (schema );
300301 }
301302
302303 public static void setParameterExplode (Parameter parameter , io .swagger .v3 .oas .annotations .Parameter p ) {
@@ -315,11 +316,10 @@ private static boolean isExplodable(io.swagger.v3.oas.annotations.Parameter p, P
315316 if (schema != null ) {
316317 Class implementation = schema .implementation ();
317318 if (implementation == Void .class ) {
318- if (!schema . type (). equals ( "object" ) && ! schema . type (). equals ( "array" ) && !schema .type ().isEmpty ()) {
319+ if (!AnnotationsUtils . isExplodableOAS30 ( schema ) && !schema .type ().isEmpty ()) {
319320 explode = false ;
320321 }
321- if (schema .types ().length != 0 &&
322- (!Arrays .asList (schema .types ()).contains ("array" ) && !Arrays .asList (schema .types ()).contains ("object" ))) {
322+ if (schema .types ().length != 0 && !AnnotationsUtils .isExplodableOAS31 (schema )) {
323323 explode = false ;
324324 }
325325 }
@@ -437,7 +437,7 @@ public AnnotationsHelper(List<Annotation> annotations, Type _type) {
437437 context = true ;
438438 } else if ("javax.ws.rs.DefaultValue" .equals (item .annotationType ().getName ())) {
439439 try {
440- rsDefault = (String ) item .annotationType ().getMethod ("value" ).invoke (item );
440+ rsDefault = (String ) item .annotationType ().getMethod (VALUE_METHOD ).invoke (item );
441441 } catch (Exception ex ) {
442442 LOGGER .error ("Invocation of value method failed" , ex );
443443 }
0 commit comments