ComponentsBuilder

Struct ComponentsBuilder 

Source
pub struct ComponentsBuilder { /* private fields */ }
Expand description

Builder for Components with chainable configuration methods to create a new Components.

Implementations§

Source§

impl ComponentsBuilder

Source

pub fn new() -> ComponentsBuilder

Constructs a new ComponentsBuilder.

Source

pub fn build(self) -> Components

Constructs a new Components taking all fields values from this object.

Source§

impl ComponentsBuilder

Source

pub fn schema<S: Into<String>, I: Into<RefOr<Schema>>>( self, name: S, schema: I, ) -> Self

Add Schema to Components.

Accepts two arguments where first is name of the schema and second is the schema itself.

Source

pub fn schema_from<I: ToSchema>(self) -> Self

Add Schema to Components.

This is effectively same as calling ComponentsBuilder::schema but expects to be called with one generic argument that implements ToSchema trait.

§Examples

Add schema from Value type that derives ToSchema.

 #[derive(ToSchema)]
 struct Value(String);

 let _ = ComponentsBuilder::new().schema_from::<Value>().build();
Source

pub fn schemas_from_iter<I: IntoIterator<Item = (S, C)>, C: Into<RefOr<Schema>>, S: Into<String>>( self, schemas: I, ) -> Self

Add Schemas from iterator.

§Examples
ComponentsBuilder::new().schemas_from_iter([(
    "Pet",
    Schema::from(
        ObjectBuilder::new()
            .property(
                "name",
                ObjectBuilder::new().schema_type(Type::String),
            )
            .required("name")
    ),
)]);
Source

pub fn response<S: Into<String>, R: Into<RefOr<Response>>>( self, name: S, response: R, ) -> Self

Add Response to Components.

Method accepts tow arguments; name of the reusable response and response which is the reusable response itself.

Source

pub fn response_from<'r, I: ToResponse<'r>>(self) -> Self

Add Response to Components.

This behaves the same way as ComponentsBuilder::schema_from but for responses. It allows adding response from type implementing ToResponse trait. Method is expected to be called with one generic argument that implements the trait.

Source

pub fn responses_from_iter<I: IntoIterator<Item = (S, R)>, S: Into<String>, R: Into<RefOr<Response>>>( self, responses: I, ) -> Self

Add multiple Responses to Components from iterator.

Like the ComponentsBuilder::schemas_from_iter this allows adding multiple responses by any iterator what returns tuples of (name, response) values.

Source

pub fn security_scheme<N: Into<String>, S: Into<SecurityScheme>>( self, name: N, security_scheme: S, ) -> Self

Add SecurityScheme to Components.

Accepts two arguments where first is the name of the SecurityScheme. This is later when referenced by SecurityRequirements. Second parameter is the SecurityScheme.

Source

pub fn extensions(self, extensions: Option<Extensions>) -> Self

Add openapi extensions (x-something) of the API.

Trait Implementations§

Source§

impl Default for ComponentsBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Components> for ComponentsBuilder

Source§

fn from(value: Components) -> Self

Converts to this type from the input type.
Source§

impl From<ComponentsBuilder> for Components

Source§

fn from(value: ComponentsBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.