Skip to content

Commit

Permalink
5378 fix schema generation markdown (#5421)
Browse files Browse the repository at this point in the history
* Test case for #5240
* Remove unnecessary strip()  from get_description

Closes #5240

* Adjust test case
  • Loading branch information
Carlton Gibson authored and tomchristie committed Sep 14, 2017
1 parent d54df8c commit efff9ff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rest_framework/schemas/inspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {'': ''}

Expand Down
36 changes: 36 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])

0 comments on commit efff9ff

Please sign in to comment.