vitalik / django-ninja

💨 Fast, Async-ready, Openapi, type hints based framework for building APIs
https://django-ninja.dev
MIT License
7.34k stars 437 forks source link

document how to use an optional file input #1326

Closed toudi closed 1 month ago

toudi commented 1 month ago

It took me a couple of google searches before I understood how to make the optional file input so I thought I'd help other people by extending the docs :)

vitalik commented 1 month ago

thank you

what was you intuitive feeling on how to make it optional ?

toudi commented 1 month ago

I tried couple of things. First thing I tried was to do file: UploadedFile = None, then UploadedFile | None = File(...), (but this one I think exploded on generating schema) then I tried UploadedFile = File(required=False) but then realized that required was not one of the parameters. I think it was due to my lack of experience. I then found the solution by pure accident by browsing trough issues of django-ninja and so I thought that I'd save some other developers some head-scratching time :)