footing 0.4.1

Feature-gated foundations for Rust backend services
Documentation
use utoipa::{
    PartialSchema, ToResponse,
    openapi::{Content, RefOr, Response, response::ResponseBuilder},
};

use crate::http::{ApiProblem, ProblemDetails, error::PROBLEM_JSON_MEDIA_TYPE};

/// Creates an RFC 9457 response description for an explicitly selected status.
/// The schema is inline, so the response has no component-registration prerequisite.
#[must_use]
pub fn problem_response(description: impl Into<String>) -> Response {
    ResponseBuilder::new()
        .description(description)
        .content(
            PROBLEM_JSON_MEDIA_TYPE,
            Content::new(Some(ProblemDetails::schema())),
        )
        .build()
}

impl ToResponse<'_> for ApiProblem {
    fn response() -> (&'static str, RefOr<Response>) {
        (
            "ApiProblem",
            problem_response("The request failed; inspect the problem code and details.").into(),
        )
    }
}