这些参数在 swagger_auto_schema (Django) 中是什么意思?

unk*_*own 6 django swagger django-rest-framework drf-yasg

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

@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}
    )
Run Code Online (Sandbox Code Playgroud)

请解释每个论点的责任。我阅读了文档,但了解的很少......特别感兴趣'200': VideoSerializer

Nic*_*oen 7

responses

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

400200分别是HTTP 响应代码、Bad Request 和 OK。

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

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

  • 好的,这意味着请求是正确的,并且一切都被正确处理。VideoSerializer意味着将根据VideoSerializer定义字段集合的的结构给出响应。


另外两个论点:

manual_parameters

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

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

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