Open jasondamour opened 1 year ago
@spacether or @krjakbrjak, Could I kindly bug you for your thoughts and triage? If no issue with the proposal, I'll begin implementing it.
Oh, I started looking into the src more closely for the implementation, and realized theres more to it! The datetimeFormat
configOption is only applied to queryParams
. I'm particularly interested in fixing this for bodyParams
, but it probably needs to apply to datetime fields in any param location!
Is your feature request related to a problem? Please describe.
The python client ("python-nextgen" as of v6.6.0, "python" in v7+) allows specifying the
datetimeFormat
, but python datetime standard library does not cover the whole ISO-8601 spec, or even RFC-3339. In order for the openapi generator client to be compatible with as many systems as possible, some additional format options should be provided.The specific issues I would like to address here are:
Z
as a timezone suffix for UTC timezonesBoth ISO-8601 and RFC-3339 allow the above two formats, but datetime does not support outputting them and has no intention of supporting them "for simplicity".
For example, take
2023-06-08T04:03:13.578Z
. Note the 3 digit (millisecond) precision, and theZ
timezone suffix. This is a totally valid ISO-8601 string, and datetime can parse it:However, there is no current possible way to output the same format using the datetime library, due to 2 restrictions:
strftime()
only supports 6 digits (microseconds)%f
, which is the method used by openapi generator today a. They offer another methodisoformat(timespec)
wheretimespec
can indicate precision, but then this does not allow arbitrary formatting+00:00
format, no support forZ
suffix a. Support is proposed here, but who knows how long it will take to get merged and wont be available in older python releases b. Usingstrftime()
, its possible to add a hardcodedZ
in the string (i.e.strftime("%Y-%m-%dT%H:%M:%SZ")
. However this conflicts with the issue above, which requires usingisoformat(timespec)
for franctional precision controlTherefore, it is up to openapi-generator to close the gaps to make datetime more compatible with RFC-3339.
Describe the solution you'd like
To address fractional second precision and
Z
timezone indicator, add 3 new configOptions to the python generator:datetimeIsoformat: bool
- Iftrue
, then instead ofstrftime()
here, useisoformat()
datetimeIsoformatTimespec: str
- IfdatetimeIsoformat=True
and not empty, then passtimespec
toisoformat()
.datetimeUTCDesignator: bool
- Iftrue
and resulting datetime string ends in+00:00
, then replace+00:00
withZ
(regardless of the value ofdatetimeIsoformat
)Describe alternatives you've considered
If possible, a single configOption which allows defining custom transformations like
[:-3] + 'Z'
to strip digits and appendZ
, or could be used for any possible transformationsAdditional context