OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Spring] generated date example results in JSON parse error

Open
#15,342 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.