diff --git a/fastapi/security/oauth2.py b/fastapi/security/oauth2.py index 3fd9e41eb..6bee873fd 100644 --- a/fastapi/security/oauth2.py +++ b/fastapi/security/oauth2.py @@ -350,7 +350,7 @@ class OAuth2(SecurityBase): The dictionary of OAuth2 flows. """ ), - ] = OAuthFlowsModel(), + ] = None, scheme_name: Annotated[ str | None, Doc( @@ -392,6 +392,8 @@ class OAuth2(SecurityBase): ), ] = True, ): + if flows is None: + flows = OAuthFlowsModel() self.model = OAuth2Model( flows=cast(OAuthFlowsModel, flows), description=description )