juhaku / utoipa

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

Examples not shown with IntoResponses #779

Open hpsjakob opened 11 months ago

hpsjakob commented 11 months ago

Hi,

I'm using utoipa as follows:

#[derive(IntoResponses)]
enum StandardResponses {
    #[response(status = 500, 
        content_type= "text/plain", 
        description = "Internal Error.", 
        example = json!("Internal error."))]
    InternalError,
}

#[utoipa::path(
    post,
    path = "/my_router",
    responses(StandardResponses),
    )]
pub async fn pair_device(){
  todo!()
}

This generates the following JSON output: grafik

I'm missing the content section here. I would have expected it to be shown since I specified content_type and example. Did I get somethign wrong or could it be that I found a bug?

I'm usign version 4.0.0.

Thank you in advance for your time!

hpsjakob commented 11 months ago

I found that this is not the case if I change the enum to

enum StandardResponses {
    #[response(status = 500, 
        content_type= "text/plain", 
        description = "Internal Error.", 
        example = json!("Internal error."))]
    InternalError(String),
}

So I guess utoipa assumes if it's an empty enum that there's now content.

juhaku commented 3 days ago

@hpsjakob Yeah this is related to #965. Currently I believe as you stated that if there is no content then the content-type will not be set. This is something that needs some tuning and we should support this eventually.