#[derive(MultiResponse)]
{
// Attributes available to this derive:
#[multi_response]
#[status]
}
Expand description
Define a multiple response.
This macro will generate 3 implementations, MultiResponse, IntoResponse and ApiResponse.
ยงExample
use predawn::{
define_into_response_error, payload::Json, response_error::WriteJsonError, MultiResponse,
SingleResponse, ToSchema,
};
use serde::Serialize;
#[derive(Debug, Serialize, ToSchema)]
pub struct ErrorSource {
error_code: u16,
error_message: String,
}
#[derive(Debug, SingleResponse)]
pub struct NotFoundAccount;
#[derive(MultiResponse)]
#[multi_response(error = MultipleResponseError)]
pub enum MultipleResponse<T: ToSchema + Serialize> {
#[status = 200]
Ok(Json<T>),
#[status = 404]
NotFound(NotFoundAccount),
#[status = 500]
Error(Json<ErrorSource>),
}
define_into_response_error! {
name: MultipleResponseError,
errors: [
WriteJsonError,
],
}