Bug Report Checklist
Description
The generated ApiClient.java (using <dateLibrary>java8</dateLibrary> and <library>resttemplate</library>) contains a method parameterToString, which is used to convert arbitrary e.g. query-parameters to a string-representation. This method always checks for java.util.Date to apply the DateFormat, which will never match when using OffsetDateTime (<dateLibrary>java8</dateLibrary>). Therefore, String.valueOf(..) is used, which does not yield the same result as using the RFC3339DateFormat.
openapi-generator version
4.2.0
OpenAPI declaration file content or url
irrelevant
Generation Details
<configOptions>
<dateLibrary>java8</dateLibrary>
<library>resttemplate</library>
</configOptions>
Steps to reproduce
- Generate client classes from any schema
- Look at
ApiClient#parameterToString
- See that it checks on old
java.util.Date instead of OffsetDateTime.
See the following test-case to show that the output is not identical and might therefor fail on a subsequent parse:
public class DateFormatTest {
@Test
void test() {
var date = OffsetDateTime.now();
var date2 = Date.from(date.toInstant());
assertEquals(new RFC3339DateFormat().format(date2), String.valueOf(date));
}
}
Expected :2020-08-11T14:16:40.013Z
Actual :2020-08-11T16:16:40.013502900+02:00
Related issues/PRs
Not that I could find any.
Suggest a fix
When <dateLibrary>java8</dateLibrary> is provided the date-formatting in the ApiClient-template should check for OffsetDateTime, instead of java.util.Date in parameterToString.
A less intrusive fix would be adding the following else-if to the checks in parameterToString:
} else if (param instanceof OffsetDateTime) {
return formatDate(Date.from(((OffsetDateTime) param).toInstant()));
}
Bug Report Checklist
Description
The generated
ApiClient.java(using<dateLibrary>java8</dateLibrary>and<library>resttemplate</library>) contains a methodparameterToString, which is used to convert arbitrary e.g. query-parameters to a string-representation. This method always checks forjava.util.Dateto apply theDateFormat, which will never match when using OffsetDateTime (<dateLibrary>java8</dateLibrary>). Therefore,String.valueOf(..)is used, which does not yield the same result as using theRFC3339DateFormat.openapi-generator version
4.2.0
OpenAPI declaration file content or url
irrelevant
Generation Details
Steps to reproduce
ApiClient#parameterToStringjava.util.Dateinstead ofOffsetDateTime.See the following test-case to show that the output is not identical and might therefor fail on a subsequent parse:
Related issues/PRs
Not that I could find any.
Suggest a fix
When
<dateLibrary>java8</dateLibrary>is provided the date-formatting in the ApiClient-template should check forOffsetDateTime, instead ofjava.util.DateinparameterToString.A less intrusive fix would be adding the following else-if to the checks in
parameterToString: