diff --git a/datamodel_code_generator/imports.py b/datamodel_code_generator/imports.py index 26c81fc7..4bd5f266 100644 --- a/datamodel_code_generator/imports.py +++ b/datamodel_code_generator/imports.py @@ -116,5 +116,6 @@ IMPORT_DICT = Import.from_full_path('typing.Dict') 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') diff --git a/datamodel_code_generator/model/pydantic/types.py b/datamodel_code_generator/model/pydantic/types.py index 4f2947c0..4256a998 100644 --- a/datamodel_code_generator/model/pydantic/types.py +++ b/datamodel_code_generator/model/pydantic/types.py @@ -9,6 +9,7 @@ from datamodel_code_generator.imports import ( IMPORT_DATE, IMPORT_DATETIME, IMPORT_DECIMAL, + IMPORT_PATH, IMPORT_TIME, IMPORT_UUID, ) @@ -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), diff --git a/datamodel_code_generator/parser/jsonschema.py b/datamodel_code_generator/parser/jsonschema.py index 2850751a..683be4e6 100644 --- a/datamodel_code_generator/parser/jsonschema.py +++ b/datamodel_code_generator/parser/jsonschema.py @@ -118,6 +118,7 @@ json_schema_data_formats: Dict[str, Dict[str, Types]] = { 'date-time': Types.date_time, 'time': Types.time, 'password': Types.password, + 'path': Types.path, 'email': Types.email, 'idn-email': Types.email, 'uuid': Types.uuid, diff --git a/datamodel_code_generator/types.py b/datamodel_code_generator/types.py index 16eaec3d..9fdfadec 100644 --- a/datamodel_code_generator/types.py +++ b/datamodel_code_generator/types.py @@ -548,6 +548,7 @@ class Types(Enum): date = auto() date_time = auto() password = auto() + path = auto() email = auto() uuid = auto() uuid1 = auto() diff --git a/docs/supported-data-types.md b/docs/supported-data-types.md index b67fe3b6..cd5b340b 100644 --- a/docs/supported-data-types.md +++ b/docs/supported-data-types.md @@ -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 diff --git a/tests/parser/test_jsonschema.py b/tests/parser/test_jsonschema.py index 1edb6d2a..4fd71941 100644 --- a/tests/parser/test_jsonschema.py +++ b/tests/parser/test_jsonschema.py @@ -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'),