From e9e9cd7baeaa6d3eba0927bc4dba80b898648532 Mon Sep 17 00:00:00 2001 From: Lasse Gravesen Date: Thu, 23 Apr 2020 21:07:39 +0200 Subject: [PATCH 1/2] 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'], } From af9ac26dd688b9f4da8e9186d4f6edf9d38fa3bb Mon Sep 17 00:00:00 2001 From: Lasse Gravesen Date: Fri, 24 Apr 2020 16:22:41 +0200 Subject: [PATCH 2/2] fix: fix pr comments. --- changes/1424-atheuz.md | 2 +- pydantic/types.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/changes/1424-atheuz.md b/changes/1424-atheuz.md index d02af90e26..f8addf0627 100644 --- a/changes/1424-atheuz.md +++ b/changes/1424-atheuz.md @@ -1 +1 @@ -include format with secret types #546 \ No newline at end of file +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 e9247de53d..01b300734e 100644 --- a/pydantic/types.py +++ b/pydantic/types.py @@ -530,8 +530,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', format='password') + field_schema.update(type='string', writeOnly=True, format='password') @classmethod def __get_validators__(cls) -> 'CallableGenerator': @@ -567,8 +566,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', format='password') + field_schema.update(type='string', writeOnly=True, format='password') @classmethod def __get_validators__(cls) -> 'CallableGenerator':