Skip to content

[Functionality] Implement Example trait for ApiResponse / ResponseContent #1020

@lucemans

Description

@lucemans

Description of the feature

Implement Example trait for ApiResponse / ResponseContent

Code example (if possible)

In a similar maner to how with the Object macro you can specify

#[derive(Serialize, Deserialize, Object)]
#[oai(example)]
pub struct MyStruct {
    ...
}

You would be able to specify it for arbitrary (user defined) response types

#[derive(ResponseContent)]
#[oai(example)]
enum IcsContent {
    #[oai(content_type = "text/calendar")]
    Calendar(PlainText<String>),
}
    
#[derive(ApiResponse)]
enum CalendarResponse {
    #[oai(status = 200)]
    Ok(IcsContent),
}

const SAMPLE_ICS: &str = include_str!(".//sample.ics");

impl Example for IcsContent {
    fn example() -> Self {
        Self::Calendar(PlainText(SAMPLE_ICS.to_string()))
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions