From: Andrey Semakin Date: Tue, 23 Aug 2022 13:47:19 +0000 (+0500) Subject: ♻ Strip empty whitespace from description extracted from docstrings (#2821) X-Git-Tag: 0.80.0~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6808e76dcb332aefe16abab37b0480b16e7cdb1;p=thirdparty%2Ffastapi%2Ffastapi.git ♻ Strip empty whitespace from description extracted from docstrings (#2821) Co-authored-by: Sebastián Ramírez --- diff --git a/fastapi/routing.py b/fastapi/routing.py index 2e0d2e552a..80bd53279a 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -409,7 +409,7 @@ class APIRoute(routing.Route): self.description = description or inspect.cleandoc(self.endpoint.__doc__ or "") # if a "form feed" character (page break) is found in the description text, # truncate description text to the content preceding the first "form feed" - self.description = self.description.split("\f")[0] + self.description = self.description.split("\f")[0].strip() response_fields = {} for additional_status_code, response in self.responses.items(): assert isinstance(response, dict), "An additional response must be a dict" diff --git a/tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py b/tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py index 456e509d5b..3de19833be 100644 --- a/tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py +++ b/tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py @@ -31,7 +31,7 @@ openapi_schema = { }, }, "summary": "Create an item", - "description": "Create an item with all the information:\n\n- **name**: each item must have a name\n- **description**: a long description\n- **price**: required\n- **tax**: if the item doesn't have tax, you can omit this\n- **tags**: a set of unique tag strings for this item\n", + "description": "Create an item with all the information:\n\n- **name**: each item must have a name\n- **description**: a long description\n- **price**: required\n- **tax**: if the item doesn't have tax, you can omit this\n- **tags**: a set of unique tag strings for this item", "operationId": "create_item_items__post", "requestBody": { "content": {