parent
c8f6d16891
commit
9d330d9509
|
|
@ -321,16 +321,32 @@ class SwaggerAutoSchema(ViewInspector):
|
||||||
operation_id = '_'.join(operation_keys)
|
operation_id = '_'.join(operation_keys)
|
||||||
return operation_id
|
return operation_id
|
||||||
|
|
||||||
|
def _extract_description_and_summary(self):
|
||||||
|
description = self.overrides.get('operation_description', None)
|
||||||
|
summary = self.overrides.get('operation_summary', None)
|
||||||
|
if description is None:
|
||||||
|
description = self._sch.get_description(self.path, self.method) or ''
|
||||||
|
description = description.strip().replace('\r', '')
|
||||||
|
|
||||||
|
if description and (summary is None):
|
||||||
|
# description from docstring ... do summary magic
|
||||||
|
# https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings
|
||||||
|
summary_max_len = 120 # OpenAPI 2.0 spec says summary should be under 120 characters
|
||||||
|
sections = description.split('\n\n', 1)
|
||||||
|
if len(sections) == 2:
|
||||||
|
sections[0] = sections[0].strip()
|
||||||
|
if len(sections[0]) < summary_max_len:
|
||||||
|
summary, description = sections
|
||||||
|
|
||||||
|
return description, summary
|
||||||
|
|
||||||
def get_description(self):
|
def get_description(self):
|
||||||
"""Return an operation description determined as appropriate from the view's method and class docstrings.
|
"""Return an operation description determined as appropriate from the view's method and class docstrings.
|
||||||
|
|
||||||
:return: the operation description
|
:return: the operation description
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
description = self.overrides.get('operation_description', None)
|
return self._extract_description_and_summary()[0]
|
||||||
if description is None:
|
|
||||||
description = self._sch.get_description(self.path, self.method)
|
|
||||||
return description
|
|
||||||
|
|
||||||
def get_summary(self):
|
def get_summary(self):
|
||||||
"""Return a summary description for this operation.
|
"""Return a summary description for this operation.
|
||||||
|
|
@ -338,7 +354,7 @@ class SwaggerAutoSchema(ViewInspector):
|
||||||
:return: the summary
|
:return: the summary
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
return self.overrides.get('operation_summary', None)
|
return self._extract_description_and_summary()[1]
|
||||||
|
|
||||||
def get_security(self):
|
def get_security(self):
|
||||||
"""Return a list of security requirements for this operation.
|
"""Return a list of security requirements for this operation.
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,10 @@ class SnippetList(generics.ListCreateAPIView):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
|
"""summary from docstring
|
||||||
|
|
||||||
|
description body is here, summary is not included
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -391,7 +391,8 @@ paths:
|
||||||
- snippets
|
- snippets
|
||||||
delete:
|
delete:
|
||||||
operationId: snippetsDeleteBulk
|
operationId: snippetsDeleteBulk
|
||||||
description: SnippetList classdoc
|
summary: summary from docstring
|
||||||
|
description: description body is here, summary is not included
|
||||||
parameters:
|
parameters:
|
||||||
- name: data
|
- name: data
|
||||||
in: body
|
in: body
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue