axnsan12 / drf-yasg

Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
https://drf-yasg.readthedocs.io/en/stable/
Other
3.36k stars 434 forks source link

Nested serializer in MultiPart form parser #772

Open MatejMijoski opened 2 years ago

MatejMijoski commented 2 years ago

Bug Report

Description

I am getting a drf_yasg.errors.SwaggerGenerationError: cannot instantiate nested serializer as Parameter when using nested serializers with multi part form parser.

Stack trace / Error message

  File "C:\Users\PC\Desktop\api\.venv\lib\site-packages\drf_yasg\inspectors\base.py", line 110, in probe_inspectors
    result = method(obj, **kwargs)
  File "C:\Users\PC\Desktop\api\.venv\lib\site-packages\drf_yasg\inspectors\field.py", line 86, in field_to_swagger_object
    raise SwaggerGenerationError("cannot instantiate nested serializer as " + swagger_object_type.__name__)
drf_yasg.errors.SwaggerGenerationError: cannot instantiate nested serializer as Parameter
HTTP GET /?format=openapi 500 [3.81, 127.0.0.1:51926]

I've tried to solve this by using a serializer inspector and with that, changing the nested serializer as a dictionary of fields but that doesn't seem to work. Is there a workaround for this?

nomidaepapi commented 2 years ago

Any fix?

creyD commented 1 year ago

@nomidaepapi no not yet, as far as I am aware.

mgrsantox commented 1 year ago

I also got the same issue while using the drf-writable-nested package.

codemunsta commented 4 months ago

Still no fix? unfortunately had to remove both form parser and multipart parse from my function definition which means the swagger docs can't take files for those endpoints in the documentation