Skip to content

Commit

Permalink
refs #1319 - fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Nov 4, 2024
1 parent 4d4fd87 commit 5e27d4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/handlebars/JavaSpring/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
);

Expand Down

0 comments on commit 5e27d4a

Please sign in to comment.