Skip to main content

Content

Trait Content 

Source
pub trait Content {
    const MEDIA_TYPE: &'static str;
    const REQUIRED: bool = true;

    // Required method
    fn schema(generator: &mut SchemaGenerator) -> Schema;
}
Available on crate feature openapi only.
Expand description

A request or response body that an API document can describe.

A type names its media type and the schema of its payload. Pass such a type to Operation::request or Operation::response_with.

Implement it for your own extractors and response types:

use topcoat::openapi::{
    Content,
    schemars::{Schema, SchemaGenerator, json_schema},
};

struct Csv(String);

impl Content for Csv {
    const MEDIA_TYPE: &'static str = "text/csv";

    fn schema(_generator: &mut SchemaGenerator) -> Schema {
        json_schema!({ "type": "string" })
    }
}

Required Associated Constants§

Source

const MEDIA_TYPE: &'static str

The media type of the body, such as application/json.

Provided Associated Constants§

Source

const REQUIRED: bool = true

Whether a request has to carry this body.

Required Methods§

Source

fn schema(generator: &mut SchemaGenerator) -> Schema

Returns the schema of the payload.

Call SchemaGenerator::subschema_for for a payload type that implements JsonSchema, so the document lists the type once and refers to it from every body that uses it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Content for &str

Source§

const MEDIA_TYPE: &'static str = "text/plain"

Source§

fn schema(generator: &mut SchemaGenerator) -> Schema

Source§

impl Content for String

Source§

const MEDIA_TYPE: &'static str = "text/plain"

Source§

fn schema(generator: &mut SchemaGenerator) -> Schema

Source§

impl<T> Content for Option<T>
where T: Content,

A body that a request may leave out.

Source§

const MEDIA_TYPE: &'static str = T::MEDIA_TYPE

Source§

const REQUIRED: bool = false

Source§

fn schema(generator: &mut SchemaGenerator) -> Schema

Implementors§

Source§

impl<T> Content for Form<T>
where T: JsonSchema,

Source§

const MEDIA_TYPE: &'static str = "application/x-www-form-urlencoded"

Source§

impl<T> Content for Json<T>
where T: JsonSchema,

Source§

const MEDIA_TYPE: &'static str = "application/json"