โ† baseline_full_v2

fastapi_14459

failed NO_PATCH NO_PATCH UNSUBMITTED empty_patch(None) ยท None tool calls ยท 0 s ยท fastapi/fastapi

Task input

๐Ÿ› Fix OAuth2 scopes in OpenAPI in extra corner cases, parent dependency with scopes, sub-dependency security scheme without scopes

๐Ÿ› Fix OAuth2 scopes in OpenAPI in extra corner cases, parent dependency with scopes, sub-dependency security scheme without scopes, and the same security scheme used as another sub-dependency without scopes in a different path operation.

The dependency without scopes would be cached for OpenAPI and for the one with scopes, it would render without scopes.

This also refactors the internals of how dependencies are handled, and how scopes and security schemes are passed through the code, removing duplication and simplifying parts, making them more robust and less error-prone. :muscle: 

This should fix https://github.com/fastapi/fastapi/issues/14454 (strike 2 :baseball:)

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Test output

show
sponse.text
>       assert response.json() == snapshot(
            {
                "openapi": "3.1.0",
                "info": {"title": "FastAPI", "version": "0.1.0"},
                "paths": {
                    "/": {
                        "get": {
                            "summary": "Root",
                            "operationId": "root__get",
                            "responses": {
                                "200": {
                                    "description": "Successful Response",
                                    "content": {"application/json": {"schema": {}}},
                                }
                            },
                            "security": [{"OAuth2AuthorizationCodeBearer": []}],
                        }
                    },
                    "/with-oauth2-scheme": {
                        "get": {
                            "summary": "Read With Oauth2 Scheme",
                            "operationId": "read_with_oauth2_scheme_with_oauth2_scheme_get",
                            "responses": {
                                "200": {
                                    "description": "Successful Response",
                                    "content": {"application/json": {"schema": {}}},
                                }
                            },
                            "security": [
                                {"OAuth2AuthorizationCodeBearer": ["read", "write"]}
                            ],
                        }
                    },
                    "/with-get-token": {
                        "get": {
                            "summary": "Read With Get Token",
                            "operationId": "read_with_get_token_with_get_token_get",
                            "responses": {
                                "200": {
                                    "description": "Successful Response",
                                    "content": {"application/json": {"schema": {}}},
                                }
                            },
                            "security": [
                                {"OAuth2AuthorizationCodeBearer": ["read", "write"]}
                            ],
                        }
                    },
                    "/items/": {
                        "get": {
                            "summary": "Read Items",
                            "operationId": "read_items_items__get",
                            "responses": {
                                "200": {
                                    "description": "Successful Response",
                                    "content": {"application/json": {"schema": {}}},
                                }
                            },
                            "security": [
                                {"OAuth2AuthorizationCodeBearer": ["read"]},
                            ],
                        },
                        "post": {
                            "summary": "Create Item",
                            "operationId": "create_item_items__post",
                            "responses": {
                                "200": {
                                    "description": "Successful Response",
                                    "content": {"application/json": {"schema": {}}},
                                }
                            },
                            "security": [
                                {"OAuth2AuthorizationCodeBearer": ["read", "write"]},
                            ],
                        },
                    },
                },
                "components": {
                    "securitySchemes": {
                        "OAuth2AuthorizationCodeBearer": {
                            "type": "oauth2",
                            "flows": {
                                "authorizationCode": {
                                    "scopes": {
                                        "read": "Read access",
                                        "write": "Write access",
                                    },
                                    "authorizationUrl": "authorize",
                                    "tokenUrl": "token",
                                }
                            },
                        }
                    }
                },
            }
        )
E       AssertionError: assert {'openapi': '... 'token'}}}}}} == {'openapi': '... 'token'}}}}}}
E         
E         Omitting 3 identical items, use -vv to show
E         Differing items:
E         {'paths': {'/': {'get': {'summary': 'Root', 'operationId': 'root__get', 'responses': {'200': {'description': 'Successf...: {'description': 'Successful Response', 'content': {...}}}, 'security': [{'OAuth2AuthorizationCodeBearer': [...]}]}}}} != {'paths': {'/': {'get': {'summary': 'Root', 'operationId': 'root__get', 'responses': {'200': {'description': 'Successf...: {'description': 'Successful Response', 'content': {...}}}, 'security': [{'OAuth2AuthorizationCodeBearer': [...]}]}}}}
E         Use -v to get more diff

tests/test_security_oauth2_authorization_code_bearer_scopes_openapi.py:103: AssertionError
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45
  /Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
    _PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 2 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 5 passed, 1 warning, 1 error in 0.56s