epam-cross-platform-lab / swagger-dart-code-generator

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter
Apache License 2.0
268 stars 124 forks source link

[QUESTION] API requires all dates to be UTC - is there a way to encode all dates like this? #740

Open dJani97 opened 8 months ago

dJani97 commented 8 months ago

Please describe a problem. I'm using an API which requires all dates to be UTC, meaning, they should be in this format, ending with a Z:

"2024-01-02T09:00:00.000Z"

If they don't end with a Z, I get an internal server error 😓

To comply with this, I have to make a copy of any newly created objects in my repository layer, and manually overwrite all DateTime fields in the class by calling the .toUtc() method on their value. This is complicated, and it's easy to accidentally miss a field.

Describe the solution you'd like Is there any way to write a custom converter or something, and apply it globally for all DateTime objects?

I know json_serializable has #custom-types-and-custom-encoding, is this accessible somehow when I'm using swagger-dart-code-generator?

Vovanella95 commented 8 months ago

Hi @dJani97 , I can add string formatter for DateTime. Will let you know soon about updates

xioxin commented 1 month ago

The Scalars Implementation can solve this problem.

You can refer to this: https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/750#issuecomment-2434347111