I have a swagger definition which is already finalized so I am not able to alter attributes or propose changes. This swagger file has various date definitions like this:
fromDate:
description: |
- en - fromDate.....
type: string
format: date
In java clients this is generated as a Date attribute. In C# there is no basic implementation of Date but just DateTime which is taken as the generated datatype. This is the same for all of the 4 ways I tried when generating the client:
Swagger Editor with C# Client generation
Swagger Editor with C# #2 Client generation (RestSharp 2)
Open API generator with C# Client generation
Open API generator with C# #2 Client generation (RestSharp 2)
I would expect a serialization pattern like yyyy-mm-dd to be created in the c# client to match the date type but this is not the case. Dates are always serialized as full date/time/timezone strings. This is not working for the server application.
The official documentation says
string date As defined by full-date - RFC3339
RFC339 full date says
full-date = date-fullyear "-" date-month "-" date-mday
As expected my client produces wrong output data (for example 2020-12-31T23:59:60Z) and crashes when it parses incoming data in the api client class (crash occurs before I can handle the input).
When I alter the swagger to have a string type with a pattern as suggested in other posts it works but this is not how it should be, I must use the predefined swagger file.
How can I create the clients or add a special pattern that gets automatically called by the client?
Cheers