diff --git a/fastapi/security/oauth2.py b/fastapi/security/oauth2.py index 661043ce7b..a83c05b354 100644 --- a/fastapi/security/oauth2.py +++ b/fastapi/security/oauth2.py @@ -255,7 +255,7 @@ class OAuth2PasswordRequestFormStrict(OAuth2PasswordRequestForm): ], password: Annotated[ str, - Form(), + Form(json_schema_extra={"format": "password"}), Doc( """ `password` string. The OAuth2 spec requires the exact field name @@ -306,7 +306,7 @@ class OAuth2PasswordRequestFormStrict(OAuth2PasswordRequestForm): ] = None, client_secret: Annotated[ str | None, - Form(), + Form(json_schema_extra={"format": "password"}), Doc( """ If there's a `client_password` (and a `client_id`), they can be sent diff --git a/tests/test_security_oauth2.py b/tests/test_security_oauth2.py index 1c216e95d8..053d1dac66 100644 --- a/tests/test_security_oauth2.py +++ b/tests/test_security_oauth2.py @@ -213,7 +213,7 @@ def test_openapi_schema(): "type": "string", }, "username": {"title": "Username", "type": "string"}, - "password": {"title": "Password", "type": "string"}, + "password": {"title": "Password", 'format': 'password', "type": "string"}, "scope": { "title": "Scope", "type": "string", @@ -224,8 +224,7 @@ def test_openapi_schema(): "anyOf": [{"type": "string"}, {"type": "null"}], }, "client_secret": { - "title": "Client Secret", - "anyOf": [{"type": "string"}, {"type": "null"}], + "title": "Client Secret", 'format': 'password', "anyOf": [{"type": "string"}, {"type": "null"}], }, }, },