You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thumbnail_data and thumbnail_metadata in the /files/upload/ api endpoint are optional and default to None. The type annotation should be UploadedFile | None but including None makes thumbnail_data and thumbnail_metadata become parameters instead of body payload in the openapi schema.
The workaround of not including None in the annotation shows thumbnail_data and thumbnail_metadata as part of request body as expected, but the annotation is wrong:
tykling
changed the title
Figure out why optional function arguments become parameters instead of body payload in ninja
Figure out why optional function arguments become query parameters instead of body payload in ninja
Dec 23, 2024
tykling
changed the title
Figure out why optional function arguments become query parameters instead of body payload in ninja
Figure out why optional function arguments become query parameters instead of body payload in ninja openapi schema
Dec 23, 2024
src/files/api.py:75: error: Incompatible default for argument "thumbnail_data" (default has type "None", argument has type "UploadedFile") [assignment]
src/files/api.py:75: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/files/api.py:75: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
src/files/api.py:76: error: Incompatible default for argument "thumbnail_metadata" (default has type "None", argument has type "ImageMetadataSchema") [assignment]
src/files/api.py:76: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/files/api.py:76: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
Found 2 errors in 1 file (checked 141 source files)
thumbnail_data
andthumbnail_metadata
in the/files/upload/
api endpoint are optional and default to None. The type annotation should beUploadedFile | None
but including None makesthumbnail_data
andthumbnail_metadata
become parameters instead of body payload in the openapi schema.The workaround of not including None in the annotation shows
thumbnail_data
andthumbnail_metadata
as part of request body as expected, but the annotation is wrong:Shows
thumbnail_data
andthumbnail_metadata
as part of query parameters, but the annotation is correct:The buggy code is in https://github.com/vitalik/django-ninja/blob/be55f63368d6ece4701c356ebec890476691e7fd/ninja/signature/details.py#L218 so create a minimal reproducer and open a ninja issue
The text was updated successfully, but these errors were encountered: