-
Notifications
You must be signed in to change notification settings - Fork 6k
[kotlin] support selection of datelibrary #7054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@magiepooh thanks for the PR 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great!
I didn't run this to verify, but it looks reasonable and correct to me. Minor suggestion to change string "true"
set on additionalProperties to true
so templates can handle them as booleans. If they're required to be stringified, we should probably comment that where these are set.
typeMapping.put("Date", "kotlin.String"); | ||
typeMapping.put("DateTime", "kotlin.String"); | ||
} else if (DateLibrary.JAVA8.value.equals(dateLibrary)) { | ||
additionalProperties.put(DateLibrary.JAVA8.value, "true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionalProperties
should be true
here rather than "true"
if it's intended to be used for switching in templates.
} | ||
|
||
if (DateLibrary.THREETENBP.value.equals(dateLibrary)) { | ||
additionalProperties.put(DateLibrary.THREETENBP.value, "true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionalProperties should be true here rather than "true" if it's intended to be used for switching in templates.
importMapping.put("LocalDate", "org.threeten.bp.LocalDate"); | ||
importMapping.put("LocalDateTime", "org.threeten.bp.LocalDateTime"); | ||
} else if (DateLibrary.STRING.value.equals(dateLibrary)) { | ||
additionalProperties.put(DateLibrary.STRING.value, "true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having just string
as an additional property would be confusing.
For instance, in a template this would lead to:
{{#string}}string date logic{{/string}}{{^string}}other logic{{/string}}
This seems like an unlikely use case, until it starts getting used and we can't change it without a breaking change. Also, I think this may cause confusion on some property/params which may have string
properties as well.
additionalProperties should be true here rather than "true" if it's intended to be used for switching in templates.
Any objection to using isStringDate
or something? iirc, Mustache will consider the string "true" for properties prefixed with is
as a boolean. I could be wrong, but I prefer to set booleans explicitly. At one point, we were able to set them as strings but I don't know if that code was changed or if the Mustache dependency was updated but as of a few weeks ago they had to be explicit booleans.
@magiepooh I don't know if you saw my comments? If you'd like, I can make the changes and open a PR against your fork. |
Thank you for reviewing! (I was not aware. sorry.)
I'll fix it.
I think that selection regarding dates should be managed with a unified option. Multiple option (isStringDate option and dateLibrary option ) may confuse the user. What do you think? |
@Maggiepooh I thought about it a little more. There's a Maybe a better approach would be to set a private flag if the additional property is set (and remove it from additional properties to avoid any confusion), and post process variables and parameters to change from dates to strings. After all, that's what this option intends to do, correct? This way, it wouldn't interfere with templates that have I haven't looked at other generators to see if/how they handle this. @wing328 is there a common approach to forcing date/date-time to strings? |
For PHP, we use our own serializer to handle the datetime to string conversion. For Java, we rely on 3rd-party libraries. For Kotlin, can we follow Java's approach? (just throwing a suggestion but I've not looked into the Kotlin client code) |
I agree. @jimschubert Should I fix it as follows? ("isStringDate" may not need to be used. Other additional properties may use like this. ) |
@jimschubert |
@magiepooh CircleCI reports the following issue:
I wonder if you can take a look when you've time. |
Can you help me? I don't know why CI failure. |
I did a test with the option
I think I've solutions to these problems and will squeeze some time this weekend to work on it. |
Why is legacy not supported here? For Java, this sets it to I used the snapshot of 2.4.0 (feb 10) and threetenbp works fine there. Legacy gives me Java8 datetime |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
support selection of date library. (
java8
,threetenbp
,string
)related Issue: #6892