From 65a0d59c700b07adb1e492b0cd93645b671aac9a Mon Sep 17 00:00:00 2001 From: Dan Bate Date: Mon, 25 Jun 2018 16:50:45 +0100 Subject: [PATCH] added ability to add sections to custom action documentation --- rest_framework/schemas/inspectors.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rest_framework/schemas/inspectors.py b/rest_framework/schemas/inspectors.py index 89a1fc93a..f108e0d36 100644 --- a/rest_framework/schemas/inspectors.py +++ b/rest_framework/schemas/inspectors.py @@ -233,9 +233,11 @@ class AutoSchema(ViewInspector): method_docstring = getattr(view, method_name, None).__doc__ if method_docstring: # An explicit docstring on the method or action. - return formatting.dedent(smart_text(method_docstring)) + return self._get_description_section(view, method.lower(), formatting.dedent(smart_text(method_docstring))) + else: + return self._get_description_section(view, getattr(view, 'action', method.lower()), view.get_view_description()) - description = view.get_view_description() + def _get_description_section(self, view, header, description): lines = [line for line in description.splitlines()] current_section = '' sections = {'': ''} @@ -249,7 +251,6 @@ class AutoSchema(ViewInspector): # TODO: SCHEMA_COERCE_METHOD_NAMES appears here and in `SchemaGenerator.get_keys` coerce_method_names = api_settings.SCHEMA_COERCE_METHOD_NAMES - header = getattr(view, 'action', method.lower()) if header in sections: return sections[header].strip() if header in coerce_method_names: