Skip to content

Commit

Permalink
fix and test
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-mfg committed Apr 2, 2024
1 parent 2934f5a commit 738e390
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{{#required}}{{^isReadOnly}} @NotNull
{{/isReadOnly}}{{/required}}{{>beanValidationCore}}
{{#required}}{{^isReadOnly}}@NotNull {{/isReadOnly}}{{/required}}{{#isContainer}}{{^isPrimitiveType}}{{^isEnum}}@Valid {{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}@Valid {{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtens
{{#vendorExtensions.x-field-extra-annotation}}
{{{vendorExtensions.x-field-extra-annotation}}}
{{/vendorExtensions.x-field-extra-annotation}}
private {{#useBeanValidation}}@Valid {{/useBeanValidation}}{{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
private {{#isContainer}}{{#useBeanValidation}}@Valid {{/useBeanValidation}}{{/isContainer}}{{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
{{/vars}}
{{#generateBuilders}}
{{^additionalProperties}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,31 @@ public void testHandleDefaultValue_issue8535() throws Exception {
.containsWithNameAndAttributes("DefaultValue", ImmutableMap.of("value", "\"true\""));
}

@Test
public void testValidAnnotation_issue14432() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/3_0/issue_14432.yaml", null, new ParseOptions()).getOpenAPI();

codegen.setOutputDir(output.getAbsolutePath());

ClientOptInput input = new ClientOptInput()
.openAPI(openAPI)
.config(codegen);

DefaultGenerator generator = new DefaultGenerator();
Map<String, File> files = generator.opts(input).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert.assertThat(files.get("ComplexObject.java"))
.fileContains("private @Valid List<LocalDate> dates")
.fileDoesNotContains("private @Valid SymbolTypeEnum symbolType")
.fileDoesNotContains("@Valid String")
.fileDoesNotContains("@Valid Double");
}

@Test
public void arrayNullableDefaultValueTests() throws Exception {
final File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
Expand Down
30 changes: 30 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue_14432.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
openapi: "3.0.3"
info:
title: "Demo models"
version: "1.0"
paths: {}
components:
schemas:
ComplexObject:
type: "object"
properties:
id:
type: "string"
probability:
type: "number"
format: "double"
dates:
type: "array"
items:
type: "string"
format: "date"
symbolType:
type: "string"
enum:
- "SYMBOL1"
- "SYMBOL2"
- "SYMBOL3"
ComplexArray:
type: array
items:
$ref: '#/components/schemas/ComplexObject'

0 comments on commit 738e390

Please sign in to comment.