Trait utoipa::ToResponse

source ·
pub trait ToResponse<'__r> {
    // Required method
    fn response() -> (&'__r str, RefOr<Response>);
}
Expand description

This trait is implemented to document a type which represents a single response which can be referenced or reused as a component in multiple operations.

ToResponse trait can also be derived with #[derive(ToResponse)].

Examples

use utoipa::{
    openapi::{RefOr, Response, ResponseBuilder},
    ToResponse,
};

struct MyResponse;

impl<'__r> ToResponse<'__r> for MyResponse {
    fn response() -> (&'__r str, RefOr<Response>) {
        (
            "MyResponse",
            ResponseBuilder::new().description("My Response").build().into(),
        )
    }
}

Required Methods§

source

fn response() -> (&'__r str, RefOr<Response>)

Returns a tuple of response component name (to be referenced) to a response.

Implementors§