]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
🚸 Set format to password for fields `password` and `client_secret` in `OAuth2Password...
authoroogee <teotyrov@gmail.com>
Tue, 17 Jun 2025 10:41:59 +0000 (05:41 -0500)
committerGitHub <noreply@github.com>
Tue, 17 Jun 2025 10:41:59 +0000 (12:41 +0200)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
fastapi/security/oauth2.py
tests/test_tutorial/test_security/test_tutorial003.py
tests/test_tutorial/test_security/test_tutorial005.py

index 5ffad59862ba942a26dc27ce77c66578659918d3..42ace07a3458b8468b631594416d4cfc778de7f7 100644 (file)
@@ -85,7 +85,7 @@ class OAuth2PasswordRequestForm:
         ],
         password: Annotated[
             str,
-            Form(),
+            Form(json_schema_extra={"format": "password"}),
             Doc(
                 """
                 `password` string. The OAuth2 spec requires the exact field name
@@ -130,7 +130,7 @@ class OAuth2PasswordRequestForm:
         ] = None,
         client_secret: Annotated[
             Union[str, None],
-            Form(),
+            Form(json_schema_extra={"format": "password"}),
             Doc(
                 """
                 If there's a `client_password` (and a `client_id`), they can be sent
index 37fc2618fbc88365e83bccf8ad8249553e11cf49..2bbb2e8510da9b26b80a93fbdd51a4fc32c24ba7 100644 (file)
@@ -163,7 +163,11 @@ def test_openapi_schema(client: TestClient):
                             }
                         ),
                         "username": {"title": "Username", "type": "string"},
-                        "password": {"title": "Password", "type": "string"},
+                        "password": {
+                            "title": "Password",
+                            "type": "string",
+                            "format": "password",
+                        },
                         "scope": {"title": "Scope", "type": "string", "default": ""},
                         "client_id": IsDict(
                             {
@@ -179,11 +183,16 @@ def test_openapi_schema(client: TestClient):
                             {
                                 "title": "Client Secret",
                                 "anyOf": [{"type": "string"}, {"type": "null"}],
+                                "format": "password",
                             }
                         )
                         | IsDict(
                             # TODO: remove when deprecating Pydantic v1
-                            {"title": "Client Secret", "type": "string"}
+                            {
+                                "title": "Client Secret",
+                                "type": "string",
+                                "format": "password",
+                            }
                         ),
                     },
                 },
index 88c3d7815726a0e4c37a6a32ea9ab54cb55a8cb0..ad644d61bbaefab2adeb349b022b030b2f9ac4dc 100644 (file)
@@ -377,7 +377,11 @@ def test_openapi_schema(mod: ModuleType):
                             }
                         ),
                         "username": {"title": "Username", "type": "string"},
-                        "password": {"title": "Password", "type": "string"},
+                        "password": {
+                            "title": "Password",
+                            "type": "string",
+                            "format": "password",
+                        },
                         "scope": {"title": "Scope", "type": "string", "default": ""},
                         "client_id": IsDict(
                             {
@@ -393,11 +397,16 @@ def test_openapi_schema(mod: ModuleType):
                             {
                                 "title": "Client Secret",
                                 "anyOf": [{"type": "string"}, {"type": "null"}],
+                                "format": "password",
                             }
                         )
                         | IsDict(
                             # TODO: remove when deprecating Pydantic v1
-                            {"title": "Client Secret", "type": "string"}
+                            {
+                                "title": "Client Secret",
+                                "type": "string",
+                                "format": "password",
+                            }
                         ),
                     },
                 },