Skip to content

unnecessary strip() breaks markdown formatting #5378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest_framework/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def get_description(self, path, method, view):
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 = {'': ''}

Expand Down
42 changes: 42 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,45 @@ def test_4605_regression(self):
'/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]