From 8413c755a26b9a9b3dd3f293b3204bfa9d91c831 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Fri, 20 Sep 2024 16:04:42 +0200 Subject: [PATCH] rebased on 0.115.0 --- fastapi/dependencies/utils.py | 2 +- fastapi/openapi/utils.py | 9 +--- ...t_dependency_security_overrides_openapi.py | 51 +++---------------- 3 files changed, 8 insertions(+), 54 deletions(-) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index d64c47c70..ecb654792 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -288,7 +288,7 @@ def get_resolved_dependant( header_params=dependant.header_params.copy(), cookie_params=dependant.cookie_params.copy(), body_params=dependant.body_params.copy(), - security_schemes=dependant.security_requirements.copy(), + security_requirements=dependant.security_requirements.copy(), ) for sub_dependant in dependant.dependencies: resolved_dependant.dependencies.append( diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index b1e8e71d5..174bd5d52 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -275,14 +275,8 @@ def get_openapi_path( operation.setdefault("security", []).extend(operation_security) if security_definitions: security_schemes.update(security_definitions) -<<<<<<< HEAD operation_parameters = _get_openapi_operation_parameters( - dependant=route.dependant, -======= - all_route_params = get_flat_params(dependant) - operation_parameters = get_openapi_operation_parameters( - all_route_params=all_route_params, ->>>>>>> 022f1e79 (Fix openapi document with dependencies override (#5451)) + dependant=dependant, schema_generator=schema_generator, model_name_map=model_name_map, field_mapping=field_mapping, @@ -471,7 +465,6 @@ def get_fields_from_routes( dependency_overrides=dependency_overrides, ) params.extend(get_flat_params(dependant)) - request_fields_from_routes.extend(params) flat_models = callback_flat_models + list( diff --git a/tests/test_dependency_security_overrides_openapi.py b/tests/test_dependency_security_overrides_openapi.py index f6b55cf15..70aa5b3ea 100644 --- a/tests/test_dependency_security_overrides_openapi.py +++ b/tests/test_dependency_security_overrides_openapi.py @@ -72,66 +72,27 @@ def test_override_with_security(): override_with_header_schema = { - "components": { - "schemas": { - "HTTPValidationError": { - "properties": { - "detail": { - "items": {"$ref": "#/components/schemas/ValidationError"}, - "title": "Detail", - "type": "array", - } - }, - "title": "HTTPValidationError", - "type": "object", - }, - "ValidationError": { - "properties": { - "loc": { - "items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}, - "title": "Location", - "type": "array", - }, - "msg": {"title": "Message", "type": "string"}, - "type": {"title": "Error " "Type", "type": "string"}, - }, - "required": ["loc", "msg", "type"], - "title": "ValidationError", - "type": "object", - }, - } - }, - "info": {"title": "FastAPI", "version": "0.1.0"}, "openapi": "3.1.0", + "info": {"title": "FastAPI", "version": "0.1.0"}, "paths": { "/user": { "get": { + "summary": "Read User", "operationId": "read_user_user_get", "parameters": [ { - "in": "header", "name": "user-id", + "in": "header", "required": True, - "schema": {"title": "User-Id", "type": "integer"}, + "schema": {"type": "integer", "title": "User-Id"}, } ], "responses": { "200": { + "description": "Successful Response", "content": {"application/json": {"schema": {}}}, - "description": "Successful " "Response", - }, - "422": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - }, - "description": "Validation " "Error", - }, + } }, - "summary": "Read User", } } },