77import java .lang .reflect .Field ;
88import java .util .ArrayList ;
99import java .util .Arrays ;
10- import java .util .Collections ;
1110import java .util .HashSet ;
1211import java .util .List ;
1312import java .util .Map ;
1716import java .util .OptionalInt ;
1817import java .util .OptionalLong ;
1918import java .util .Set ;
19+ import java .util .function .Predicate ;
2020import java .util .stream .Stream ;
2121
2222import io .swagger .v3 .oas .annotations .Parameter ;
@@ -37,19 +37,16 @@ private static Stream<MethodParameter> extractFrom(Class<?> clazz, String fieldN
3737 }
3838
3939 private static Stream <MethodParameter > fromGetterOfField (Class <?> paramClass , Field field , String fieldNamePrefix ) {
40- if (isSimpleType (field .getType ())) {
40+ if (isSimpleType (field .getType ()))
4141 return fromSimpleClass (paramClass , field , fieldNamePrefix );
42- }
43- else {
42+ else
4443 return extractFrom (field .getType (), fieldNamePrefix + field .getName () + "." );
45- }
4644 }
4745
4846 private static Stream <MethodParameter > fromSimpleClass (Class <?> paramClass , Field field , String fieldNamePrefix ) {
4947 Annotation [] fieldAnnotations = field .getDeclaredAnnotations ();
50- if (isOptional (field )) {
48+ if (isOptional (field ))
5149 fieldAnnotations = ArrayUtils .add (fieldAnnotations , NULLABLE_ANNOTATION );
52- }
5350 try {
5451 Annotation [] finalFieldAnnotations = fieldAnnotations ;
5552 return Stream .of (Introspector .getBeanInfo (paramClass ).getPropertyDescriptors ())
@@ -79,10 +76,8 @@ private static List<Field> allFieldsOf(Class<?> clazz) {
7976 }
8077
8178 private static boolean isSimpleType (Class <?> clazz ) {
82- if (clazz .isPrimitive ()) return true ;
83- if (clazz .isArray ()) return true ;
84- if (clazz .isEnum ()) return true ;
85- return SIMPLE_TYPES .stream ().anyMatch (c -> c .isAssignableFrom (clazz ));
79+ return SIMPLE_TYPE_PREDICATES .stream ().anyMatch (p -> p .test (clazz )) ||
80+ SIMPLE_TYPES .stream ().anyMatch (c -> c .isAssignableFrom (clazz ));
8681 }
8782
8883 private static final Nullable NULLABLE_ANNOTATION = new Nullable () {
@@ -92,22 +87,37 @@ public Class<? extends Annotation> annotationType() {
9287 }
9388 };
9489
95- private static final Set <Class <?>> SIMPLE_TYPES ;
90+ private static final List <Predicate <Class <?>>> SIMPLE_TYPE_PREDICATES = new ArrayList <>();
91+
92+ private static final Set <Class <?>> SIMPLE_TYPES = new HashSet <>();
93+
94+ static void addSimpleTypePredicate (Predicate <Class <?>> predicate ) {
95+ SIMPLE_TYPE_PREDICATES .add (predicate );
96+ }
97+
98+ static void addSimpleTypes (Class <?>... classes ) {
99+ SIMPLE_TYPES .addAll (Arrays .asList (classes ));
100+ }
101+
102+ static void removeSimpleTypes (Class <?>... classes ) {
103+ SIMPLE_TYPES .removeAll (Arrays .asList (classes ));
104+ }
96105
97106 static {
98- Set <Class <?>> simpleTypes = new HashSet <>();
99- simpleTypes .add (Boolean .class );
100- simpleTypes .add (Character .class );
101- simpleTypes .add (Number .class );
102- simpleTypes .add (CharSequence .class );
103- simpleTypes .add (Optional .class );
104- simpleTypes .add (OptionalInt .class );
105- simpleTypes .add (OptionalLong .class );
106- simpleTypes .add (OptionalDouble .class );
107-
108- simpleTypes .add (Map .class );
109- simpleTypes .add (Iterable .class );
110-
111- SIMPLE_TYPES = Collections .unmodifiableSet (simpleTypes );
107+ SIMPLE_TYPES .add (Boolean .class );
108+ SIMPLE_TYPES .add (Character .class );
109+ SIMPLE_TYPES .add (Number .class );
110+ SIMPLE_TYPES .add (CharSequence .class );
111+ SIMPLE_TYPES .add (Optional .class );
112+ SIMPLE_TYPES .add (OptionalInt .class );
113+ SIMPLE_TYPES .add (OptionalLong .class );
114+ SIMPLE_TYPES .add (OptionalDouble .class );
115+
116+ SIMPLE_TYPES .add (Map .class );
117+ SIMPLE_TYPES .add (Iterable .class );
118+
119+ SIMPLE_TYPE_PREDICATES .add (Class ::isPrimitive );
120+ SIMPLE_TYPE_PREDICATES .add (Class ::isEnum );
121+ SIMPLE_TYPE_PREDICATES .add (Class ::isArray );
112122 }
113123}
0 commit comments