juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.23k stars 173 forks source link

Example on how to use encoding #811

Open DylanVerstraete opened 10 months ago

DylanVerstraete commented 10 months ago

I don't understand how the Encoding struct can be used to add specific encoding to a schema.

For example I have this struct:

pub type Metadata = HashMap<String, String>;

#[derive(MultipartForm, ToSchema, Debug)]
pub struct Upload {
    #[schema(value_type = String, format = Binary)]
    #[multipart(limit = "512 MiB")]
    pub file_content: MultipartBytes,
    pub metadata: Option<Json<Metadata>>,
}

How can I add custom encoding for metadata so that metadata using application/json encoding?

See: https://swagger.io/docs/specification/describing-request-body/multipart-requests/

Specifically (Specifying Content-Type)

wangjia184 commented 3 months ago

+1 for the same question, how to specify file upload via multipart form

I3r1h0n commented 1 month ago

+1 for this question. This is important because, with actix_multipart it doesn't work without specifying "application/json".

juhaku commented 4 days ago

Unfortunately encoding does need to be defined manually by editing the OpenAPI spec path for the handler. Currently there is no implementation in #[utoipa::path()] macro to define Encoding. Though support for this could be added in future releases.