Trait utoipa::openapi::request_body::RequestBodyExt
source · pub trait RequestBodyExt {
// Required method
fn json_schema_ref(self, ref_name: &str) -> Self;
}
Available on crate feature
openapi_extensions
only.Expand description
Trait with convenience functions for documenting request bodies.
With a single method call we can add Content
to our RequestBodyBuilder
and
RequestBody
that references a schema using
content-type "application/json"
.
Add json request body from schema ref.
use utoipa::openapi::request_body::{RequestBodyBuilder, RequestBodyExt};
let request = RequestBodyBuilder::new().json_schema_ref("EmailPayload").build();
If serialized to JSON, the above will result in a requestBody schema like this.
{
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/EmailPayload"
}
}
}
}
Required Methods§
sourcefn json_schema_ref(self, ref_name: &str) -> Self
fn json_schema_ref(self, ref_name: &str) -> Self
Add Content
to RequestBody
referring to a schema
with Content-Type application/json
.
Object Safety§
This trait is not object safe.