-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Swift4] Allow for custom dateformatter to be used #6672
Conversation
@DawidvanGraan 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.
@DawidvanGraan : Overall changes look good. I made one comment regarding why .dataDecodingStrategy was being changed since this change was about date decoding, not data decoding.
However, from your comment above that your date format from the server is "YYYY-MM-DD'T'HH:mm:ss.sssZ". The format you describe is ISO8601 exactly:
https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14
So I was wondering why setting JSONDecoder.dateDecodingStrategy = .iso8601 did not work for you, and why a customer decoder was needed in your case. I think the change is good and useful, but I didn't understand why it was needed for the date format you describe above.
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable { | ||
var returnedDecodable: T? = nil | ||
var returnedError: Error? = nil | ||
|
||
let decoder = JSONDecoder() | ||
decoder.dataDecodingStrategy = .base64 |
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.
Why is this being removed?
@ehyche Currently using Will update the PR and set |
Change to correct format: decoder.dataDecodingStrategy = .base64
Add `decoder.dataDecodingStrategy = .base64` back
Fix `decoder.dataDecodingStrategy = .base64`
Fix `decoder.dataDecodingStrategy = .base64`
@DawidvanGraan : thanks for the update. Looks good to me. @wing328 : should be good to merge. |
* master: (101 commits) [Swift4] Allow for custom dateformatter to be used (swagger-api#6672) [haskell-http-client] fix bug when generating models-only (swagger-api#6931) fix typo: crediential => credential minor typo fix [csharp] fix enum serialization of first value (swagger-api#6873) [PHP] Improve docs and README (swagger-api#6935) Binary mode for file deserialization in python (swagger-api#6936) add python tornado test to travis [Python/tornado] add integration tests and fix bugs (swagger-api#6925) Fix PHP passes response body to ApiException (swagger-api#6923) [TypeScript][Node] Resolve TS2532 error (swagger-api#6932) skip "all" shell script minor formatting change Fixes Issue swagger-api#6841, Map for accessing additionalProperties is generated. (swagger-api#6886) add tsloughter as owner erlang WIP: initial commit for Erlang client generator (swagger-api#6502) add back php client test Switch Travis image from MacOS to Linux (swagger-api#6937) add link to ebook [Scala] Default case class Option types to None for non-required fields (swagger-api#6790) ...
https://bugs.swift.org/browse/SR-5823 Thanks! I'll be using this PR as well. |
@TakenakaSimon you may want to use the SNAPSHOT version of the latest master as mentioned in https://github.com/swagger-api/swagger-codegen#compatibility |
if let df = self.dateformatter { | ||
decoder.dateDecodingStrategy = .formatted(df) | ||
} else { | ||
decoder.dataDecodingStrategy = .base64 |
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.
@DawidvanGraan Why is this inside the else
scope?
Shouldn't the dataDecodingStrategy
be applied, regardless of the custom date formatter?
Could be a mistake because date and data looks pretty much the same...
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
Setting a custom date format to be used on decoding.
My server response date uses the format
YYYY-MM-DD'T'HH:mm:ss.sssZ
, I needed a way to set DateFormatter on the decoding of the data models. Suggest allowing for a custom DateFormat to be used inCodableHelper
.Usage:
Suggested code change in
CodableHelper
Also changed the
dateDecodingStrategy
from '.base64' to '.deferredToDate` from issue #6576.