-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Multipart Form RawBody Type Support #324
Multipart Form RawBody Type Support #324
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay as I wasn't 100% sure what to do about multipart forms and how best to handle them. A couple thoughts:
- This PR is great, thank you! I think allowing raw access to the form as a convenience is a good idea and will merge it in.
- I think in the future it would be great to have a
huma.Format
that can unmarshal multipart forms into user-defined structs just like you unmarshal JSON, but that's for another PR. For now raw access to the form is a step in the right direction.
Thanks! 🚀
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #324 +/- ##
==========================================
+ Coverage 95.14% 95.28% +0.14%
==========================================
Files 19 19
Lines 2782 2823 +41
==========================================
+ Hits 2647 2690 +43
+ Misses 98 97 -1
+ Partials 37 36 -1 ☔ View full report in Codecov by Sentry. |
@danielgtaylor Hey, no worries. I know that life can get busy. I just wanted to put something in there. I thought I saw you put a comment in a ticket that you were open to folks contributing multipart form support. So, I tried to stick it in there while fitting nicely into the design spirit of what you had there. But your suggestion for number two is fantastic. I had that thought as well. But considering my requirement was uploading files, it seemed like quite a bit of a stretch to try to support a bunch of generic parameters and unmarshaling those into JSON. Also, the structure of the possibilities of the multipart form's key values seems quite flexible to the extent that you might have to make some choices on how the JSON mapping will work. But it would help because you could then get your open API spec to document what properties are available in these multipart form endpoints. Thanks again! |
With this PR the docs now include the following example:
That works. However, ideally the RawBody can also be of the type
I get the warning: Is there a way to use a multipart.Form RawBody and a structured Body at the same time? |
I am in exactly the same situation. |
@JanRuettinger @minpeter good catch. These should be fixed by #329. |
I'm not entirely sure if this is the direction you want to go in. But this makes adding simple upload endpoints more approachable.