Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: [OpenAPI] Upload file is not possible when defined as Optional #3459

Open
1 of 4 tasks
vkuznetsovgn opened this issue May 2, 2024 · 2 comments
Open
1 of 4 tasks
Labels
Bug 🐛 This is something that is not working as expected

Comments

@vkuznetsovgn
Copy link

vkuznetsovgn commented May 2, 2024

Description

When defining an UploadFile as Optional the upload file button disappears.
Removing the Optional makes the button to be present but there's no way not to specify the file anymore as there's no send empty value checkbox in this case.

Screenshot from 2024-05-02 11-21-23

MCVE

from typing import Annotated, Optional
from pydantic import BaseModel, ConfigDict
from litestar.datastructures import UploadFile
from litestar.enums import RequestEncodingType
from litestar.params import Body

class FormData(BaseModel):
    model_config = ConfigDict(arbitrary_types_allowed=True)
    
    file: Optional[UploadFile]
    some_params: dict


@post("/test")
async def handle_file(data: Annotated[FormData, Body(media_type=RequestEncodingType.MULTI_PART)]) -> None:
    print(data.file)


app = Litestar(route_handlers=[handle_file])

Litestar Version

2.8.2

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@vkuznetsovgn vkuznetsovgn added the Bug 🐛 This is something that is not working as expected label May 2, 2024
@peterschutt
Copy link
Contributor

I believe a dup of this: #3411

@vkuznetsovgn
Copy link
Author

vkuznetsovgn commented May 2, 2024

@peterschutt Possibly but I'm not sure as the OpenAPI UI looks differently in your case. Maybe we could merge two issues. In my case, there's also no send empty value checkmark available without the Optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants