Closed kevinlutzer closed 1 month ago
I am unfamiliar with the codebase but am equally interested in a feature allowing request bodies with multipart/form-data with files.
RequestBody
is holding a Map of content-type to Content
which looks like this:
So, the utopia structure can already hold multipart/form-data by manually defining the RequestBody.
The macro part of utoipa does not handle multipart/form-data (quick code search with no success).
I will check how to manually add such a RequestBody. After that, I would like to contribute to the macro part of creating multipart/form-data request bodies.
@juhaku Would you have time to discuss the possible API change (I hope to find a way without a breaking change)?
In theory it should be possible. Yet it is true that the examples related to the multipart is sparse if non existing. However the macro does not support setting encoding and it need to be set manually for now.
There are ongoing changes to the macro at the moment which will change the request body definition in macro quite a bid.
#[derive(ToSchema)]
struct MyRequest {
#[schema(format = Binary, value_type = String)]
imageBytes: Vec<u8>,
// ... other fields normally
foobar: String
}
#[utoipa::path(
request_body(content = MyRequest, content_type = "multipart/form-data")
)]
async fn handler() {}
Thanks, worked out perfectly. Adding the encodings of the different fields worked out as well using the manual method.
There is a new PR #1113 for coming utoipa 5.0.0 version with examples for file uploads in OpenAPI 3.1 specification. There are examples for multipart and as well as sending raw binary.
Awesome thanks guys!
Hello!
I want to be able to generate an open API json spec with an API schema containing:
Is this not currently supported by the utoipa macro?