From c4123c071a72e3a306a19325799febe29be5c650 Mon Sep 17 00:00:00 2001 From: thiswasdumb Date: Thu, 23 Apr 2026 23:34:20 +0100 Subject: [PATCH 1/5] Adding logic and verifying with test which ensures @NotNull is generated for objects containing required fields --- .../codegen/languages/SpringCodegen.java | 4 +- .../java/spring/SpringCodegenTest.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index e6a150c4e21a..5e2b1552d7b8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -430,8 +430,6 @@ public void processOpts() { documentationProvider = DocumentationProvider.NONE; annotationLibrary = AnnotationLibrary.NONE; useJakartaEe = true; - useBeanValidation = false; - performBeanValidation = false; additionalProperties.put(USE_JAKARTA_EE, useJakartaEe); additionalProperties.put(USE_BEANVALIDATION, useBeanValidation); @@ -443,7 +441,7 @@ public void processOpts() { applyJakartaPackage(); - LOGGER.warn("For Spring HTTP Interface following options are disabled: documentProvider, annotationLibrary, useBeanValidation, performBeanValidation. " + LOGGER.warn("For Spring HTTP Interface following options are disabled: documentProvider, annotationLibrary. " + "useJakartaEe defaulted to 'true'"); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 96444d9aee77..3da8a28326eb 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -6664,4 +6664,42 @@ public void testJspecify(String library, int springBootVersion, String fooApiFil JavaFileAssert.assertThat(files.get("model/package-info.java")) .fileContains("@org.jspecify.annotations.NullMarked"); } + + @Test + public void useBeanValidationTrueWithSpringHttpInterface() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/petstore.yaml", null, new ParseOptions()) + .getOpenAPI(); + + SpringCodegen codegen = new SpringCodegen(); + codegen.setLibrary(SPRING_HTTP_INTERFACE); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.setUseBeanValidation(true); + codegen.setPerformBeanValidation(true); + codegen.setUseSpringBoot3(true); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + generator.setGenerateMetadata(false); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + + generator.opts(input).generate(); + + Path pet = Paths.get( + output.getAbsolutePath(), + "src/main/java/org/openapitools/model/Pet.java" + ); + + String content = Files.readString(pet); + + assertThat(content).contains("@NotNull"); + } } From c9ede045d75e1d111ce03a24db88f318164fdfab Mon Sep 17 00:00:00 2001 From: thiswasdumb Date: Fri, 24 Apr 2026 22:34:37 +0100 Subject: [PATCH 2/5] Adding samples for pipeline --- .../src/main/java/org/openapitools/api/UserApi.java | 4 ++-- .../main/java/org/openapitools/model/ArrayTestDto.java | 10 +++++----- .../org/openapitools/model/FileSchemaTestClassDto.java | 8 ++++---- .../src/main/java/org/openapitools/model/PetDto.java | 8 ++++---- .../main/java/org/openapitools/model/ArrayTest.java | 10 +++++----- .../org/openapitools/model/FileSchemaTestClass.java | 8 ++++---- .../src/main/java/org/openapitools/model/Pet.java | 8 ++++---- .../main/java/org/openapitools/model/ArrayTest.java | 10 +++++----- .../org/openapitools/model/FileSchemaTestClass.java | 8 ++++---- .../src/main/java/org/openapitools/model/Pet.java | 8 ++++---- .../src/main/java/org/openapitools/api/UserApi.java | 4 ++-- .../main/java/org/openapitools/model/ArrayTestDto.java | 10 +++++----- .../org/openapitools/model/FileSchemaTestClassDto.java | 8 ++++---- .../src/main/java/org/openapitools/model/PetDto.java | 8 ++++---- .../src/main/java/org/openapitools/api/UserApi.java | 4 ++-- .../main/java/org/openapitools/model/ArrayTestDto.java | 10 +++++----- .../org/openapitools/model/FileSchemaTestClassDto.java | 8 ++++---- .../src/main/java/org/openapitools/model/PetDto.java | 8 ++++---- 18 files changed, 71 insertions(+), 71 deletions(-) diff --git a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/api/UserApi.java b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/api/UserApi.java index 420027cf0c52..65e22573a3e4 100644 --- a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/api/UserApi.java +++ b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/api/UserApi.java @@ -55,7 +55,7 @@ void createUser( contentType = "application/json" ) void createUsersWithArrayInput( - @RequestBody List userDto + @RequestBody List<@Valid UserDto> userDto ); @@ -74,7 +74,7 @@ void createUsersWithArrayInput( contentType = "application/json" ) void createUsersWithListInput( - @RequestBody List userDto + @RequestBody List<@Valid UserDto> userDto ); diff --git a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ArrayTestDto.java b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ArrayTestDto.java index 377f9f0c2202..7426e9b5acd8 100644 --- a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ArrayTestDto.java +++ b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ArrayTestDto.java @@ -33,7 +33,7 @@ public class ArrayTestDto { private List> arrayArrayOfInteger = new ArrayList<>(); - private List> arrayArrayOfModel = new ArrayList<>(); + private List> arrayArrayOfModel = new ArrayList<>(); public ArrayTestDto arrayOfString(List arrayOfString) { this.arrayOfString = arrayOfString; @@ -91,12 +91,12 @@ public void setArrayArrayOfInteger(List> arrayArrayOfInteger) { this.arrayArrayOfInteger = arrayArrayOfInteger; } - public ArrayTestDto arrayArrayOfModel(List> arrayArrayOfModel) { + public ArrayTestDto arrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; return this; } - public ArrayTestDto addArrayArrayOfModelItem(List arrayArrayOfModelItem) { + public ArrayTestDto addArrayArrayOfModelItem(List<@Valid ReadOnlyFirstDto> arrayArrayOfModelItem) { if (this.arrayArrayOfModel == null) { this.arrayArrayOfModel = new ArrayList<>(); } @@ -110,12 +110,12 @@ public ArrayTestDto addArrayArrayOfModelItem(List arrayArrayOf */ @JsonProperty("array_array_of_model") - public List> getArrayArrayOfModel() { + public List> getArrayArrayOfModel() { return arrayArrayOfModel; } @JsonProperty("array_array_of_model") - public void setArrayArrayOfModel(List> arrayArrayOfModel) { + public void setArrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; } diff --git a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java index 0a861be1a6ee..f3bef2ce367f 100644 --- a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java +++ b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java @@ -29,7 +29,7 @@ public class FileSchemaTestClassDto { private @Nullable FileDto file; - private List files = new ArrayList<>(); + private List<@Valid FileDto> files = new ArrayList<>(); public FileSchemaTestClassDto file(@Nullable FileDto file) { this.file = file; @@ -51,7 +51,7 @@ public void setFile(@Nullable FileDto file) { this.file = file; } - public FileSchemaTestClassDto files(List files) { + public FileSchemaTestClassDto files(List<@Valid FileDto> files) { this.files = files; return this; } @@ -70,12 +70,12 @@ public FileSchemaTestClassDto addFilesItem(FileDto filesItem) { */ @JsonProperty("files") - public List getFiles() { + public List<@Valid FileDto> getFiles() { return files; } @JsonProperty("files") - public void setFiles(List files) { + public void setFiles(List<@Valid FileDto> files) { this.files = files; } diff --git a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/PetDto.java b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/PetDto.java index 8b0168d11ba8..6f208df0d648 100644 --- a/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/PetDto.java +++ b/samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/PetDto.java @@ -41,7 +41,7 @@ public class PetDto { private Set photoUrls = new LinkedHashSet<>(); - private List tags = new ArrayList<>(); + private List<@Valid TagDto> tags = new ArrayList<>(); /** * pet status in the store @@ -176,7 +176,7 @@ public void setPhotoUrls(Set photoUrls) { this.photoUrls = photoUrls; } - public PetDto tags(List tags) { + public PetDto tags(List<@Valid TagDto> tags) { this.tags = tags; return this; } @@ -195,12 +195,12 @@ public PetDto addTagsItem(TagDto tagsItem) { */ @JsonProperty("tags") - public List getTags() { + public List<@Valid TagDto> getTags() { return tags; } @JsonProperty("tags") - public void setTags(List tags) { + public void setTags(List<@Valid TagDto> tags) { this.tags = tags; } diff --git a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ArrayTest.java b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ArrayTest.java index f924e495e51c..92f6754e306d 100644 --- a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ArrayTest.java +++ b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ArrayTest.java @@ -31,7 +31,7 @@ public class ArrayTest { private List> arrayArrayOfInteger = new ArrayList<>(); - private List> arrayArrayOfModel = new ArrayList<>(); + private List> arrayArrayOfModel = new ArrayList<>(); public ArrayTest arrayOfString(List arrayOfString) { this.arrayOfString = arrayOfString; @@ -89,12 +89,12 @@ public void setArrayArrayOfInteger(List> arrayArrayOfInteger) { this.arrayArrayOfInteger = arrayArrayOfInteger; } - public ArrayTest arrayArrayOfModel(List> arrayArrayOfModel) { + public ArrayTest arrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; return this; } - public ArrayTest addArrayArrayOfModelItem(List arrayArrayOfModelItem) { + public ArrayTest addArrayArrayOfModelItem(List<@Valid ReadOnlyFirst> arrayArrayOfModelItem) { if (this.arrayArrayOfModel == null) { this.arrayArrayOfModel = new ArrayList<>(); } @@ -108,12 +108,12 @@ public ArrayTest addArrayArrayOfModelItem(List arrayArrayOfModelI */ @JsonProperty("array_array_of_model") - public List> getArrayArrayOfModel() { + public List> getArrayArrayOfModel() { return arrayArrayOfModel; } @JsonProperty("array_array_of_model") - public void setArrayArrayOfModel(List> arrayArrayOfModel) { + public void setArrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; } diff --git a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClass.java b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClass.java index fbf04675218c..2acc2ab14971 100644 --- a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClass.java +++ b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/FileSchemaTestClass.java @@ -27,7 +27,7 @@ public class FileSchemaTestClass { private @Nullable File file; - private List files = new ArrayList<>(); + private List<@Valid File> files = new ArrayList<>(); public FileSchemaTestClass file(@Nullable File file) { this.file = file; @@ -49,7 +49,7 @@ public void setFile(@Nullable File file) { this.file = file; } - public FileSchemaTestClass files(List files) { + public FileSchemaTestClass files(List<@Valid File> files) { this.files = files; return this; } @@ -68,12 +68,12 @@ public FileSchemaTestClass addFilesItem(File filesItem) { */ @JsonProperty("files") - public List getFiles() { + public List<@Valid File> getFiles() { return files; } @JsonProperty("files") - public void setFiles(List files) { + public void setFiles(List<@Valid File> files) { this.files = files; } diff --git a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/Pet.java b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/Pet.java index 83498b044d67..ac1ed83c31ed 100644 --- a/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/Pet.java +++ b/samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/Pet.java @@ -39,7 +39,7 @@ public class Pet { private Set photoUrls = new LinkedHashSet<>(); - private List tags = new ArrayList<>(); + private List<@Valid Tag> tags = new ArrayList<>(); /** * pet status in the store @@ -182,7 +182,7 @@ public void setPhotoUrls(Set photoUrls) { this.photoUrls = photoUrls; } - public Pet tags(List tags) { + public Pet tags(List<@Valid Tag> tags) { this.tags = tags; return this; } @@ -201,12 +201,12 @@ public Pet addTagsItem(Tag tagsItem) { */ @JsonProperty("tags") - public List getTags() { + public List<@Valid Tag> getTags() { return tags; } @JsonProperty("tags") - public void setTags(List tags) { + public void setTags(List<@Valid Tag> tags) { this.tags = tags; } diff --git a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ArrayTest.java b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ArrayTest.java index f924e495e51c..92f6754e306d 100644 --- a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ArrayTest.java +++ b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ArrayTest.java @@ -31,7 +31,7 @@ public class ArrayTest { private List> arrayArrayOfInteger = new ArrayList<>(); - private List> arrayArrayOfModel = new ArrayList<>(); + private List> arrayArrayOfModel = new ArrayList<>(); public ArrayTest arrayOfString(List arrayOfString) { this.arrayOfString = arrayOfString; @@ -89,12 +89,12 @@ public void setArrayArrayOfInteger(List> arrayArrayOfInteger) { this.arrayArrayOfInteger = arrayArrayOfInteger; } - public ArrayTest arrayArrayOfModel(List> arrayArrayOfModel) { + public ArrayTest arrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; return this; } - public ArrayTest addArrayArrayOfModelItem(List arrayArrayOfModelItem) { + public ArrayTest addArrayArrayOfModelItem(List<@Valid ReadOnlyFirst> arrayArrayOfModelItem) { if (this.arrayArrayOfModel == null) { this.arrayArrayOfModel = new ArrayList<>(); } @@ -108,12 +108,12 @@ public ArrayTest addArrayArrayOfModelItem(List arrayArrayOfModelI */ @JsonProperty("array_array_of_model") - public List> getArrayArrayOfModel() { + public List> getArrayArrayOfModel() { return arrayArrayOfModel; } @JsonProperty("array_array_of_model") - public void setArrayArrayOfModel(List> arrayArrayOfModel) { + public void setArrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; } diff --git a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/FileSchemaTestClass.java b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/FileSchemaTestClass.java index fbf04675218c..2acc2ab14971 100644 --- a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/FileSchemaTestClass.java +++ b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/FileSchemaTestClass.java @@ -27,7 +27,7 @@ public class FileSchemaTestClass { private @Nullable File file; - private List files = new ArrayList<>(); + private List<@Valid File> files = new ArrayList<>(); public FileSchemaTestClass file(@Nullable File file) { this.file = file; @@ -49,7 +49,7 @@ public void setFile(@Nullable File file) { this.file = file; } - public FileSchemaTestClass files(List files) { + public FileSchemaTestClass files(List<@Valid File> files) { this.files = files; return this; } @@ -68,12 +68,12 @@ public FileSchemaTestClass addFilesItem(File filesItem) { */ @JsonProperty("files") - public List getFiles() { + public List<@Valid File> getFiles() { return files; } @JsonProperty("files") - public void setFiles(List files) { + public void setFiles(List<@Valid File> files) { this.files = files; } diff --git a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/Pet.java b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/Pet.java index 83498b044d67..ac1ed83c31ed 100644 --- a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/Pet.java +++ b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/Pet.java @@ -39,7 +39,7 @@ public class Pet { private Set photoUrls = new LinkedHashSet<>(); - private List tags = new ArrayList<>(); + private List<@Valid Tag> tags = new ArrayList<>(); /** * pet status in the store @@ -182,7 +182,7 @@ public void setPhotoUrls(Set photoUrls) { this.photoUrls = photoUrls; } - public Pet tags(List tags) { + public Pet tags(List<@Valid Tag> tags) { this.tags = tags; return this; } @@ -201,12 +201,12 @@ public Pet addTagsItem(Tag tagsItem) { */ @JsonProperty("tags") - public List getTags() { + public List<@Valid Tag> getTags() { return tags; } @JsonProperty("tags") - public void setTags(List tags) { + public void setTags(List<@Valid Tag> tags) { this.tags = tags; } diff --git a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/api/UserApi.java b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/api/UserApi.java index 0f64f3586cd3..f38bef23d0a0 100644 --- a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/api/UserApi.java +++ b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/api/UserApi.java @@ -53,7 +53,7 @@ ResponseEntity createUser( contentType = "application/json" ) ResponseEntity createUsersWithArrayInput( - @RequestBody List userDto + @RequestBody List<@Valid UserDto> userDto ); @@ -71,7 +71,7 @@ ResponseEntity createUsersWithArrayInput( contentType = "application/json" ) ResponseEntity createUsersWithListInput( - @RequestBody List userDto + @RequestBody List<@Valid UserDto> userDto ); diff --git a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ArrayTestDto.java b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ArrayTestDto.java index 311c30a1ce5d..fb23558f92f5 100644 --- a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ArrayTestDto.java +++ b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/ArrayTestDto.java @@ -32,7 +32,7 @@ public class ArrayTestDto { private List> arrayArrayOfInteger = new ArrayList<>(); - private List> arrayArrayOfModel = new ArrayList<>(); + private List> arrayArrayOfModel = new ArrayList<>(); public ArrayTestDto arrayOfString(List arrayOfString) { this.arrayOfString = arrayOfString; @@ -90,12 +90,12 @@ public void setArrayArrayOfInteger(List> arrayArrayOfInteger) { this.arrayArrayOfInteger = arrayArrayOfInteger; } - public ArrayTestDto arrayArrayOfModel(List> arrayArrayOfModel) { + public ArrayTestDto arrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; return this; } - public ArrayTestDto addArrayArrayOfModelItem(List arrayArrayOfModelItem) { + public ArrayTestDto addArrayArrayOfModelItem(List<@Valid ReadOnlyFirstDto> arrayArrayOfModelItem) { if (this.arrayArrayOfModel == null) { this.arrayArrayOfModel = new ArrayList<>(); } @@ -109,12 +109,12 @@ public ArrayTestDto addArrayArrayOfModelItem(List arrayArrayOf */ @JsonProperty("array_array_of_model") - public List> getArrayArrayOfModel() { + public List> getArrayArrayOfModel() { return arrayArrayOfModel; } @JsonProperty("array_array_of_model") - public void setArrayArrayOfModel(List> arrayArrayOfModel) { + public void setArrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; } diff --git a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java index 46226dd697ac..1e4bf38fe0c0 100644 --- a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java +++ b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java @@ -28,7 +28,7 @@ public class FileSchemaTestClassDto { private @Nullable FileDto file; - private List files = new ArrayList<>(); + private List<@Valid FileDto> files = new ArrayList<>(); public FileSchemaTestClassDto file(@Nullable FileDto file) { this.file = file; @@ -50,7 +50,7 @@ public void setFile(@Nullable FileDto file) { this.file = file; } - public FileSchemaTestClassDto files(List files) { + public FileSchemaTestClassDto files(List<@Valid FileDto> files) { this.files = files; return this; } @@ -69,12 +69,12 @@ public FileSchemaTestClassDto addFilesItem(FileDto filesItem) { */ @JsonProperty("files") - public List getFiles() { + public List<@Valid FileDto> getFiles() { return files; } @JsonProperty("files") - public void setFiles(List files) { + public void setFiles(List<@Valid FileDto> files) { this.files = files; } diff --git a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/PetDto.java b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/PetDto.java index 356f8201de97..178e57c7fec1 100644 --- a/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/PetDto.java +++ b/samples/client/petstore/spring-http-interface-springboot-4/src/main/java/org/openapitools/model/PetDto.java @@ -40,7 +40,7 @@ public class PetDto { private Set photoUrls = new LinkedHashSet<>(); - private List tags = new ArrayList<>(); + private List<@Valid TagDto> tags = new ArrayList<>(); /** * pet status in the store @@ -175,7 +175,7 @@ public void setPhotoUrls(Set photoUrls) { this.photoUrls = photoUrls; } - public PetDto tags(List tags) { + public PetDto tags(List<@Valid TagDto> tags) { this.tags = tags; return this; } @@ -194,12 +194,12 @@ public PetDto addTagsItem(TagDto tagsItem) { */ @JsonProperty("tags") - public List getTags() { + public List<@Valid TagDto> getTags() { return tags; } @JsonProperty("tags") - public void setTags(List tags) { + public void setTags(List<@Valid TagDto> tags) { this.tags = tags; } diff --git a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/UserApi.java b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/UserApi.java index 0f64f3586cd3..f38bef23d0a0 100644 --- a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/UserApi.java +++ b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/UserApi.java @@ -53,7 +53,7 @@ ResponseEntity createUser( contentType = "application/json" ) ResponseEntity createUsersWithArrayInput( - @RequestBody List userDto + @RequestBody List<@Valid UserDto> userDto ); @@ -71,7 +71,7 @@ ResponseEntity createUsersWithArrayInput( contentType = "application/json" ) ResponseEntity createUsersWithListInput( - @RequestBody List userDto + @RequestBody List<@Valid UserDto> userDto ); diff --git a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ArrayTestDto.java b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ArrayTestDto.java index 377f9f0c2202..7426e9b5acd8 100644 --- a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ArrayTestDto.java +++ b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/ArrayTestDto.java @@ -33,7 +33,7 @@ public class ArrayTestDto { private List> arrayArrayOfInteger = new ArrayList<>(); - private List> arrayArrayOfModel = new ArrayList<>(); + private List> arrayArrayOfModel = new ArrayList<>(); public ArrayTestDto arrayOfString(List arrayOfString) { this.arrayOfString = arrayOfString; @@ -91,12 +91,12 @@ public void setArrayArrayOfInteger(List> arrayArrayOfInteger) { this.arrayArrayOfInteger = arrayArrayOfInteger; } - public ArrayTestDto arrayArrayOfModel(List> arrayArrayOfModel) { + public ArrayTestDto arrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; return this; } - public ArrayTestDto addArrayArrayOfModelItem(List arrayArrayOfModelItem) { + public ArrayTestDto addArrayArrayOfModelItem(List<@Valid ReadOnlyFirstDto> arrayArrayOfModelItem) { if (this.arrayArrayOfModel == null) { this.arrayArrayOfModel = new ArrayList<>(); } @@ -110,12 +110,12 @@ public ArrayTestDto addArrayArrayOfModelItem(List arrayArrayOf */ @JsonProperty("array_array_of_model") - public List> getArrayArrayOfModel() { + public List> getArrayArrayOfModel() { return arrayArrayOfModel; } @JsonProperty("array_array_of_model") - public void setArrayArrayOfModel(List> arrayArrayOfModel) { + public void setArrayArrayOfModel(List> arrayArrayOfModel) { this.arrayArrayOfModel = arrayArrayOfModel; } diff --git a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java index 0a861be1a6ee..f3bef2ce367f 100644 --- a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java +++ b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/FileSchemaTestClassDto.java @@ -29,7 +29,7 @@ public class FileSchemaTestClassDto { private @Nullable FileDto file; - private List files = new ArrayList<>(); + private List<@Valid FileDto> files = new ArrayList<>(); public FileSchemaTestClassDto file(@Nullable FileDto file) { this.file = file; @@ -51,7 +51,7 @@ public void setFile(@Nullable FileDto file) { this.file = file; } - public FileSchemaTestClassDto files(List files) { + public FileSchemaTestClassDto files(List<@Valid FileDto> files) { this.files = files; return this; } @@ -70,12 +70,12 @@ public FileSchemaTestClassDto addFilesItem(FileDto filesItem) { */ @JsonProperty("files") - public List getFiles() { + public List<@Valid FileDto> getFiles() { return files; } @JsonProperty("files") - public void setFiles(List files) { + public void setFiles(List<@Valid FileDto> files) { this.files = files; } diff --git a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/PetDto.java b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/PetDto.java index 8b0168d11ba8..6f208df0d648 100644 --- a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/PetDto.java +++ b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/PetDto.java @@ -41,7 +41,7 @@ public class PetDto { private Set photoUrls = new LinkedHashSet<>(); - private List tags = new ArrayList<>(); + private List<@Valid TagDto> tags = new ArrayList<>(); /** * pet status in the store @@ -176,7 +176,7 @@ public void setPhotoUrls(Set photoUrls) { this.photoUrls = photoUrls; } - public PetDto tags(List tags) { + public PetDto tags(List<@Valid TagDto> tags) { this.tags = tags; return this; } @@ -195,12 +195,12 @@ public PetDto addTagsItem(TagDto tagsItem) { */ @JsonProperty("tags") - public List getTags() { + public List<@Valid TagDto> getTags() { return tags; } @JsonProperty("tags") - public void setTags(List tags) { + public void setTags(List<@Valid TagDto> tags) { this.tags = tags; } From 820dfc352ab24894ed549732daa23ecf6775fbaa Mon Sep 17 00:00:00 2001 From: thiswasdumb Date: Tue, 28 Apr 2026 00:16:21 +0100 Subject: [PATCH 3/5] Updating error in build due to forced bean setting --- .../java/org/openapitools/codegen/languages/SpringCodegen.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index 5e2b1552d7b8..4da65a6b993d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -639,7 +639,6 @@ public void processOpts() { supportingFiles.add(new SupportingFile(httpInterfacesAbstractConfiguratorFile, (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HttpInterfacesAbstractConfigurator.java")); - writePropertyBack(USE_BEANVALIDATION, false); writePropertyBack(HTTP_INTERFACES_CONFIGURATOR_DEPENDENCY, useHttpServiceProxyFactoryInterfacesConfigurator ? From ca60f58e427c17094abb66a63f07e9bacd0869b9 Mon Sep 17 00:00:00 2001 From: thiswasdumb Date: Tue, 28 Apr 2026 00:24:54 +0100 Subject: [PATCH 4/5] Trying to fix by setting as expected Co-authored-by: Copilot --- .../codegen/languages/SpringCodegen.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index 4da65a6b993d..04afa5d93099 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -430,6 +430,26 @@ public void processOpts() { documentationProvider = DocumentationProvider.NONE; annotationLibrary = AnnotationLibrary.NONE; useJakartaEe = true; + if (!additionalProperties.containsKey(USE_BEANVALIDATION)) { + useBeanValidation = false; + } else { + Object beanValidationValue = additionalProperties.get(USE_BEANVALIDATION); + if (beanValidationValue instanceof Boolean) { + useBeanValidation = (Boolean) beanValidationValue; + } else if (beanValidationValue instanceof String) { + useBeanValidation = Boolean.parseBoolean((String) beanValidationValue); + } + } + if (!additionalProperties.containsKey(PERFORM_BEANVALIDATION)) { + performBeanValidation = false; + } else { + Object performBeanValidationValue = additionalProperties.get(PERFORM_BEANVALIDATION); + if (performBeanValidationValue instanceof Boolean) { + performBeanValidation = (Boolean) performBeanValidationValue; + } else if (performBeanValidationValue instanceof String) { + performBeanValidation = Boolean.parseBoolean((String) performBeanValidationValue); + } + } additionalProperties.put(USE_JAKARTA_EE, useJakartaEe); additionalProperties.put(USE_BEANVALIDATION, useBeanValidation); From 4888232751218b5eb04042a68cc7649a5c1310a5 Mon Sep 17 00:00:00 2001 From: thiswasdumb Date: Tue, 28 Apr 2026 00:36:26 +0100 Subject: [PATCH 5/5] Addressing comment Co-authored-by: Copilot --- .../codegen/languages/SpringCodegen.java | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index 04afa5d93099..dd98755abe23 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -430,25 +430,14 @@ public void processOpts() { documentationProvider = DocumentationProvider.NONE; annotationLibrary = AnnotationLibrary.NONE; useJakartaEe = true; - if (!additionalProperties.containsKey(USE_BEANVALIDATION)) { - useBeanValidation = false; - } else { - Object beanValidationValue = additionalProperties.get(USE_BEANVALIDATION); - if (beanValidationValue instanceof Boolean) { - useBeanValidation = (Boolean) beanValidationValue; - } else if (beanValidationValue instanceof String) { - useBeanValidation = Boolean.parseBoolean((String) beanValidationValue); - } + + if (configOptions.stream().noneMatch(opt -> USE_BEANVALIDATION.equals(opt.getLeft()))) { + Object val = additionalProperties.get(USE_BEANVALIDATION); + useBeanValidation = val instanceof Boolean ? (Boolean) val : Boolean.parseBoolean(val.toString()); } - if (!additionalProperties.containsKey(PERFORM_BEANVALIDATION)) { - performBeanValidation = false; - } else { - Object performBeanValidationValue = additionalProperties.get(PERFORM_BEANVALIDATION); - if (performBeanValidationValue instanceof Boolean) { - performBeanValidation = (Boolean) performBeanValidationValue; - } else if (performBeanValidationValue instanceof String) { - performBeanValidation = Boolean.parseBoolean((String) performBeanValidationValue); - } + if (configOptions.stream().noneMatch(opt -> PERFORM_BEANVALIDATION.equals(opt.getLeft()))) { + Object val = additionalProperties.get(PERFORM_BEANVALIDATION); + performBeanValidation = val instanceof Boolean ? (Boolean) val : Boolean.parseBoolean(val.toString()); } additionalProperties.put(USE_JAKARTA_EE, useJakartaEe);