-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with pydantic v2, use pydantic.AwareDatetime instead of datetime (#1735)
* with pydantic v2, use pydantic.AwareDatetime instead of datetime Openapi spec says that type string with format "date-time" must have a timezone. Therefore, we need pydantic.AwareDatetime here. * Add unittest --------- Co-authored-by: Koudai Aono <[email protected]>
- Loading branch information
1 parent
a36ce94
commit a31148d
Showing
4 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from datamodel_code_generator.imports import Import | ||
|
||
IMPORT_CONFIG_DICT = Import.from_full_path('pydantic.ConfigDict') | ||
IMPORT_AWARE_DATETIME = Import.from_full_path('pydantic.AwareDatetime') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/data/expected/main/main_openapi_datetime_pydantic_v2/output.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# generated by datamodel-codegen: | ||
# filename: datetime.yaml | ||
# timestamp: 2019-07-26T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from pydantic import AwareDatetime, BaseModel, Field | ||
|
||
|
||
class InventoryItem(BaseModel): | ||
releaseDate: AwareDatetime = Field(..., examples=['2016-08-29T09:12:33.001Z']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters