]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻ Strip empty whitespace from description extracted from docstrings (#2821)
authorAndrey Semakin <and-semakin@ya.ru>
Tue, 23 Aug 2022 13:47:19 +0000 (18:47 +0500)
committerGitHub <noreply@github.com>
Tue, 23 Aug 2022 13:47:19 +0000 (13:47 +0000)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
fastapi/routing.py
tests/test_tutorial/test_path_operation_advanced_configurations/test_tutorial004.py

index 2e0d2e552aaf0b9c17fc95d393446c9cc4ea94a3..80bd53279a31fe75898d9607fc2726dd04839e9d 100644 (file)
@@ -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"
index 456e509d5b76a62e7255548f7af268e6ccda3645..3de19833beb2310b24b696ddfad1305bea3673ef 100644 (file)
@@ -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": {