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

pub trait Entity {
    fn type_name() -> Cow<'static, str>;
fn describe(comp_d: &mut ComponentDescriptor) -> ComponentOrInlineSchema; }
Expand description

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

String uniquely identifying this type, respecting component naming pattern.

If this type is a component, this is the component’s name.

Even if this type is not a component, this is necessary for assembling names of generic components parameterized on underlying types.

Returns

Name of this type, respecting ^[a-zA-Z0-9\.\-_]+$ regex.

Panics

Panic if you decide that this type must not be used for generic parameterization of components.

Describe this entity, and the components it (may) requires.

Implementations on Foreign Types

Returns empty schema

Implementors