From 64f88569243c38847ce1a6b2d9768c09c9055ad3 Mon Sep 17 00:00:00 2001 From: Konstantin Zangerle Date: Wed, 4 Jun 2025 15:52:24 +0200 Subject: [PATCH] make compatible with 3.8 --- fastapi/openapi/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index c2cb8b5df..be23ba346 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -100,7 +100,7 @@ def _get_openapi_operation_parameters( field_mapping: Dict[ Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue ], - field_docstring: Dict[str, str] | None = None, + field_docstring: Optional[Dict[str, str]] = None, separate_input_output_schemas: bool = True, ) -> List[Dict[str, Any]]: parameters = [] @@ -240,9 +240,12 @@ def get_openapi_operation_metadata( operation["description"] = "\n\n".join( [i.value for i in route.parsed_docstring if i.kind == "text"] ) + operation["description"] = operation["description"].split("\f")[0].strip() + if not operation["description"]: + del operation["description"] if route.description: operation["description"] = route.description - operation["description"] = operation["description"].split("\f")[0].strip() + operation["description"] = operation["description"].split("\f")[0].strip() operation_id = route.operation_id or route.unique_id if operation_id in operation_ids: