pub struct ComponentsBuilder { /* private fields */ }Expand description
Builder for Components with chainable configuration methods to create a new Components.
Implementations§
Source§impl ComponentsBuilder
impl ComponentsBuilder
Sourcepub fn new() -> ComponentsBuilder
pub fn new() -> ComponentsBuilder
Constructs a new ComponentsBuilder.
Sourcepub fn build(self) -> Components
pub fn build(self) -> Components
Constructs a new Components taking all fields values from this object.
Source§impl ComponentsBuilder
impl ComponentsBuilder
Sourcepub fn schema<S: Into<String>, I: Into<RefOr<Schema>>>(
self,
name: S,
schema: I,
) -> Self
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.
Sourcepub fn schema_from<I: ToSchema>(self) -> Self
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();Sourcepub fn schemas_from_iter<I: IntoIterator<Item = (S, C)>, C: Into<RefOr<Schema>>, S: Into<String>>(
self,
schemas: I,
) -> Self
pub fn schemas_from_iter<I: IntoIterator<Item = (S, C)>, C: Into<RefOr<Schema>>, S: Into<String>>( self, schemas: I, ) -> Self
Sourcepub fn response<S: Into<String>, R: Into<RefOr<Response>>>(
self,
name: S,
response: R,
) -> Self
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.
Sourcepub fn response_from<'r, I: ToResponse<'r>>(self) -> Self
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.
Sourcepub fn responses_from_iter<I: IntoIterator<Item = (S, R)>, S: Into<String>, R: Into<RefOr<Response>>>(
self,
responses: I,
) -> Self
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.
Sourcepub fn security_scheme<N: Into<String>, S: Into<SecurityScheme>>(
self,
name: N,
security_scheme: S,
) -> Self
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.
Sourcepub fn extensions(self, extensions: Option<Extensions>) -> Self
pub fn extensions(self, extensions: Option<Extensions>) -> Self
Add openapi extensions (x-something) of the API.