yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
625 stars 147 forks source link

How to add Date formatters in the 4.0 version? #145

Closed cerupcat closed 5 years ago

cerupcat commented 5 years ago

Previously you could override DateTime.dateDecodingFormatters, but I don't see an option for setting the date formats in v4.0. Is there a way to add multiple date formatting options? Right now I'm getting errors that it can't parse certain Date fields.

yonaskolb commented 5 years ago

Hi @cerupcat. In 4.0, DateTime was changed to a simple Date. You can set apiClient.jsonDecoder.dateDecodingStrategy to choose how these are decoded. If you use .custom you can provide your own decoder that uses multiple date formatters. That's what the default one does.

It reminds me, I should add a apiClient.jsonEncoder as well, at the moment it just uses a new instance everytime.

cerupcat commented 5 years ago

Thanks @yonaskolb that's helpful. I missed seeing that jsonDecoder was public.

Keep up the great work! This is very helpful!