ToSchema

Trait ToSchema 

Source
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§

Source

fn schema_name() -> &'static str

The name of this schema in the OpenAPI spec.

Source

fn schema() -> Schema

Generate the OpenAPI schema for this type.

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.

Implementations on Foreign Types§

Source§

impl ToSchema for bool

Source§

impl ToSchema for f32

Source§

impl ToSchema for f64

Source§

impl ToSchema for i32

Source§

impl ToSchema for i64

Source§

impl ToSchema for str

Source§

impl ToSchema for u8

Source§

impl ToSchema for u16

Source§

impl ToSchema for u32

Source§

impl ToSchema for String

Source§

impl<T: ToSchema> ToSchema for Option<T>

Source§

impl<T: ToSchema> ToSchema for Vec<T>

Implementors§