Open jbkervyn opened 2 years ago
Very interesting for me how sometimes things happen. I was debugging the similar (or even same) thing the last couple of hours. Unfortunatelly, I could not decide if it is a bug or feature, Hence, I'm requesting the contributors to give their 2 cents.
My settings is as follows: I use the schema
type: string
format: date-time
that I expect to render as OffsetDateTime
in case of jdk8 and use a prefix for model generation. The prefix (and obviously the suffix) are key to this issue. Without it, it works as I would expect.
To reproduce the issue I used the following schema
openapi: 3.0.1
paths:
components:
schemas:
MyObject:
type: object
properties:
date1:
$ref: '#/components/schemas/OffsetDateTimeX'
date2:
$ref: '#/components/schemas/OffsetDateTime'
OffsetDateTimeX:
type: string
format: date-time
OffsetDateTime:
type: string
format: date-time
Basically, both attributes date1
and date2
are quite similar except that for date2
I've hit a somehow known word/type. Using the prefix Prefix
, in the resulting Java model, the two attributes are rendered as follows:
@SerializedName(SERIALIZED_NAME_DATE1)
private OffsetDateTime date1;
public static final String SERIALIZED_NAME_DATE2 = "date2";
@SerializedName(SERIALIZED_NAME_DATE2)
private PrefixOffsetDateTime date2;
date1
is correct for me, however, I would have expected date2
also to be rendered as OffsetDateTime
. Please note that there is no class PrefixOffsetDateTime
generated.
Hint for @jbkervyn: As my example shows, probably another workaround for you is to rename the schema Date
to something else. Maybe give that a try.
@juergencodes I don't know why I didn't think about that :) Indeed, renaming the Component to something else than Date fixes it !
Here is a patch for reproducing the issue in a unit test.
Since the version 5.4.0, the code generation of the following component via the spring generator generates the following model
And the DateApi object is not being genertated or present in the import
Here is the configuration
In version 5.3.1, the following is being generated
It's worth noting that a quick workaround would be to inline the date directly.