Add operation_keys to SwaggerAutoSchema constructor (#355)
parent
eed8a8d3ec
commit
a083d3cf7c
|
|
@ -440,7 +440,7 @@ class OpenAPISchemaGenerator(object):
|
||||||
if view_inspector_cls is None:
|
if view_inspector_cls is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
view_inspector = view_inspector_cls(view, path, method, components, request, overrides)
|
view_inspector = view_inspector_cls(view, path, method, components, request, overrides, operation_keys)
|
||||||
operation = view_inspector.get_operation(operation_keys)
|
operation = view_inspector.get_operation(operation_keys)
|
||||||
if operation is None:
|
if operation is None:
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,15 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SwaggerAutoSchema(ViewInspector):
|
class SwaggerAutoSchema(ViewInspector):
|
||||||
def __init__(self, view, path, method, components, request, overrides):
|
def __init__(self, view, path, method, components, request, overrides, operation_keys=None):
|
||||||
super(SwaggerAutoSchema, self).__init__(view, path, method, components, request, overrides)
|
super(SwaggerAutoSchema, self).__init__(view, path, method, components, request, overrides)
|
||||||
self._sch = AutoSchema()
|
self._sch = AutoSchema()
|
||||||
self._sch.view = view
|
self._sch.view = view
|
||||||
|
self.operation_keys = operation_keys
|
||||||
|
|
||||||
|
def get_operation(self, operation_keys=None):
|
||||||
|
operation_keys = operation_keys or self.operation_keys
|
||||||
|
|
||||||
def get_operation(self, operation_keys):
|
|
||||||
consumes = self.get_consumes()
|
consumes = self.get_consumes()
|
||||||
produces = self.get_produces()
|
produces = self.get_produces()
|
||||||
|
|
||||||
|
|
@ -300,7 +303,7 @@ class SwaggerAutoSchema(ViewInspector):
|
||||||
|
|
||||||
return natural_parameters + serializer_parameters
|
return natural_parameters + serializer_parameters
|
||||||
|
|
||||||
def get_operation_id(self, operation_keys):
|
def get_operation_id(self, operation_keys=None):
|
||||||
"""Return an unique ID for this operation. The ID must be unique across
|
"""Return an unique ID for this operation. The ID must be unique across
|
||||||
all :class:`.Operation` objects in the API.
|
all :class:`.Operation` objects in the API.
|
||||||
|
|
||||||
|
|
@ -308,6 +311,8 @@ class SwaggerAutoSchema(ViewInspector):
|
||||||
of this view in the API; e.g. ``('snippets', 'list')``, ``('snippets', 'retrieve')``, etc.
|
of this view in the API; e.g. ``('snippets', 'list')``, ``('snippets', 'retrieve')``, etc.
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
|
operation_keys = operation_keys or self.operation_keys
|
||||||
|
|
||||||
operation_id = self.overrides.get('operation_id', '')
|
operation_id = self.overrides.get('operation_id', '')
|
||||||
if not operation_id:
|
if not operation_id:
|
||||||
operation_id = '_'.join(operation_keys)
|
operation_id = '_'.join(operation_keys)
|
||||||
|
|
@ -369,7 +374,7 @@ class SwaggerAutoSchema(ViewInspector):
|
||||||
"""
|
"""
|
||||||
return self.overrides.get('deprecated', None)
|
return self.overrides.get('deprecated', None)
|
||||||
|
|
||||||
def get_tags(self, operation_keys):
|
def get_tags(self, operation_keys=None):
|
||||||
"""Get a list of tags for this operation. Tags determine how operations relate with each other, and in the UI
|
"""Get a list of tags for this operation. Tags determine how operations relate with each other, and in the UI
|
||||||
each tag will show as a group containing the operations that use it. If not provided in overrides,
|
each tag will show as a group containing the operations that use it. If not provided in overrides,
|
||||||
tags will be inferred from the operation url.
|
tags will be inferred from the operation url.
|
||||||
|
|
@ -378,6 +383,8 @@ class SwaggerAutoSchema(ViewInspector):
|
||||||
of this view in the API; e.g. ``('snippets', 'list')``, ``('snippets', 'retrieve')``, etc.
|
of this view in the API; e.g. ``('snippets', 'list')``, ``('snippets', 'retrieve')``, etc.
|
||||||
:rtype: list[str]
|
:rtype: list[str]
|
||||||
"""
|
"""
|
||||||
|
operation_keys = operation_keys or self.operation_keys
|
||||||
|
|
||||||
tags = self.overrides.get('tags')
|
tags = self.overrides.get('tags')
|
||||||
if not tags:
|
if not tags:
|
||||||
tags = [operation_keys[0]]
|
tags = [operation_keys[0]]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue