From e9e9cd7baeaa6d3eba0927bc4dba80b898648532 Mon Sep 17 00:00:00 2001 From: Lasse Gravesen Date: Thu, 23 Apr 2020 21:07:39 +0200 Subject: [PATCH] include format with secret types --- changes/1424-atheuz.md | 1 + pydantic/types.py | 2 ++ tests/test_schema.py | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changes/1424-atheuz.md diff --git a/changes/1424-atheuz.md b/changes/1424-atheuz.md new file mode 100644 index 0000000000..d02af90e26 --- /dev/null +++ b/changes/1424-atheuz.md @@ -0,0 +1 @@ +include format with secret types #546 \ No newline at end of file diff --git a/pydantic/types.py b/pydantic/types.py index 8eb72d6ac9..e9247de53d 100644 --- a/pydantic/types.py +++ b/pydantic/types.py @@ -531,6 +531,7 @@ class SecretStr: @classmethod def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None: field_schema.update(type='string', writeOnly=True) + field_schema.update(type='string', format='password') @classmethod def __get_validators__(cls) -> 'CallableGenerator': @@ -567,6 +568,7 @@ class SecretBytes: @classmethod def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None: field_schema.update(type='string', writeOnly=True) + field_schema.update(type='string', format='password') @classmethod def __get_validators__(cls) -> 'CallableGenerator': diff --git a/tests/test_schema.py b/tests/test_schema.py index e78ddb69e0..73f8ff49e8 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -579,7 +579,7 @@ class Model(BaseModel): base_schema = { 'title': 'Model', 'type': 'object', - 'properties': {'a': {'title': 'A', 'type': inner_type, 'writeOnly': True}}, + 'properties': {'a': {'title': 'A', 'type': inner_type, 'writeOnly': True, 'format': 'password'}}, 'required': ['a'], }