OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Spring] generated date example results in JSON parse error
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
We do have a openapi yaml which contains a property which is defined like that
dateOfOrder:
description: Date of the order
type: string
format: date
example: "2021-01-30"
the gernerated model class for spring boot looks like that
@NotNull @Valid
@Schema(name = "dateOfOrder", example = "Sat Jan 30 01:00:00 CET 2021", description = "Date of the order", required = true)
public Date getDateOfOrder() {
return dateOfOrder;
}
when I start a swagger-ui it produces a json example like this
{
"dateOfOrder": "Sat Jan 30 01:00:00 CET 2021"
}
when Im now trying to send this json without changing the date I get back
JSON parse error: Cannot deserialize value of type java.util.Datefrom String \"Sat Jan 30 01:00:00 CET 2021\": not a valid representation (error: Failed to parse Date value 'Sat Jan 30 01:00:00 CET 2021': Cannot parse date \"Sat Jan 30 01:00:00 CET 2021\": not compatible with any of standard forms (\"yyyy-MM-dd'T'HH:mm:ss.SSSX\", \"yyyy-MM-dd'T'HH:mm:ss.SSS\", \"EEE, dd MMM yyyy HH:mm:ss zzz\", \"yyyy-MM-dd\")); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of typejava.util.Datefrom String \"Sat Jan 30 01:00:00 CET 2021\": not a valid representation (error: Failed to parse Date value 'Sat Jan 30 01:00:00 CET 2021': Cannot parse date \"Sat Jan 30 01:00:00 CET 2021\": not compatible with any of standard forms (\"yyyy-MM-dd'T'HH:mm:ss.SSSX\", \"yyyy-MM-dd'T'HH:mm:ss.SSS\", \"EEE, dd MMM yyyy HH:mm:ss zzz\", \"yyyy-MM-dd\")
I expect that the dateOfOrder is equal to the example defined in the openapi.yaml or if the date has a different format it should be parsable.
Right now we are using the generator 6.4.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the OpenAPI YAML date property and the generated Spring model shown in the issue, then reproduce the Swagger UI JSON example and its deserialization error. Trace the Spring generator's date example handling; done means the generated example matches the OpenAPI value or uses a date format that the generated model can parse.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100