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, I>(self, name: S, schema: I) -> ComponentsBuilder
where S: Into<String>, I: Into<RefOr<Schema>>,

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>(self) -> ComponentsBuilder
where I: ToSchema,

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, C, S>(self, schemas: I) -> ComponentsBuilder
where I: IntoIterator<Item = (S, C)>, C: Into<RefOr<Schema>>, S: Into<String>,

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, R>(self, name: S, response: R) -> ComponentsBuilder
where S: Into<String>, R: Into<RefOr<Response>>,

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>(self) -> ComponentsBuilder
where I: ToResponse<'r>,

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, S, R>(self, responses: I) -> ComponentsBuilder
where I: IntoIterator<Item = (S, R)>, S: Into<String>, R: Into<RefOr<Response>>,

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, S>( self, name: N, security_scheme: S, ) -> ComponentsBuilder
where N: Into<String>, S: Into<SecurityScheme>,

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>) -> ComponentsBuilder

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

Trait Implementations§

Source§

impl Default for ComponentsBuilder

Source§

fn default() -> ComponentsBuilder

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

impl From<Components> for ComponentsBuilder

Source§

fn from(value: Components) -> ComponentsBuilder

Converts to this type from the input type.
Source§

impl From<ComponentsBuilder> for Components

Source§

fn from(value: ComponentsBuilder) -> Components

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more