Open SorenHolstHansen opened 3 months ago
The rust-server
generator uses chrono::NaiveDate
and chrono::NaiveDateTime
(see #9769); it would be nice to use those types in generated models, too, e.g.,:
use chrono::NaiveDateTime;
// ...
pub struct Post {
// ...
#[serde(rename = "posted")]
pub posted: NaiveDateTime,
}
I do this manually right now, using Git to discard the NaiveDateTime->String
conversion every time I regenerate from the API spec.
I looked at doing this via templates for the first part (use
), but the data type itself comes from {{{dataType}}}
in the middle of the template, which seems better addressed through the generator tool itself.
Is your feature request related to a problem? Please describe.
It is cumbersome to have to parse dates into datetime types yourself when it can be done by serde automatically.
Describe the solution you'd like
Since there are some intricacies to it, it would be best if it could be enabled with a cli flag to specify what date-time format (or, just, date format) to expect. Probably something like
If the flag is left out, the dates will be strings, otherwise it will deserialize the string to a date using the given format.
I would be fine with just enabling the formats specified here, but if more obscure formats are needed, we could do something like the time-crates format descriptions
Describe alternatives you've considered
Alternative would be to leave as is.