Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add date time format annotation on pojo for model query parameters
  • Loading branch information
zalito12 committed Mar 3, 2020
commit 2df7b2b7d1e466ce9abe5019c684eb6c163fbd3a
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}}{{^parent}}
private {{>nullableDataType}} {{name}} = {{#isNullable}}JsonNullable.undefined(){{/isNullable}}{{^isNullable}}{{#required}}{{{defaultValue}}}{{/required}}{{^required}}null{{/required}}{{/isNullable}};
{{/isContainer}}
{{^isContainer}}
{{#isDate}}
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
{{/isDate}}
{{#isDateTime}}
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
{{/isDateTime}}
private {{>nullableDataType}} {{name}}{{#isNullable}} = JsonNullable.undefined(){{/isNullable}}{{^isNullable}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/isNullable}};
{{/isContainer}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,31 @@ public void doGenerateCookieParams() throws IOException {
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/ZebrasApi.java", "@CookieValue");
checkFileNotContains(generator, outputPath + "/src/main/java/org/openapitools/api/BirdsApi.java", "@CookieValue");
}

@Test
public void doAnnotateDatesOnModelParameters() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');

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

SpringCodegen codegen = new SpringCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");

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

MockDefaultGenerator generator = new MockDefaultGenerator();
generator.opts(input).generate();

checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/api/ZebrasApi.java",
"AnimalParams");
checkFileContains(generator, outputPath + "/src/main/java/org/openapitools/model/AnimalParams.java",
"@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)",
"@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)");
}
}
51 changes: 51 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue_5436.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
openapi: 3.0.0
servers:
- url: 'localhost:8080'
info:
version: 1.0.0
title: OpenAPI Zoo
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/zebras:
get:
operationId: getZebras
parameters:
- in: query
name: limit
schema:
type: number
- $ref: '#/components/parameters/SearchParams'
components:
parameters:
SearchParams:
name: animalParams
description: Search animal grouped parameters
in: query
style: form
explode: true
schema:
$ref: '#/components/schemas/AnimalParams'
schemas:
AnimalParams:
type: object
properties:
born:
type: string
format: date
example: '2019-12-01'
lastSeen:
type: string
format: date-time
example: '2020-02-22T10:30:00.000'
status:
type: integer
enum: [0,1]
default: 0
name:
type: string
example: 'Marty'
age:
type: integer
example: 15