You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Python client generator, the Pydantic fields are annotated with datetime, which allows timezone-naive objects to be passed. When serialized to strings, these do not contain time-zone information like a trailing Z or +00:00. This violates the OpenAPI spec.
openapi-generator version
7.7.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
I would change the type annotations for date-time format string to pydantic.types.AwareDatetime, to require the time-zone information that the OpenAPI spec asks for when objects are constructed in Python.
This can be a breaking change to users using lenient REST APIs with the generated client. It might also be annoying if server responses contain "incorrect" timezone-naive timestamps and client-side validation fails.
Looking forward to feedback on how this should be best handled, to correctly represent the OpenAPI spec but not be annoying to users.
The text was updated successfully, but these errors were encountered:
robertschweizer
changed the title
[BUG] Python client should only allow timezone-aware datetime
[BUG][PYTHON] should only allow timezone-aware datetime
Aug 6, 2024
Bug Report Checklist
Description
As described in OAI/OpenAPI-Specification#1498 (comment), OpenAPI
date-time
strings must contain time-zone information.In the Python client generator, the Pydantic fields are annotated with
datetime
, which allows timezone-naive objects to be passed. When serialized to strings, these do not contain time-zone information like a trailingZ
or+00:00
. This violates the OpenAPI spec.openapi-generator version
7.7.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
I would change the type annotations for
date-time
format string topydantic.types.AwareDatetime
, to require the time-zone information that the OpenAPI spec asks for when objects are constructed in Python.This can be a breaking change to users using lenient REST APIs with the generated client. It might also be annoying if server responses contain "incorrect" timezone-naive timestamps and client-side validation fails.
Looking forward to feedback on how this should be best handled, to correctly represent the OpenAPI spec but not be annoying to users.
The text was updated successfully, but these errors were encountered: