#[non_exhaustive]pub struct SecurityRequirement { /* private fields */ }
Expand description
OpenAPI security requirement object.
Security requirement holds list of required SecurityScheme
names and possible scopes required
to execute the operation. They can be defined in #[utoipa::path(...)]
or in #[openapi(...)]
of OpenApi
.
Applying the security requirement to OpenApi
will make it globally
available to all operations. When applied to specific #[utoipa::path(...)]
will only
make the security requirements available for that operation. Only one of the requirements must be
satisfied.
Implementations§
Source§impl SecurityRequirement
impl SecurityRequirement
Sourcepub fn new<N: Into<String>, S: IntoIterator<Item = I>, I: Into<String>>(
name: N,
scopes: S,
) -> Self
pub fn new<N: Into<String>, S: IntoIterator<Item = I>, I: Into<String>>( name: N, scopes: S, ) -> Self
Construct a new SecurityRequirement
.
Accepts name for the security requirement which must match to the name of available SecurityScheme
.
Second parameter is IntoIterator
of Into<String>
scopes needed by the SecurityRequirement
.
Scopes must match to the ones defined in SecurityScheme
.
§Examples
Create new security requirement with scopes.
SecurityRequirement::new("api_oauth2_flow", ["edit:items", "read:items"]);
You can also create an empty security requirement with Default::default()
.
SecurityRequirement::default();
If you have more than one name in the security requirement you can use
SecurityRequirement::add
.
Sourcepub fn add<N: Into<String>, S: IntoIterator<Item = I>, I: Into<String>>(
self,
name: N,
scopes: S,
) -> Self
pub fn add<N: Into<String>, S: IntoIterator<Item = I>, I: Into<String>>( self, name: N, scopes: S, ) -> Self
Allows to add multiple names to security requirement.
Accepts name for the security requirement which must match to the name of available SecurityScheme
.
Second parameter is IntoIterator
of Into<String>
scopes needed by the SecurityRequirement
.
Scopes must match to the ones defined in SecurityScheme
.
§Examples
Make both API keys required:
#[derive(Debug, Serialize)]
struct Foo;
impl Modify for Foo {
fn modify(&self, openapi: &mut openapi::OpenApi) {
if let Some(schema) = openapi.components.as_mut() {
schema.add_security_scheme(
"api_key1",
SecurityScheme::Http(
HttpBuilder::new()
.scheme(HttpAuthScheme::Bearer)
.bearer_format("JWT")
.build(),
),
);
schema.add_security_scheme(
"api_key2",
SecurityScheme::Http(
HttpBuilder::new()
.scheme(HttpAuthScheme::Bearer)
.bearer_format("JWT")
.build(),
),
);
}
}
}
#[derive(Default, OpenApi)]
#[openapi(
modifiers(&Foo),
security(
("api_key1" = ["edit:items", "read:items"], "api_key2" = ["edit:items", "read:items"]),
)
)]
struct ApiDoc;
Trait Implementations§
Source§impl Clone for SecurityRequirement
impl Clone for SecurityRequirement
Source§fn clone(&self) -> SecurityRequirement
fn clone(&self) -> SecurityRequirement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Default for SecurityRequirement
impl Default for SecurityRequirement
Source§fn default() -> SecurityRequirement
fn default() -> SecurityRequirement
Source§impl<'de> Deserialize<'de> for SecurityRequirement
impl<'de> Deserialize<'de> for SecurityRequirement
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SecurityRequirement
impl PartialEq for SecurityRequirement
Source§impl Serialize for SecurityRequirement
impl Serialize for SecurityRequirement
impl Eq for SecurityRequirement
impl StructuralPartialEq for SecurityRequirement
Auto Trait Implementations§
impl Freeze for SecurityRequirement
impl RefUnwindSafe for SecurityRequirement
impl Send for SecurityRequirement
impl Sync for SecurityRequirement
impl Unpin for SecurityRequirement
impl UnwindSafe for SecurityRequirement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.