swagger-api / swagger-api/swagger-codegen
[JAVA] Generates String instead of OffsetDateTime
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
A reference in an object in the definitions part to a primitive date-time is generated as String instead of OffsetDateTime.
I tried this with the definition on my local machine with swagger-codegen-cli but I get the same result when generating a java client on editor.swagger.io
The generated class io.swagger.client.model.Test has 2 fields, date1 of type OffsetDateTime and date2 of Type String.
I would expect both fields to be of type OffsetDateTime.
Here is an excerpt from the code:
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2019-08-14T07:51:15.087Z")
public class Test {
@SerializedName("date1")
private OffsetDateTime date1 = null;
@SerializedName("date2")
private String date2 = null;
Swagger-codegen version
2.3.0 and 2.4.7 (and probably more)
Swagger declaration file content or url
swagger: "2.0"
info:
title: "Test"
version: "2"
paths:
/test:
get:
produces:
- "application/json"
responses:
200:
description: "success"
schema:
$ref: "#/definitions/Test"
definitions:
Date:
type: "string"
format: "date-time"
Test:
type: "object"
properties:
date1:
type: "string"
format: "date-time"
date2:
$ref: '#/definitions/Date'
Steps to reproduce
Insert swagger definition in editor.swagger.io and generate java client.
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
Use the supplied Swagger 2.0 definition as the reproduction input, generate the Java client, and compare inline date1 with referenced date2 in io.swagger.client.model.Test. Trace the Java client generation path for referenced primitive date-time schemas; done when both fields are OffsetDateTime and the generated output matches the expectation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100