diff --git a/drf_spectacular/openapi.py b/drf_spectacular/openapi.py index ea8aa4ea..9caf79d9 100644 --- a/drf_spectacular/openapi.py +++ b/drf_spectacular/openapi.py @@ -47,14 +47,14 @@ def get_operation(self, path, path_regex, method, registry: ComponentRegistry): self.method = method operation = {} - - summary = self.get_summary() - if summary: - operation['summary'] = summary operation['operationId'] = self.get_operation_id() operation['description'] = self.get_description() + summary = self.get_summary() + if summary: + operation['summary'] = summary + parameters = self._get_parameters() if parameters: operation['parameters'] = parameters @@ -175,6 +175,10 @@ def get_description(self): action_doc = inspect.getdoc(action_or_method) or '' return action_doc or view_doc + def get_summary(self): + """ override this for custom behaviour """ + return None + def get_auth(self): """ Obtains authentication classes and permissions from view. If authentication diff --git a/drf_spectacular/utils.py b/drf_spectacular/utils.py index 6ac283a6..c2b9c193 100644 --- a/drf_spectacular/utils.py +++ b/drf_spectacular/utils.py @@ -46,13 +46,13 @@ def __init__(self, name, type=str, location=QUERY, required=False, description=' def extend_schema( - summary=None, operation_id=None, parameters=None, request=None, responses=None, auth=None, description=None, + summary=None, deprecated=None, tags=None, exclude=False, @@ -64,7 +64,6 @@ def extend_schema( decorator for the "view" kind. partially or completely overrides what would be generated by drf-spectacular. - :param summary: An optional, string summary, intended to apply to all operations in this path. :param operation_id: replaces the auto-generated operation_id. make sure there are no naming collisions. :param parameters: list of additional or replacement parameters added to the @@ -81,6 +80,7 @@ def extend_schema( :param request: replaces the discovered ``Serializer``. :param auth: :param description: replaces discovered doc strings + :param summary: an optional short summary of the description :param deprecated: mark operation as deprecated :param tags: override default list of tags :param exclude: set True to exclude operation from schema @@ -124,10 +124,6 @@ def get_operation(self, path, path_regex, method, registry): return operation return super().get_operation(path, path_regex, method, registry) - def get_summary(self): - if summary and is_in_scope(self): - return summary - def get_operation_id(self): if operation_id and is_in_scope(self): return operation_id @@ -158,6 +154,11 @@ def get_description(self): return description return super().get_description() + def get_summary(self): + if summary and is_in_scope(self): + return summary + return super().get_summary() + def is_deprecated(self): if deprecated and is_in_scope(self): return deprecated diff --git a/tests/test_extend_schema.py b/tests/test_extend_schema.py index 5fcf806d..1102a6e3 100644 --- a/tests/test_extend_schema.py +++ b/tests/test_extend_schema.py @@ -97,6 +97,7 @@ class DoesItAllViewset(viewsets.GenericViewSet): ) ], description='this weird endpoint needs some explaining', + summary='short summary', deprecated=True, tags=['custom_tag'], ) diff --git a/tests/test_extend_schema.yml b/tests/test_extend_schema.yml index f5b6c663..18b96d63 100644 --- a/tests/test_extend_schema.yml +++ b/tests/test_extend_schema.yml @@ -7,6 +7,7 @@ paths: post: operationId: customname_create description: this weird endpoint needs some explaining + summary: short summary parameters: - in: query name: expiration_date