From 7b8ca1e9121b2f00fc71e3dfae7be635f05d794d Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Thu, 31 Aug 2017 10:28:37 +0200 Subject: [PATCH 1/2] unnecessary strip() breaks markdown formatting --- rest_framework/schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index 437413355..902656f02 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -476,7 +476,7 @@ class SchemaGenerator(object): 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 = {'': ''} From e4a81d290308440243799e15cb9870bc1150d268 Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Thu, 31 Aug 2017 15:06:06 +0200 Subject: [PATCH 2/2] test added --- tests/test_schemas.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index b435dfdd7..d72e0d155 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -496,3 +496,45 @@ class Test4605Regression(TestCase): '/auth/convert-token/' ]) assert prefix == '/' + + +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 + + +class TestDocstringIsNotStrippedByGetDescription(TestCase): + def setUp(self): + self.patterns = [ + url('^example/?$', ExampleDocstringAPIView.as_view()), + ] + + def test_docstring(self): + view = ExampleDocstringAPIView() + generator = SchemaGenerator(title='Example API', patterns=self.patterns) + descr = generator.get_description('example', 'get', view) + # the first and last character are '\n' correctly removed by get_description + assert descr == ExampleDocstringAPIView.__doc__[1:][:-1]