pub trait ResponseExt {
// 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 response bodies.
With a single method call we can add Content
to our ResponseBuilder
and Response
that references a schema using content-type "application/json"
.
Add json response from schema ref.
use utoipa::openapi::response::{ResponseBuilder, ResponseExt};
let request = ResponseBuilder::new()
.description("A sample response")
.json_schema_ref("MyResponsePayload").build();
If serialized to JSON, the above will result in a response schema like this.
{
"description": "A sample response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyResponsePayload"
}
}
}
}
Required Methods§
Sourcefn json_schema_ref(self, ref_name: &str) -> Self
fn json_schema_ref(self, ref_name: &str) -> Self
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.