From efff9ff338bb0994b3249fa9907bb7018d7b6d5e Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Thu, 14 Sep 2017 13:20:41 +0200 Subject: [PATCH] 5378 fix schema generation markdown (#5421) * Test case for #5240 * Remove unnecessary strip() from get_description Closes #5240 * Adjust test case --- rest_framework/schemas/inspectors.py | 2 +- tests/test_schemas.py | 36 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/rest_framework/schemas/inspectors.py b/rest_framework/schemas/inspectors.py index cd9fa73da9..a91205cde9 100644 --- a/rest_framework/schemas/inspectors.py +++ b/rest_framework/schemas/inspectors.py @@ -207,7 +207,7 @@ def get_description(self, path, method): return formatting.dedent(smart_text(method_docstring)) description = view.get_view_description() - lines = [line.strip() for line in description.splitlines()] + lines = [line for line in description.splitlines()] current_section = '' sections = {'': ''} diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 14ed0f6b6f..f8a63aa897 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -15,6 +15,7 @@ AutoSchema, ManualSchema, SchemaGenerator, get_schema_view ) from rest_framework.test import APIClient, APIRequestFactory +from rest_framework.utils import formatting from rest_framework.views import APIView from rest_framework.viewsets import ModelViewSet @@ -577,3 +578,38 @@ class CustomView(APIView): view = CustomView() link = view.schema.get_link(path, method, base_url) assert link == expected + + +def test_docstring_is_not_stripped_by_get_description(): + class ExampleDocstringAPIView(APIView): + """ + === title + + * item a + * item a-a + * item a-b + * item b + + - item 1 + - item 2 + + code block begin + code + code + code + code block end + + the end + """ + + def get(self, *args, **kwargs): + pass + + def post(self, request, *args, **kwargs): + pass + + view = ExampleDocstringAPIView() + schema = view.schema + descr = schema.get_description('example', 'get') + # the first and last character are '\n' correctly removed by get_description + assert descr == formatting.dedent(ExampleDocstringAPIView.__doc__[1:][:-1])