diff --git a/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java index ce31cc6c0d..f9fe4790c5 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java @@ -293,6 +293,7 @@ public void processOpts() { if (additionalProperties.containsKey(USE_BEANVALIDATION)) { this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); + writePropertyBack(USE_BEANVALIDATION, this.useBeanValidation); } if (additionalProperties.containsKey(USE_OPTIONAL)) { @@ -320,10 +321,10 @@ public void processOpts() { if (useBeanValidation) { writePropertyBack(USE_BEANVALIDATION, useBeanValidation); if (VALIDATION_MODE_LOOSE.equals(validationMode) || VALIDATION_MODE_STRICT.equals(validationMode)) { - supportingFiles.add(new SupportingFile("NotUndefined.mustache", - (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefined.java")); - supportingFiles.add(new SupportingFile("NotUndefinedValidator.mustache", - (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefinedValidator.java")); + writeOptional(outputFolder, new SupportingFile("NotUndefined.mustache", + (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefined.java"), true); + writeOptional(outputFolder, new SupportingFile("NotUndefinedValidator.mustache", + (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefinedValidator.java"), true); } } diff --git a/src/main/resources/handlebars/JavaSpring/model.mustache b/src/main/resources/handlebars/JavaSpring/model.mustache index 16c0b0228d..8fb655915c 100644 --- a/src/main/resources/handlebars/JavaSpring/model.mustache +++ b/src/main/resources/handlebars/JavaSpring/model.mustache @@ -11,11 +11,11 @@ import java.io.Serializable; import org.springframework.validation.annotation.Validated; {{#isLooseValidation}} import org.openapitools.jackson.nullable.JsonNullable; -import io.swagger.configuration.NotUndefined; +import {{configPackage}}.NotUndefined; {{/isLooseValidation}} {{#isStrictValidation}} import org.openapitools.jackson.nullable.JsonNullable; -import io.swagger.configuration.NotUndefined; +import {{configPackage}}.NotUndefined; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; diff --git a/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorTest.java b/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorTest.java index 84f91b8845..30c03e53c8 100644 --- a/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorTest.java +++ b/src/test/java/io/swagger/codegen/v3/generators/java/SpringGeneratorTest.java @@ -20,6 +20,9 @@ public class SpringGeneratorTest extends AbstractCodegenTest { @Test public void testGenerator() throws Exception { + System.setProperty("supportingFiles", "false"); + System.setProperty("generateModels", "true"); + System.setProperty("generateApis", "true"); String path = getOutFolder(false).getAbsolutePath(); GenerationRequest request = new GenerationRequest(); request @@ -32,13 +35,20 @@ public void testGenerator() throws Exception { false)) // OpenAPI 3.x - use true for Swagger/OpenAPI 2.x definitions .options( new Options() - // .library("spring-boot3") - // .addAdditionalProperty("jakarta", true) + .addAdditionalProperty("dateLibrary", "legacy") + .addAdditionalProperty("serializableModel", false) + .addAdditionalProperty("useTags", true) + .addAdditionalProperty("generateForOpenFeign", true) + .addAdditionalProperty("configPackage", "test.configPackage") + // .addAdditionalProperty("generateSupportingFiles", false) + .library("spring-cloud") + .addAdditionalProperty("jakarta", true) // .addAdditionalProperty("validationMode", "loose") // .addAdditionalProperty("validationMode", "legacy") // .addAdditionalProperty("validationMode", "legacyNullable") - // .addAdditionalProperty("useBeanValidation", false) + .addAdditionalProperty("useBeanValidation", false) // .addAdditionalProperty("useNullableForNotNull", false) + .modelPackage("test.foo") .outputDir(path) );