swagger-api / swagger-api/swagger-codegen

[JAVA] OffsetDateTime, LocalDateTime parameter format broken usingGet API

Open
#7,701 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

I want send LocalDateTime parameter using get method.

DateTimeFormatter formater = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
LocalDateTime localDateTime = LocalDateTime.parse("2018-02-21'T'18:11:00.000Z", formatter);

but, swagger generate code like this.

public String parameterToString(Object param) {
        if (param == null) {
             return "";
        } else if (param instanceof Date) {
            return formatDatetime((Date) param);
        } else if (param instanceof Collection) {
            StringBuilder b = new StringBuilder();
            for (Object o : (Collection)param) {
                if (b.length() > 0) {
                    b.append(",");
                }
                b.append(String.valueOf(o));
            }
            return b.toString();
        } else {    //LocalDateTime and OffsetDateTIme task here!
            return String.valueOf(param);
        }
}

Expected : 2018-02-21'T'18:11:00.000Z
Actual : 2018-02-21'T'18:11

Swagger-codegen version

2.2.3

How can I catch instanceOf LocalDateTime and OffsetDateTime?

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 at the generated Java parameterToString(Object param) method and trace the template or generator entry point that produces it. Check how LocalDateTime and OffsetDateTime are serialized for GET parameters, then verify that the output preserves the expected timestamp format rather than truncating it.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
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.