forked from loafle/openapi-generator-original
Add date time format annotation on pojo for model query parameters (#5437)
* Add date time format annotation on pojo for model query parameters * Regenetare samples * update spring samples Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
@@ -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}}
|
||||
|
||||
|
||||
@@ -544,4 +544,31 @@ public class SpringCodegenTest {
|
||||
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)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -27,6 +27,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private LocalDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private LocalDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private LocalDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormatTest {
|
||||
private Resource binary;
|
||||
|
||||
@JsonProperty("date")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)
|
||||
private LocalDate date;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("uuid")
|
||||
|
||||
@@ -24,6 +24,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
|
||||
private UUID uuid;
|
||||
|
||||
@JsonProperty("dateTime")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime dateTime;
|
||||
|
||||
@JsonProperty("map")
|
||||
|
||||
@@ -26,6 +26,7 @@ public class Order {
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user