server: api doc part 3

This commit is contained in:
nym21
2025-10-08 17:48:15 +02:00
parent a53f89c849
commit 114228e8eb
29 changed files with 645 additions and 319 deletions

View File

@@ -1,5 +1,7 @@
mod header_map;
mod response;
mod transform_operation;
pub use header_map::*;
pub use response::*;
pub use transform_operation::*;

View File

@@ -0,0 +1,49 @@
use aide::transform::{TransformOperation, TransformResponse};
use axum::Json;
use schemars::JsonSchema;
pub trait TransformResponseExtended<'t> {
/// 200
fn with_ok_response<R, F>(self, f: F) -> Self
where
R: JsonSchema,
F: FnOnce(TransformResponse<'_, R>) -> TransformResponse<'_, R>;
/// 400
fn with_bad_request(self) -> Self;
/// 404
fn with_not_found(self) -> Self;
/// 304
fn with_not_modified(self) -> Self;
/// 500
fn with_server_error(self) -> Self;
}
impl<'t> TransformResponseExtended<'t> for TransformOperation<'t> {
fn with_ok_response<R, F>(self, f: F) -> Self
where
R: JsonSchema,
F: FnOnce(TransformResponse<'_, R>) -> TransformResponse<'_, R>,
{
self.response_with::<200, Json<R>, _>(|res| f(res.description("Successful response")))
}
fn with_bad_request(self) -> Self {
self.response_with::<400, Json<String>, _>(|res| {
res.description("Invalid request parameters")
})
}
fn with_not_found(self) -> Self {
self.response_with::<404, Json<String>, _>(|res| res.description("Resource not found"))
}
fn with_not_modified(self) -> Self {
self.response_with::<304, (), _>(|res| {
res.description("Not modified - content unchanged since last request")
})
}
fn with_server_error(self) -> Self {
self.response_with::<500, Json<String>, _>(|res| res.description("Internal server error"))
}
}