Skip to content

Commit efff9ff

Browse files
Carlton Gibsontomchristie
authored andcommitted
5378 fix schema generation markdown (#5421)
* Test case for #5240 * Remove unnecessary strip() from get_description Closes #5240 * Adjust test case
1 parent d54df8c commit efff9ff

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

rest_framework/schemas/inspectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def get_description(self, path, method):
207207
return formatting.dedent(smart_text(method_docstring))
208208

209209
description = view.get_view_description()
210-
lines = [line.strip() for line in description.splitlines()]
210+
lines = [line for line in description.splitlines()]
211211
current_section = ''
212212
sections = {'': ''}
213213

tests/test_schemas.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
AutoSchema, ManualSchema, SchemaGenerator, get_schema_view
1616
)
1717
from rest_framework.test import APIClient, APIRequestFactory
18+
from rest_framework.utils import formatting
1819
from rest_framework.views import APIView
1920
from rest_framework.viewsets import ModelViewSet
2021

@@ -577,3 +578,38 @@ class CustomView(APIView):
577578
view = CustomView()
578579
link = view.schema.get_link(path, method, base_url)
579580
assert link == expected
581+
582+
583+
def test_docstring_is_not_stripped_by_get_description():
584+
class ExampleDocstringAPIView(APIView):
585+
"""
586+
=== title
587+
588+
* item a
589+
* item a-a
590+
* item a-b
591+
* item b
592+
593+
- item 1
594+
- item 2
595+
596+
code block begin
597+
code
598+
code
599+
code
600+
code block end
601+
602+
the end
603+
"""
604+
605+
def get(self, *args, **kwargs):
606+
pass
607+
608+
def post(self, request, *args, **kwargs):
609+
pass
610+
611+
view = ExampleDocstringAPIView()
612+
schema = view.schema
613+
descr = schema.get_description('example', 'get')
614+
# the first and last character are '\n' correctly removed by get_description
615+
assert descr == formatting.dedent(ExampleDocstringAPIView.__doc__[1:][:-1])

0 commit comments

Comments
 (0)