Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for passing pathlib.Path as a format to JSON schema #1879

Merged
merged 5 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datamodel_code_generator/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ def remove_referenced_imports(self, reference_path: str) -> None:
IMPORT_DECIMAL = Import.from_full_path('decimal.Decimal')
IMPORT_DATE = Import.from_full_path('datetime.date')
IMPORT_DATETIME = Import.from_full_path('datetime.datetime')
IMPORT_PATH = Import.from_full_path('pathlib.Path')
IMPORT_TIME = Import.from_full_path('datetime.time')
IMPORT_UUID = Import.from_full_path('uuid.UUID')
2 changes: 2 additions & 0 deletions datamodel_code_generator/model/pydantic/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
IMPORT_DATE,
IMPORT_DATETIME,
IMPORT_DECIMAL,
IMPORT_PATH,
IMPORT_TIME,
IMPORT_UUID,
)
Expand Down Expand Up @@ -70,6 +71,7 @@ def type_map_factory(
Types.binary: data_type(type='bytes'),
Types.date: data_type.from_import(IMPORT_DATE),
Types.date_time: data_type.from_import(IMPORT_DATETIME),
Types.path: data_type.from_import(IMPORT_PATH),
Types.password: data_type.from_import(IMPORT_SECRET_STR),
Types.email: data_type.from_import(IMPORT_EMAIL_STR),
Types.uuid: data_type.from_import(IMPORT_UUID),
Expand Down
1 change: 1 addition & 0 deletions datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def get_model_by_path(
'date-time': Types.date_time,
'time': Types.time,
'password': Types.password,
'path': Types.path,
'email': Types.email,
'idn-email': Types.email,
'uuid': Types.uuid,
Expand Down
1 change: 1 addition & 0 deletions datamodel_code_generator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ class Types(Enum):
date = auto()
date_time = auto()
password = auto()
path = auto()
email = auto()
uuid = auto()
uuid1 = auto()
Expand Down
1 change: 1 addition & 0 deletions docs/supported-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Below are the data types and features recognized by datamodel-code-generator for
- password
- email
- idn-email
- path
- uuid (uuid1/uuid2/uuid3/uuid4/uuid5)
- ipv4
- ipv6
Expand Down
1 change: 1 addition & 0 deletions tests/parser/test_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def test_parse_nested_array():
('boolean', None, 'bool', None, None),
('string', 'date', 'date', 'datetime', 'date'),
('string', 'date-time', 'datetime', 'datetime', 'datetime'),
('string', 'path', 'Path', 'pathlib', 'Path'),
('string', 'password', 'SecretStr', 'pydantic', 'SecretStr'),
('string', 'email', 'EmailStr', 'pydantic', 'EmailStr'),
('string', 'uri', 'AnyUrl', 'pydantic', 'AnyUrl'),
Expand Down
Loading