drf_yasg 不将 TYPE_ARRAY 作为有效类型

drf_yasg doesn't take TYPE_ARRAY as a valid type

drf_yasg swagger 生成器不将 TYPE_ARRAY 作为有效参数类型。 实现如下

from drf_yasg import openapi
param1 = openapi.Parameter('param_name',
                            in_=openapi.IN_QUERY,
                            description='description of param',
                            type=openapi.TYPE_ARRAY,
                            required=True
                            )

而 drf_yasg 的 documentation 表明它采用 openapi.TYPE_ARRAY 作为有效类型。

生成器抛出的错误是

File "/usr/local/lib/python3.6/dist-packages/drf_yasg/codecs.py", line 73, in encode
    raise SwaggerValidationError("spec validation failed", errors, spec, self)
drf_yasg.errors.SwaggerValidationError: spec validation failed

是否有一些配置是我遗漏的,或者因为 TYPE_STRING、TYPE_NUMBER 工作得很好。

TYPE_ARRAYParameter 需要 items 键:

param1 = openapi.Parameter('param_name',
                            in_=openapi.IN_QUERY,
                            description='description of param',
                            type=openapi.TYPE_ARRAY,
                            items=openapi.Items(type=openapi.TYPE_STRING)  # <------
                            required=True
)

有关详细信息,请参阅 OpenAPI 2.0 specification