From 9238e3d98ff5b104ec9761454b565dda6145e877 Mon Sep 17 00:00:00 2001 From: Atheuz Date: Thu, 30 Apr 2020 14:09:45 +0200 Subject: [PATCH] include format with secret types (#1424) * include format with secret types * fix: fix pr comments. Co-authored-by: Lasse Gravesen --- changes/1424-atheuz.md | 1 + pydantic/types.py | 4 ++-- tests/test_schema.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) 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..f8addf0627 --- /dev/null +++ b/changes/1424-atheuz.md @@ -0,0 +1 @@ +include `'format': 'password'` in the schema for secret types \ No newline at end of file diff --git a/pydantic/types.py b/pydantic/types.py index 2b7a64e946..13e74c33cb 100644 --- a/pydantic/types.py +++ b/pydantic/types.py @@ -540,7 +540,7 @@ def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None: 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', writeOnly=True, format='password') @classmethod def __get_validators__(cls) -> 'CallableGenerator': @@ -576,7 +576,7 @@ def get_secret_value(self) -> str: 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', writeOnly=True, format='password') @classmethod def __get_validators__(cls) -> 'CallableGenerator': diff --git a/tests/test_schema.py b/tests/test_schema.py index b0bd2f0206..3dd902a19b 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -580,7 +580,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'], }