mirror of
https://github.com/koxudaxi/datamodel-code-generator.git
synced 2024-03-18 14:54:37 +03:00
Added support for passing pathlib.Path as a format to JSON schema (#1879)
* Added support for passing pathlib.Path as a format to JSON schema * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added unit test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -548,6 +548,7 @@ class Types(Enum):
|
||||
date = auto()
|
||||
date_time = auto()
|
||||
password = auto()
|
||||
path = auto()
|
||||
email = auto()
|
||||
uuid = auto()
|
||||
uuid1 = auto()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user