Description
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:
- Arbitrary fractional seconds precision
Z
as a timezone suffix for UTC timezones
Both 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 the Z
timezone suffix. This is a totally valid ISO-8601 string, and datetime can parse it:
Python 3.11.3 (main, Apr 7 2023, 20:13:31) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
>>> from datetime import datetime
>>> datetime.fromisoformat('2023-06-08T04:03:13.578Z')
datetime.datetime(2023, 6, 8, 4, 3, 13, 578000, tzinfo=datetime.timezone.utc)
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- The only timezone indicactor supported today is the
+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 control
Therefore, 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 append Z
, or could be used for any possible transformations