Python drf_yasg.utils.swagger_auto_schema() Examples
The following are 1
code examples of drf_yasg.utils.swagger_auto_schema().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
drf_yasg.utils
, or try the search function
.
Example #1
Source File: swagger.py From opencraft with GNU Affero General Public License v3.0 | 5 votes |
def viewset_swagger_helper( public_actions=None, tags: Optional[List[str]] = None, **action_summary_docs: Optional[str] ) -> Callable: """ A meta-decorator to apply swagger decorators for multiple methods. This decorator simplifies applying multiple decorators by applying sane defaults for swagger decorator, and passing in the supplied values as the summary. Example: @viewset_swagger_helper( list="List Snippets", create="Create new Snippet", destroy="Delete Snippet", public_actions=["list"] ) class SnippetViewSet(ModelViewSet): ... In the above example this function will apply a decorator that will override the operation summary for `list`, `create` and `destroy` for the `SnippetViewSet`. The `public_actions` parameter specifies which actions don't need an authentication and as such won't raise an authentication/authorization error. """ decorators_to_apply = [] public_actions = [] if public_actions is None else public_actions for action in ['list', 'create', 'retrieve', 'update', 'partial_update', 'destroy']: if action in action_summary_docs: decorators_to_apply.append( method_decorator( name=action, decorator=swagger_auto_schema( operation_summary=action_summary_docs.get(action), responses=VALIDATION_RESPONSE if action in public_actions else VALIDATION_AND_AUTH_RESPONSES, tags=tags, security=[] if action in public_actions else None, ), ) ) def inner(viewset): """ Applies all the decorators built up in the decorator list. """ for decorator in decorators_to_apply: viewset = decorator(viewset) return viewset return inner