[Swift5] Fix Datetime default value#7003
[Swift5] Fix Datetime default value#7003wing328 merged 2 commits intoOpenAPITools:masterfrom allezxandre:fix-datetime-handling
Conversation
If a default value is provided by the API spec for a date-time attribute, this commit fixes the generation code to build a correct Swift `Date` object.
|
Can you please run |
|
I've updated the samples via 80f9612. Let's see how that goes. |
|
It looks like the samples don't have a default date value, so this PR will be difficult to validate. |
| public var mapMapString: [String: [String: String]]? | ||
|
|
||
| public init(mapString: [String: String]?, mapMapString: [String: [String: String]]?) { | ||
| public init(mapString: [String: String]? = nil, mapMapString: [String: [String: String]]? = nil) { |
There was a problem hiding this comment.
@allezxandre looks like many parameters are default to nil. Is that expected?
There was a problem hiding this comment.
This is not related to this PR, it was introduced in another one, but apparently the samples were outdated.
There was a problem hiding this comment.
I actually tested with the master but didn't get these nil default value. Maybe my test wasn't done right.
There was a problem hiding this comment.
When I run ./mvnw package && ./bin/generate-samples.sh bin/configs/other/swift5-* on the master, I get all of those nil changes
There was a problem hiding this comment.
Thanks for confirming that.
Is the nil default value expected? If not, we can remove it later in another PR. ( I think I know where to fix it )
There was a problem hiding this comment.
Yes it is expected.
Basically this is just providing default nil values for for nullable types to shorten the constructor to the library user.
I tested this locally, and this yields the following default date when it is defined to March 17th 2020 10:00:00 UTC: |
|
Is there any disadvantages in removing the division like this? |
This is because the date time can be expressed up to the microsecond precision. However, in Java they are represented as Microseconds stored in a long and in Swift they are represented as seconds represented in a double. To avoid float precision issue, I let Java keep its storage as a long, and then add a In my example of a |
|
Thanks for the explanation, looks good to me 👍 |
This is a follow-up to #5256, which happens to affect the Swift5 code-gen.
If a default value is provided by the API spec for a date-time attribute, this PR fixes the generation code to build a correct Swift
Dateobject.To close #5256
PR checklist
./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.master