[BUG] [Java Spring] Illegal date format in generated delegate examples
Created by: j0th
Description
The generated code (generator v4.1.2) for the example responses in an api delegate has illegal date formats for the properties of type "string" and format "date".
public interface DummyApiDelegate {
default Optional<NativeWebRequest> getRequest() {
return Optional.empty();
}
/**
* @see DummyApi#dummyGet
*/
default ResponseEntity<Result> dummyGet() {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
ApiUtil.setExampleResponse(request, "application/json", "{ \"attr1\" : \"2019-09-18T00:00:00.000+0000\"}");
break;
}
}
});
return new ResponseEntity<>(HttpStatus.valueOf(200));
}
}
openapi-generator version
4.1.2
OpenAPI declaration file content or url
openapi: 3.0.2
info:
title: Test for illegal date format in delegate examples
version: 1.0.0
paths:
/dummy:
get:
summary: just a dummy
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/result'
components:
schemas:
result:
description: the result with the illegal date format
type: object
properties:
attr1:
type: string
format: date
example: "2019-09-18"
Command line used for generation
docker run --rm -v %CD%:/local openapitools/openapi-generator-cli:v4.1.2 generate -i /local/test.yaml -g spring -o /local/testexample -c /local/config-test.json
The config-test.json looks like this:
{
"library": "spring-boot",
"delegatePattern": true,
"returnSuccessCode": true,
"hideGenerationTimestamp": true
}
Steps to reproduce
Just run the generator, you'll see
Related issues/PRs
Nothing found.
Suggest a fix
Not a fix , but a hint: The generated code have the expected date format:
- if I use version 3.3.4 of the generator-cli
- if I remove example: "2019-09-18" from attr1 (best solution for me, because I want to use version 4.x of the generator)
- if I remove type: string from attr1 (but the the type of the generated getter and setter is just object, not so good)
/**
* @see DummyApi#dummyGet
*/
default ResponseEntity<Result> dummyGet() {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
ApiUtil.setExampleResponse(request, "application/json", "{ \"attr1\" : \"2019-09-18\"}");
break;
}
}
});
return new ResponseEntity<>(HttpStatus.valueOf(200));
}