Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #1319 - fix validation #1322

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading