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

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

    fn describe_components() -> Components { ... }
}
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

Provided methods

Implementations on Foreign Types

Returns empty schema

Implementors