swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[Swift 4] Replace custom dateformatter property with dateDecodingStrategy to al…

Open fl034 opened this issue 7 years ago • 1 comments

Allow setting .iso8601 or custom DateFormatter as date decoding strategy.

PR checklist

  • [x] Read the contribution guidelines.
  • [x] Ran the shell script under ./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\.
  • [x] Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • [x] Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

To be able to set .iso8601 as a JSONDecoder.DateDecodingStrategy I replaced the custom static dateformatter property inside CodableHelper.swift with the strategy.

You only have to change your code if you were using this property. If yes, just encapsulate your existing DateFormatter like this:

CodableHelper.dateDecodingStragegy = .formatted(myPreviousDateFormatter)

The benefits of this is to be able to set the new strategy available from iOS 10 which fits all my date decoding needs :).

CodableHelper.dateDecodingStragegy = .iso8601

fl034 avatar Jun 02 '18 10:06 fl034

cc @ehyche (please be kind, this is my first contribution here, i hope i did everything right 🤓)

fl034 avatar Jun 02 '18 10:06 fl034