88import it .aboutbits .springboot .toolbox .type .CustomType ;
99import it .aboutbits .springboot .toolbox .type .ScaledBigDecimal ;
1010import it .aboutbits .springboot .toolbox .type .identity .EntityId ;
11- import lombok .NonNull ;
1211import lombok .extern .slf4j .Slf4j ;
1312import org .springdoc .core .customizers .PropertyCustomizer ;
1413
@@ -24,123 +23,103 @@ public Schema<?> customize(Schema property, AnnotatedType annotatedType) {
2423 if (type instanceof SimpleType simpleType ) {
2524 var rawClass = simpleType .getRawClass ();
2625
27- // We set the enum name as the description because swagger treats each usage as a new enum.
28- // This way we can preserve the information about the original enum type.
29- if ( rawClass . isEnum ()) {
30- var displayName = rawClass . getName (); // .replace( rawClass.getPackage(). getName() + ".", "");
31- property . setDescription ( SwaggerMetaUtil . setOriginalTypeFqn ( property . getDescription (), displayName ));
26+ if ( rawClass . getName (). contains ( "." ) && ! rawClass . getName (). startsWith ( "java." )) {
27+ property . setDescription ( SwaggerMetaUtil . setOriginalTypeFqn (
28+ property . getDescription (),
29+ rawClass .getName ()
30+ ));
3231 }
33- }
3432
35- if (type instanceof SimpleType simpleType && CustomType .class .isAssignableFrom (simpleType .getRawClass ())) {
36- var rawClass = simpleType .getRawClass ();
33+ if (CustomType .class .isAssignableFrom (simpleType .getRawClass ())) {
34+ Class <?> wrappedType ;
35+ if (rawClass .equals (EntityId .class )) {
36+ wrappedType = simpleType .getBindings ().getBoundType (0 ).getRawClass ();
37+ } else {
38+ var constructor = RecordReflectionUtil .getCanonicalConstructor (rawClass );
39+ wrappedType = constructor .getParameters ()[0 ].getType ();
40+ }
3741
38- var displayName = rawClass .getName (); // .getSimpleName();
39- var isIdentity = false ;
42+ var isIdentity = EntityId .class .isAssignableFrom (rawClass );
4043
41- Class <?> wrappedType ;
42- if (EntityId .class .isAssignableFrom (rawClass )) {
43- isIdentity = true ;
44- displayName = resolveEntityIdDisplayName (rawClass );
45- }
46-
47- if (rawClass .equals (EntityId .class )) {
48- wrappedType = simpleType .getBindings ().getBoundType (0 ).getRawClass ();
49- } else {
50- var constructor = RecordReflectionUtil .getCanonicalConstructor (rawClass );
51- wrappedType = constructor .getParameters ()[0 ].getType ();
52- }
44+ var description = SwaggerMetaUtil .setIsIdentity (property .getDescription (), isIdentity );
5345
54- var description = SwaggerMetaUtil .setOriginalTypeFqn (property .getDescription (), displayName );
55- description = SwaggerMetaUtil .setIsIdentity (description , isIdentity );
56- description = SwaggerMetaUtil .setIsIdentity (description , isIdentity );
46+ if (Short .class .isAssignableFrom (wrappedType )) {
47+ property .type ("integer" );
48+ property .format ("" );
49+ property .setDescription (description );
50+ property .setProperties (null );
51+ property .set$ref (null );
52+ return property ;
53+ }
54+ if (Integer .class .isAssignableFrom (wrappedType )) {
55+ property .type ("integer" );
56+ property .format ("int32" );
57+ property .setDescription (description );
58+ property .setProperties (null );
59+ property .set$ref (null );
60+ return property ;
61+ }
62+ if (Long .class .isAssignableFrom (wrappedType )) {
63+ property .type ("integer" );
64+ property .format ("int64" );
65+ property .setDescription (description );
66+ property .setProperties (null );
67+ property .set$ref (null );
68+ return property ;
69+ }
70+ if (BigInteger .class .isAssignableFrom (wrappedType )) {
71+ property .type ("integer" );
72+ property .format ("int64" );
73+ property .setDescription (description );
74+ property .setProperties (null );
75+ property .set$ref (null );
76+ return property ;
77+ }
78+ if (Float .class .isAssignableFrom (wrappedType )) {
79+ property .type ("number" );
80+ property .format ("float" );
81+ property .setDescription (description );
82+ property .setProperties (null );
83+ property .set$ref (null );
84+ return property ;
85+ }
86+ if (Double .class .isAssignableFrom (wrappedType )) {
87+ property .type ("number" );
88+ property .format ("double" );
89+ property .setDescription (description );
90+ property .setProperties (null );
91+ property .set$ref (null );
92+ return property ;
93+ }
94+ if (BigDecimal .class .isAssignableFrom (wrappedType )) {
95+ property .type ("number" );
96+ property .format ("" );
97+ property .setDescription (description );
98+ property .setProperties (null );
99+ property .set$ref (null );
100+ return property ;
101+ }
57102
58- if (Short .class .isAssignableFrom (wrappedType )) {
59- property .type ("integer" );
60- property .format ("" );
61- property .setDescription (description );
62- property .setProperties (null );
63- property .set$ref (null );
64- return property ;
65- }
66- if (Integer .class .isAssignableFrom (wrappedType )) {
67- property .type ("integer" );
68- property .format ("int32" );
69- property .setDescription (description );
70- property .setProperties (null );
71- property .set$ref (null );
72- return property ;
73- }
74- if (Long .class .isAssignableFrom (wrappedType )) {
75- property .type ("integer" );
76- property .format ("int64" );
77- property .setDescription (description );
78- property .setProperties (null );
79- property .set$ref (null );
80- return property ;
81- }
82- if (BigInteger .class .isAssignableFrom (wrappedType )) {
83- property .type ("integer" );
84- property .format ("int64" );
85- property .setDescription (description );
86- property .setProperties (null );
87- property .set$ref (null );
88- return property ;
89- }
90- if (Float .class .isAssignableFrom (wrappedType )) {
91- property .type ("number" );
92- property .format ("float" );
93- property .setDescription (description );
94- property .setProperties (null );
95- property .set$ref (null );
96- return property ;
103+ if (ScaledBigDecimal .class .isAssignableFrom (wrappedType )) {
104+ property .type ("number" );
105+ property .format ("" );
106+ property .setDescription (description );
107+ property .setProperties (null );
108+ property .set$ref (null );
109+ return property ;
110+ }
111+ if (String .class .isAssignableFrom (wrappedType )) {
112+ property .type ("string" );
113+ property .format (null );
114+ property .setDescription (description );
115+ property .setProperties (null );
116+ property .set$ref (null );
117+ return property ;
118+ }
119+ log .warn ("Property {} of type WrappedValue: Can not resolve parameter type!" , property .getName ());
97120 }
98- if (Double .class .isAssignableFrom (wrappedType )) {
99- property .type ("number" );
100- property .format ("double" );
101- property .setDescription (description );
102- property .setProperties (null );
103- property .set$ref (null );
104- return property ;
105- }
106- if (BigDecimal .class .isAssignableFrom (wrappedType )) {
107- property .type ("number" );
108- property .format ("" );
109- property .setDescription (description );
110- property .setProperties (null );
111- property .set$ref (null );
112- return property ;
113- }
114-
115- if (ScaledBigDecimal .class .isAssignableFrom (wrappedType )) {
116- property .type ("number" );
117- property .format ("" );
118- property .setDescription (description );
119- property .setProperties (null );
120- property .set$ref (null );
121- return property ;
122- }
123- if (String .class .isAssignableFrom (wrappedType )) {
124- property .type ("string" );
125- property .format (null );
126- property .setDescription (description );
127- property .setProperties (null );
128- property .set$ref (null );
129- return property ;
130- }
131- log .warn ("Property {} of type WrappedValue: Can not resolve parameter type!" , property .getName ());
132121 }
133122
134123 return property ;
135124 }
136-
137- @ NonNull
138- private static String resolveEntityIdDisplayName (Class <?> rawClass ) {
139- return rawClass .getName ();
140- /* var parent = rawClass.getEnclosingClass();
141- if (parent != null) {
142- return parent.getSimpleName() + "." + rawClass.getSimpleName();
143- }
144- return rawClass.getSimpleName();*/
145- }
146125}
0 commit comments