swagger-api / swagger-api/swagger-codegen

Java bug generating proper formatting for date fields

Open
#11,992 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The Java client code being generated for fields defined with format 'date' in OAS3 and a pattern of "YYYY-MM-DD" are working properly. Specifically, even with explicitly setting the export configuration to use Java 11 JSR384 and use Jackson. there is no reference to Jackson in the java file and the Java type is java.util.Date, with no formatting and the getXXX method returns a long/integer.

Swagger-codegen version

The current version being provided on https://app.swaggerhub.com

Swagger declaration file content or url

birthdate:
type: string
format: date
pattern: "YYYY-MM-DD"
example: "1995-01-01"

Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

The only workaround is to manually alter the Java code generated by swagger code-gen with the following Jackson annotations. However, this is very brittle and breaks the general rule never to alter auto-generated code. It also means our CI/CD flow won't work automatically without reverting the workaround back to the broken code.

@JsonProperty("birthdate")
@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date birthdate = null;

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 by reproducing the generated Java client from the supplied OAS3 birthdate declaration with Java 11 JSR384 and Jackson selected in the export configuration. Inspect the generated field and getter, then compare the output with the requested date representation; done means the generated client handles the date field and formatting without manual edits.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.