@@ -662,7 +662,11 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
662
662
}
663
663
664
664
for (var param : op .allParams ) {
665
- processGenericAnnotations (param .dataType , param .datatypeWithEnum , param .isArray , param .items , param .vendorExtensions );
665
+ processGenericAnnotations (param );
666
+ }
667
+ if (op .returnProperty != null ) {
668
+ processGenericAnnotations (op .returnProperty );
669
+ op .returnType = op .returnProperty .vendorExtensions .get ("typeWithEnumWithGenericAnnotations" ).toString ();
666
670
}
667
671
}
668
672
@@ -688,6 +692,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
688
692
689
693
if (op .isResponseFile ) {
690
694
op .returnType = typeMapping .get ("responseFile" );
695
+ op .returnProperty .dataType = op .returnType ;
696
+ op .returnProperty .datatypeWithEnum = op .returnType ;
691
697
op .imports .add (op .returnType );
692
698
}
693
699
@@ -806,14 +812,17 @@ private void wrapOperationReturnType(CodegenOperation op, String wrapperType, bo
806
812
originalReturnType = "Void" ;
807
813
op .returnProperty = new CodegenProperty ();
808
814
op .returnProperty .dataType = "Void" ;
815
+ op .returnProperty .openApiType = "" ;
809
816
}
810
817
newReturnType .dataType = typeName + '<' + originalReturnType + '>' ;
811
818
newReturnType .items = op .returnProperty ;
812
819
}
820
+ newReturnType .containerTypeMapped = typeName ;
821
+ newReturnType .containerType = typeName ;
813
822
op .vendorExtensions .put ("originalReturnType" , originalReturnType );
814
823
815
824
op .returnType = newReturnType .dataType ;
816
- op .returnContainer = null ;
825
+ op .returnContainer = newReturnType . containerTypeMapped ;
817
826
op .returnProperty = newReturnType ;
818
827
op .isArray = op .returnProperty .isArray ;
819
828
}
@@ -893,53 +902,57 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
893
902
property .vendorExtensions .put ("lombok" , lombok );
894
903
property .vendorExtensions .put ("defaultValueIsNotNull" , property .defaultValue != null && !property .defaultValue .equals ("null" ));
895
904
property .vendorExtensions .put ("isServer" , isServer );
896
- processGenericAnnotations (property . dataType , property . datatypeWithEnum , property . isArray , property . items , property . vendorExtensions );
905
+ processGenericAnnotations (property );
897
906
}
898
907
model .vendorExtensions .put ("isServer" , isServer );
899
908
for (var property : model .requiredVars ) {
900
909
property .vendorExtensions .put ("lombok" , lombok );
901
910
property .vendorExtensions .put ("isServer" , isServer );
902
911
property .vendorExtensions .put ("defaultValueIsNotNull" , property .defaultValue != null && !property .defaultValue .equals ("null" ));
903
- processGenericAnnotations (property . dataType , property . datatypeWithEnum , property . isArray , property . items , property . vendorExtensions );
912
+ processGenericAnnotations (property );
904
913
}
905
914
}
906
915
907
916
return objs ;
908
917
}
909
918
910
- private void processGenericAnnotations (String dataType , String dataTypeWithEnum , boolean isArray , CodegenProperty itemsProp , Map <String , Object > ext ) {
919
+ private void processGenericAnnotations (CodegenParameter parameter ) {
920
+ CodegenProperty items = parameter .isMap ? parameter .additionalProperties : parameter .items ;
921
+ String datatypeWithEnum = parameter .datatypeWithEnum == null ? parameter .dataType : parameter .datatypeWithEnum ;
922
+ processGenericAnnotations (parameter .dataType , datatypeWithEnum , parameter .isArray , parameter .isMap , parameter .containerTypeMapped , items , parameter .vendorExtensions );
923
+ }
924
+
925
+ private void processGenericAnnotations (CodegenProperty property ) {
926
+ CodegenProperty items = property .isMap ? property .additionalProperties : property .items ;
927
+ String datatypeWithEnum = property .datatypeWithEnum == null ? property .dataType : property .datatypeWithEnum ;
928
+ processGenericAnnotations (property .dataType , datatypeWithEnum , property .isArray , property .isMap , property .containerTypeMapped , items , property .vendorExtensions );
929
+ }
930
+
931
+ private void processGenericAnnotations (String dataType , String dataTypeWithEnum , boolean isArray , boolean isMap , String containerType , CodegenProperty itemsProp , Map <String , Object > ext ) {
911
932
var typeWithGenericAnnotations = dataType ;
912
933
var typeWithEnumWithGenericAnnotations = dataTypeWithEnum ;
913
- var addedGenericAnnotations = false ;
914
- if (useBeanValidation && isArray && itemsProp != null && isPrimitive (itemsProp .openApiType ) && dataType .contains ("<" )) {
915
- var genericAnnotations = genericAnnotations (itemsProp );
916
- if (itemsProp .isArray ) {
917
- processGenericAnnotations (itemsProp .dataType , itemsProp .datatypeWithEnum , true , itemsProp .items , itemsProp .vendorExtensions );
918
- typeWithGenericAnnotations = addGenericAnnotations ((String ) itemsProp .vendorExtensions .get ("typeWithGenericAnnotations" ), dataType , genericAnnotations );
919
- typeWithEnumWithGenericAnnotations = addGenericAnnotations ((String ) itemsProp .vendorExtensions .get ("typeWithEnumWithGenericAnnotations" ), dataTypeWithEnum , genericAnnotations );
920
- } else {
921
- typeWithGenericAnnotations = addGenericAnnotations (dataType , null , genericAnnotations );
922
- typeWithEnumWithGenericAnnotations = addGenericAnnotations (dataTypeWithEnum , null , genericAnnotations );
934
+ if (useBeanValidation && itemsProp != null && dataType .contains ("<" )) {
935
+ if (isMap ) {
936
+ var genericAnnotations = genericAnnotations (itemsProp );
937
+ processGenericAnnotations (itemsProp );
938
+ typeWithGenericAnnotations = "Map<String, " + genericAnnotations + itemsProp .vendorExtensions .get ("typeWithGenericAnnotations" ) + ">" ;
939
+ typeWithEnumWithGenericAnnotations = "Map<String, " + genericAnnotations + itemsProp .vendorExtensions .get ("typeWithEnumWithGenericAnnotations" ) + ">" ;
940
+ } else if (containerType != null ) {
941
+ var genericAnnotations = genericAnnotations (itemsProp );
942
+ processGenericAnnotations (itemsProp );
943
+ typeWithGenericAnnotations = containerType + "<" + genericAnnotations + itemsProp .vendorExtensions .get ("typeWithGenericAnnotations" ) + ">" ;
944
+ typeWithEnumWithGenericAnnotations = containerType + "<" + genericAnnotations + itemsProp .vendorExtensions .get ("typeWithEnumWithGenericAnnotations" ) + ">" ;
923
945
}
924
946
}
925
947
ext .put ("typeWithGenericAnnotations" , typeWithGenericAnnotations );
926
948
ext .put ("typeWithEnumWithGenericAnnotations" , typeWithEnumWithGenericAnnotations );
927
949
}
928
950
929
- private String addGenericAnnotations (String type , String wrapType , String genericAnnotations ) {
930
- if (StringUtils .isEmpty (type ) || StringUtils .isEmpty (genericAnnotations )) {
931
- return type ;
932
- }
933
- var t = wrapType != null ? wrapType : type ;
934
- var diamondOpen = t .indexOf ('<' );
935
- var diamondClose = t .lastIndexOf ('>' );
936
- var containerType = t .substring (0 , diamondOpen );
937
- var elementType = t .substring (diamondOpen + 1 , diamondClose );
938
- return containerType + '<' + genericAnnotations + (wrapType != null ? type : elementType ) + '>' ;
939
- }
940
-
941
951
private boolean isPrimitive (String type ) {
942
- return switch (type .toLowerCase ()) {
952
+ if (type == null ) {
953
+ return false ;
954
+ }
955
+ return switch (type ) {
943
956
case "array" , "string" , "boolean" , "byte" , "uri" , "url" , "uuid" , "email" , "integer" , "long" , "float" , "double" ,
944
957
"number" , "partial-time" , "date" , "date-time" , "bigdecimal" , "biginteger" -> true ;
945
958
default -> false ;
@@ -948,11 +961,19 @@ private boolean isPrimitive(String type) {
948
961
949
962
private String genericAnnotations (CodegenProperty prop ) {
950
963
951
- var type = prop .openApiType .toLowerCase ();
964
+ var type = prop .openApiType == null ? null : prop . openApiType .toLowerCase ();
952
965
953
966
var result = new StringBuilder ();
967
+
968
+ if (prop .isModel ) {
969
+ result .append ("@Valid " );
970
+ }
971
+ if (!isPrimitive (type )) {
972
+ return result .toString ();
973
+ }
974
+
954
975
if (StringUtils .isNotEmpty (prop .pattern )) {
955
- if (type . equals ( "email" )) {
976
+ if ("email" . equals ( type )) {
956
977
result .append ("@Email(regexp = \" " );
957
978
} else {
958
979
result .append ("@Pattern(regexp = \" " );
0 commit comments