pub trait ToSchema {
// Required methods
fn schema_name() -> &'static str;
fn schema() -> Schema;
}Expand description
Types that can generate OpenAPI schemas.
This trait should be implemented for all domain types that need to appear in OpenAPI specifications.
§Example
use domainstack_schema::{ToSchema, Schema};
struct User {
email: String,
age: u8,
}
impl ToSchema for User {
fn schema_name() -> &'static str {
"User"
}
fn schema() -> Schema {
Schema::object()
.property("email", Schema::string().format("email"))
.property("age", Schema::integer().minimum(0).maximum(150))
.required(&["email", "age"])
}
}Required Methods§
Sourcefn schema_name() -> &'static str
fn schema_name() -> &'static str
The name of this schema in the OpenAPI spec.
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.