okapi_operation/axum_integration/
trait_impls.rs1use axum::{Form, Json, response::Html};
2use mime::{APPLICATION_JSON, APPLICATION_WWW_FORM_URLENCODED, TEXT_HTML};
3use okapi::{
4 Map, map,
5 openapi3::{MediaType, RefOr, Response, Responses},
6};
7
8use crate::{
9 Components, ToMediaTypes, ToResponses, impl_to_media_types_for_wrapper,
10 impl_to_responses_for_wrapper,
11};
12
13impl_to_media_types_for_wrapper!(Json<T>, APPLICATION_JSON.to_string());
15impl_to_responses_for_wrapper!(Json<T>);
16
17impl_to_media_types_for_wrapper!(Form<T>, APPLICATION_WWW_FORM_URLENCODED.to_string());
19impl_to_responses_for_wrapper!(Form<T>);
20
21impl<T> ToMediaTypes for Html<T> {
23 fn generate(_components: &mut Components) -> Result<Map<String, MediaType>, anyhow::Error> {
24 Ok(map! {
25 TEXT_HTML.to_string() => MediaType::default()
26 })
27 }
28}
29
30impl<T> ToResponses for Html<T> {
31 fn generate(components: &mut Components) -> Result<Responses, anyhow::Error> {
32 Ok(Responses {
33 responses: map! {
34 "200".into() => RefOr::Object(Response {
35 content: <Self as ToMediaTypes>::generate(components)?,
36 ..Default::default()
37 }),
38 },
39 ..Default::default()
40 })
41 }
42}