这些参数在 swagger_auto_schema (Django) 中意味着什么?

What do these arguments mean in swagger_auto_schema (Django)?

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

@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

responses

responses 参数是该端点可以 return 的可能响应的字典。

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

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

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

  • OK,说明请求是正确的,一切都被正确处理了。 VideoSerializer表示将按照VideoSerializer的结构给出响应,该结构定义了字段的集合。


另外两个参数:

manual_parameters

这是一个自定义参数列表,可以将其添加到请求中以自定义响应。 在本例中,定义了两个参数:

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

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