drf_yasg doesn't take TYPE_ARRAY as a valid type
Asked Answered
S

1

7

the drf_yasg swagger generator doesnt take TYPE_ARRAY as a valid parameter type. the implementation is as follows

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

whereas the documentation of drf_yasg suggests that it takes openapi.TYPE_ARRAY as valid type.

the error that the generators throws is

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

is there some configuration that i am missing or something because TYPE_STRING,TYPE_NUMBER works perfectly fine.

Spinney answered 27/11, 2018 at 4:41 Comment(0)
G
16

A Parameter of TYPE_ARRAY requires the items key:

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
)

See the OpenAPI 2.0 specification for more details.

Godiva answered 22/12, 2018 at 18:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.