本文整理汇总了Python中drf_yasg.utils.swagger_auto_schema方法的典型用法代码示例。如果您正苦于以下问题:Python utils.swagger_auto_schema方法的具体用法?Python utils.swagger_auto_schema怎么用?Python utils.swagger_auto_schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类drf_yasg.utils
的用法示例。
在下文中一共展示了utils.swagger_auto_schema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: viewset_swagger_helper
# 需要导入模块: from drf_yasg import utils [as 别名]
# 或者: from drf_yasg.utils import swagger_auto_schema [as 别名]
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