@@ -984,10 +984,7 @@ public CodegenModel fromModel(String name, Schema model) {
984984 codegenModel .imports .remove ("Schema" );
985985 }
986986
987- // Add Nullable import for all models including array-type models (issue #22788)
988- if (getName ().contains ("spring" )) {
989- codegenModel .imports .add ("Nullable" );
990- }
987+ addSpringNullableImport (codegenModel .imports );
991988
992989 return codegenModel ;
993990 }
@@ -1052,11 +1049,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
10521049 codegenOperation .imports .addAll (provideArgsClassSet );
10531050 }
10541051
1055- // to prevent inheritors (JavaCamelServerCodegen etc.) mistakenly use it
1056- if (getName ().contains ("spring" )) {
1057- codegenOperation .allParams .stream ().filter (CodegenParameter ::notRequiredOrIsNullable ).findAny ()
1058- .ifPresent (p -> codegenOperation .imports .add ("Nullable" ));
1059- }
1052+ addSpringNullableImportForOperation (codegenOperation );
10601053
10611054 if (reactive ) {
10621055 if (DocumentationProvider .SPRINGFOX .equals (getDocumentationProvider ())) {
@@ -1219,4 +1212,23 @@ public List<VendorExtension> getSupportedVendorExtensions() {
12191212 extensions .add (VendorExtension .X_SPRING_API_VERSION );
12201213 return extensions ;
12211214 }
1215+
1216+ private boolean isSpringCodegen () {
1217+ return getName ().contains ("spring" );
1218+ }
1219+
1220+ private void addSpringNullableImport (Set <String > imports ) {
1221+ if (isSpringCodegen ()) {
1222+ imports .add ("Nullable" );
1223+ }
1224+ }
1225+
1226+ private void addSpringNullableImportForOperation (CodegenOperation codegenOperation ) {
1227+ if (isSpringCodegen ()) {
1228+ codegenOperation .allParams .stream ()
1229+ .filter (CodegenParameter ::notRequiredOrIsNullable )
1230+ .findAny ()
1231+ .ifPresent (param -> codegenOperation .imports .add ("Nullable" ));
1232+ }
1233+ }
12221234}
0 commit comments