mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
5378 fix schema generation markdown (#5421)
* Test case for #5240 * Remove unnecessary strip() from get_description Closes #5240 * Adjust test case
This commit is contained in:
parent
d54df8c438
commit
efff9ff338
|
@ -207,7 +207,7 @@ class AutoSchema(ViewInspector):
|
||||||
return formatting.dedent(smart_text(method_docstring))
|
return formatting.dedent(smart_text(method_docstring))
|
||||||
|
|
||||||
description = view.get_view_description()
|
description = view.get_view_description()
|
||||||
lines = [line.strip() for line in description.splitlines()]
|
lines = [line for line in description.splitlines()]
|
||||||
current_section = ''
|
current_section = ''
|
||||||
sections = {'': ''}
|
sections = {'': ''}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ from rest_framework.schemas import (
|
||||||
AutoSchema, ManualSchema, SchemaGenerator, get_schema_view
|
AutoSchema, ManualSchema, SchemaGenerator, get_schema_view
|
||||||
)
|
)
|
||||||
from rest_framework.test import APIClient, APIRequestFactory
|
from rest_framework.test import APIClient, APIRequestFactory
|
||||||
|
from rest_framework.utils import formatting
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
|
@ -577,3 +578,38 @@ class TestDescriptor(TestCase):
|
||||||
view = CustomView()
|
view = CustomView()
|
||||||
link = view.schema.get_link(path, method, base_url)
|
link = view.schema.get_link(path, method, base_url)
|
||||||
assert link == expected
|
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])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user