【问题标题】:What do these arguments mean in swagger_auto_schema (Django)?这些参数在 swagger_auto_schema (Django) 中意味着什么?
【发布时间】:2020-02-05 17:07:42
【问题描述】:

该项目使用招摇。 有如下代码。

@swagger_auto_schema(
        manual_parameters=[
            Parameter('download', IN_QUERY,
                      'Set `Content-Disposition=attachment` to make browser to download file'
                      'instead of showing it.',
                      type='bool'),
            Parameter('share_id', IN_PATH, type='uuid')
        ],
        security=[],
        responses={'400': 'Validation Error (e.g. base64 is wrong)',
                   '200': VideoSerializer}
    )

请解释每个参数的作用。 我阅读了文档,但了解甚少... 对'200': VideoSerializer特别感兴趣

【问题讨论】:

    标签: django django-rest-framework swagger drf-yasg


    【解决方案1】:

    responses

    response 参数是该端点可以返回的可能响应的字典。

    400200 分别是 HTTP response codes、Bad Request 和 OK。

    在这种情况下,这意味着该端点可以生成两种类型的响应:

    • 错误的请求也会返回(如所述)验证错误,这意味着请求中的某些内容不正确,这意味着无法正确处理。

    • OK,这意味着请求是正确的,并且一切都得到了正确的处理。 VideoSerializer 表示将按照VideoSerializer 的结构给出响应,该结构定义了一个字段集合。


    另外两个参数:

    manual_parameters

    这是一个自定义参数列表,可以添加到请求中以自定义响应。 在这种情况下,定义了两个参数:

    • download : bool 类型的查询参数。查询参数是这样传递的:`example.com?query_parameter=true
    • share_id,“uuid”类型的路径参数。路径参数是这样传递的:example.com/path_parameter

    security 请求必须遵守的安全方案列表。例如用于基本身份验证。

    【讨论】:

      猜你喜欢
      • 2020-11-30
      • 2011-01-17
      • 1970-01-01
      • 2015-09-13
      • 1970-01-01
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多