Trait rweb::openapi::Entity[][src]

pub trait Entity {
    fn describe() -> Schema;

    fn describe_components() -> Components { ... }
}

This can be derived by #[derive(Schema)].

#[derive(Schema)]

It implements Entity for the struct or enum. Note that it’s recommended to use derive(Schema) even when you are not using openapi, as it is noop when cargo feature openapi is disabled.

Overriding description

use rweb::*;

/// private documentation, for example
#[derive(Debug, Default, Schema)]
// #[schema(description = "This is output!!")]
pub struct Output {
    /// By default, doc comments become description
    data: String,
    /// Another private info like implementation detail.
    #[schema(description = "field")]
    field_example: String,
}

Component

use rweb::*;
use serde::{Serialize, Deserialize};

// This item is stored at #/components/schema/Item
#[derive(Debug, Serialize, Deserialize, Schema)]
#[schema(component = "Item")]
struct ComponentTestReq {
    data: String,
}

Example value

#[schema(example = $path)] is supported. If $path is a literal, it’s automatically converted into json value. Otherwise, you should provide an expression to get example value.

use rweb::*;
use serde::{Serialize, Deserialize};

// This item is stored at #/components/schema/Item
#[derive(Debug, Serialize, Deserialize, Schema)]
struct ExampleTest {
    #[schema(example = "10")]
    data: usize,
    #[schema(example = "\"Example for string values must be escaped like this\"")]
    s: String,
    #[schema(example = "complex_example()")]
    complex: String,
}

fn complex_example() -> serde_json::Value {
    serde_json::Value::String(String::from("this is example!"))
}

Required methods

Loading content...

Provided methods

Loading content...

Implementations on Foreign Types

impl Entity for ()[src]

fn describe() -> Schema[src]

Returns empty schema

impl Entity for u8[src]

impl Entity for u16[src]

impl Entity for u32[src]

impl Entity for u64[src]

impl Entity for u128[src]

impl Entity for usize[src]

impl Entity for i8[src]

impl Entity for i16[src]

impl Entity for i32[src]

impl Entity for i64[src]

impl Entity for i128[src]

impl Entity for isize[src]

impl Entity for f32[src]

impl Entity for f64[src]

impl Entity for bool[src]

impl Entity for char[src]

impl Entity for str[src]

impl<T: ?Sized> Entity for Box<T> where
    T: Entity
[src]

impl<'a, T: ?Sized> Entity for &'a T where
    T: Entity
[src]

impl<T: Entity> Entity for Vec<T>[src]

impl<T: Entity> Entity for [T][src]

impl<T> Entity for Option<T> where
    T: Entity
[src]

impl Entity for String[src]

impl<T, E> Entity for Result<T, E> where
    T: Entity,
    E: Entity
[src]

impl<V> Entity for BTreeSet<V> where
    V: Entity
[src]

impl<V, S> Entity for HashSet<V, S> where
    V: Entity
[src]

impl<V> Entity for LinkedList<V> where
    V: Entity
[src]

impl<V> Entity for VecDeque<V> where
    V: Entity
[src]

impl Entity for Infallible[src]

impl Entity for Value[src]

Loading content...

Implementors

Loading content...