44import io .swagger .v3 .core .converter .AnnotatedType ;
55import io .swagger .v3 .oas .models .media .Schema ;
66import it .aboutbits .springboot .toolbox .reflection .util .RecordReflectionUtil ;
7+ import it .aboutbits .springboot .toolbox .swagger .SwaggerMetaUtil ;
78import it .aboutbits .springboot .toolbox .type .CustomType ;
89import it .aboutbits .springboot .toolbox .type .ScaledBigDecimal ;
910import it .aboutbits .springboot .toolbox .type .identity .EntityId ;
@@ -26,18 +27,20 @@ public Schema<?> customize(Schema property, AnnotatedType annotatedType) {
2627 // We set the enum name as the description because swagger treats each usage as a new enum.
2728 // This way we can preserve the information about the original enum type.
2829 if (rawClass .isEnum ()) {
29- var displayName = rawClass .getCanonicalName () .replace (rawClass .getPackage ().getName () + "." , "" );
30- property .setDescription (displayName );
30+ var displayName = rawClass .getName (); // .replace(rawClass.getPackage().getName() + ".", "");
31+ property .setDescription (SwaggerMetaUtil . setOriginalTypeFqn ( property . getDescription (), displayName ) );
3132 }
3233 }
3334
3435 if (type instanceof SimpleType simpleType && CustomType .class .isAssignableFrom (simpleType .getRawClass ())) {
3536 var rawClass = simpleType .getRawClass ();
3637
37- var displayName = rawClass .getSimpleName ();
38+ var displayName = rawClass .getName (); // .getSimpleName();
39+ var isIdentity = false ;
3840
3941 Class <?> wrappedType ;
4042 if (EntityId .class .isAssignableFrom (rawClass )) {
43+ isIdentity = true ;
4144 displayName = resolveEntityIdDisplayName (rawClass );
4245 }
4346
@@ -48,58 +51,62 @@ public Schema<?> customize(Schema property, AnnotatedType annotatedType) {
4851 wrappedType = constructor .getParameters ()[0 ].getType ();
4952 }
5053
54+ var description = SwaggerMetaUtil .setOriginalTypeFqn (property .getDescription (), displayName );
55+ description = SwaggerMetaUtil .setIsIdentity (description , isIdentity );
56+ description = SwaggerMetaUtil .setIsIdentity (description , isIdentity );
57+
5158 if (Short .class .isAssignableFrom (wrappedType )) {
5259 property .type ("integer" );
5360 property .format ("" );
54- property .setDescription (displayName );
61+ property .setDescription (description );
5562 property .setProperties (null );
5663 property .set$ref (null );
5764 return property ;
5865 }
5966 if (Integer .class .isAssignableFrom (wrappedType )) {
6067 property .type ("integer" );
6168 property .format ("int32" );
62- property .setDescription (displayName );
69+ property .setDescription (description );
6370 property .setProperties (null );
6471 property .set$ref (null );
6572 return property ;
6673 }
6774 if (Long .class .isAssignableFrom (wrappedType )) {
6875 property .type ("integer" );
6976 property .format ("int64" );
70- property .setDescription (displayName );
77+ property .setDescription (description );
7178 property .setProperties (null );
7279 property .set$ref (null );
7380 return property ;
7481 }
7582 if (BigInteger .class .isAssignableFrom (wrappedType )) {
7683 property .type ("integer" );
7784 property .format ("int64" );
78- property .setDescription (displayName );
85+ property .setDescription (description );
7986 property .setProperties (null );
8087 property .set$ref (null );
8188 return property ;
8289 }
8390 if (Float .class .isAssignableFrom (wrappedType )) {
8491 property .type ("number" );
8592 property .format ("float" );
86- property .setDescription (displayName );
93+ property .setDescription (description );
8794 property .setProperties (null );
8895 property .set$ref (null );
8996 return property ;
9097 }
9198 if (Double .class .isAssignableFrom (wrappedType )) {
9299 property .type ("number" );
93100 property .format ("double" );
94- property .setDescription (displayName );
101+ property .setDescription (description );
95102 property .setProperties (null );
96103 property .set$ref (null );
97104 return property ;
98105 }
99106 if (BigDecimal .class .isAssignableFrom (wrappedType )) {
100107 property .type ("number" );
101108 property .format ("" );
102- property .setDescription (displayName );
109+ property .setDescription (description );
103110 property .setProperties (null );
104111 property .set$ref (null );
105112 return property ;
@@ -108,15 +115,15 @@ public Schema<?> customize(Schema property, AnnotatedType annotatedType) {
108115 if (ScaledBigDecimal .class .isAssignableFrom (wrappedType )) {
109116 property .type ("number" );
110117 property .format ("" );
111- property .setDescription (displayName );
118+ property .setDescription (description );
112119 property .setProperties (null );
113120 property .set$ref (null );
114121 return property ;
115122 }
116123 if (String .class .isAssignableFrom (wrappedType )) {
117124 property .type ("string" );
118125 property .format (null );
119- property .setDescription (displayName );
126+ property .setDescription (description );
120127 property .setProperties (null );
121128 property .set$ref (null );
122129 return property ;
@@ -129,10 +136,11 @@ public Schema<?> customize(Schema property, AnnotatedType annotatedType) {
129136
130137 @ NonNull
131138 private static String resolveEntityIdDisplayName (Class <?> rawClass ) {
132- var parent = rawClass .getEnclosingClass ();
139+ return rawClass .getName ();
140+ /* var parent = rawClass.getEnclosingClass();
133141 if (parent != null) {
134142 return parent.getSimpleName() + "." + rawClass.getSimpleName();
135143 }
136- return rawClass .getSimpleName ();
144+ return rawClass.getSimpleName();*/
137145 }
138146}
0 commit comments