#[non_exhaustive]pub enum SecurityScheme {
#[non_exhaustive] ApiKey {
name: String,
location: ParameterIn,
description: Option<String>,
deprecated: Option<bool>,
extensions: Extensions,
},
#[non_exhaustive] Http {
scheme: String,
bearer_format: Option<String>,
description: Option<String>,
deprecated: Option<bool>,
extensions: Extensions,
},
#[non_exhaustive] MutualTls {
description: Option<String>,
deprecated: Option<bool>,
extensions: Extensions,
},
#[non_exhaustive] OAuth2 {
flows: Box<OAuthFlows>,
oauth2_metadata_url: Option<String>,
description: Option<String>,
deprecated: Option<bool>,
extensions: Extensions,
},
#[non_exhaustive] OpenIdConnect {
open_id_connect_url: String,
description: Option<String>,
deprecated: Option<bool>,
extensions: Extensions,
},
}Expand description
A security scheme the API can use.
The variants are the five type values the specification defines. Modelling
them as an enum rather than one struct with conditionally-required fields
means an unusable combination — an apiKey scheme with OAuth flows, say —
cannot be constructed.
#[non_exhaustive] because OpenAPI 3.2 adds to this and the addition is
#[cfg]-gated. Cargo unifies features across a dependency graph, so any
crate enabling openapi32 enables it for every crate in the build – and
without this attribute that would turn a downstream exhaustive match into
a compile error, which is not what “purely additive” is supposed to mean.
§Every variant is sealed too
The attribute above covers a variant being added. 3.2 also adds a field
to every variant already here — deprecated, and oauth2MetadataUrl on
OAuth2 — so each variant carries the attribute as well.
The enum’s does not reach a variant’s field list, and a field list is what
a pattern names.
So a pattern takes .., and reads the same in either build:
fn scheme_of(security: &SecurityScheme) -> Option<&str> {
match security {
SecurityScheme::Http { scheme, .. } => Some(scheme),
_ => None,
}
}Without it, naming every field is a compile error even when the list is
complete for this build — which is the guarantee. It is the error a
downstream crate would otherwise have met the day something else in its
build turned openapi32 on.
fn scheme_of(security: &SecurityScheme) -> Option<&str> {
match security {
SecurityScheme::Http {
scheme,
bearer_format,
description,
deprecated,
extensions,
} => Some(scheme),
_ => None,
}
}Construction goes through the constructors for the same reason:
http, bearer, basic, the
three api_key_*, mutual_tls,
oauth2 and open_id_connect,
then with_description,
with_extension and the rest.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
#[non_exhaustive]ApiKey
A key carried in a header, query parameter or cookie.
Fields
This variant is marked as non-exhaustive
location: ParameterInWhere the key is carried. Only query, header and cookie are legal.
description: Option<String>A description of the scheme. CommonMark syntax may be used.
extensions: ExtensionsSpecification extensions.
#[non_exhaustive]Http
An RFC 7235 Authorization header scheme.
Fields
This variant is marked as non-exhaustive
extensions: ExtensionsSpecification extensions.
#[non_exhaustive]MutualTls
Mutual TLS client certificate authentication.
Kynos declares this automatically when the listener is configured to verify client certificates, so enabling mTLS cannot leave the description silent about it.
Fields
This variant is marked as non-exhaustive
extensions: ExtensionsSpecification extensions.
#[non_exhaustive]OAuth2
OAuth 2.0.
Fields
This variant is marked as non-exhaustive
flows: Box<OAuthFlows>The supported flows.
oauth2_metadata_url: Option<String>A URL to the RFC 8414 authorization server metadata.
Introduced in OpenAPI 3.2.
extensions: ExtensionsSpecification extensions.
#[non_exhaustive]OpenIdConnect
OpenID Connect Discovery.
Fields
This variant is marked as non-exhaustive
extensions: ExtensionsSpecification extensions.
Implementations§
Source§impl SecurityScheme
impl SecurityScheme
Sourcepub fn api_key_header(name: impl Into<String>) -> Self
pub fn api_key_header(name: impl Into<String>) -> Self
An API key carried in a header.
Sourcepub fn api_key_query(name: impl Into<String>) -> Self
pub fn api_key_query(name: impl Into<String>) -> Self
An API key carried in a query parameter.
An API key carried in a cookie.
Sourcepub fn mutual_tls() -> Self
pub fn mutual_tls() -> Self
Mutual TLS client certificate authentication.
Sourcepub fn oauth2(flows: OAuthFlows) -> Self
pub fn oauth2(flows: OAuthFlows) -> Self
OAuth 2.0 with the given flows.
A constructor rather than a struct literal, so the #[cfg]-gated
fields are written down once here instead of at every call site — which
is what a caller in a crate that cannot see the feature needs.
Sourcepub fn open_id_connect(url: impl Into<String>) -> Self
pub fn open_id_connect(url: impl Into<String>) -> Self
OpenID Connect Discovery, against the given metadata URL.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Sets the scheme’s description.
Sourcepub fn with_extension(
self,
key: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_extension( self, key: impl Into<String>, value: impl Into<Value>, ) -> Self
Attaches a specification extension.
Every variant is #[non_exhaustive], so a caller outside this crate
cannot reach extensions through a struct literal; this is how one
arrives. Reading them back needs no method — a pattern with .. still
binds the field.
Sourcepub fn with_deprecated(self, deprecated: bool) -> Self
pub fn with_deprecated(self, deprecated: bool) -> Self
States whether the scheme is deprecated.
deprecate is the common case. This exists because
deprecated: false is a thing a description can say and a round trip
has to keep saying, which a method that only ever writes true cannot
express.
Introduced in OpenAPI 3.2, and a blocker for emitting the document as
3.1 — see emit.
Sourcepub fn deprecate(self) -> Self
pub fn deprecate(self) -> Self
Marks the scheme deprecated.
Introduced in OpenAPI 3.2, and a blocker for emitting the document as
3.1 — see emit.
Sourcepub fn with_oauth2_metadata_url(self, url: impl Into<String>) -> Self
pub fn with_oauth2_metadata_url(self, url: impl Into<String>) -> Self
Sets the RFC 8414 authorization server metadata URL.
Ignored by any scheme that is not OAuth 2.0, because no other kind has the field. Introduced in OpenAPI 3.2.
Trait Implementations§
Source§impl Clone for SecurityScheme
impl Clone for SecurityScheme
Source§impl Debug for SecurityScheme
impl Debug for SecurityScheme
Source§impl<'de> Deserialize<'de> for SecurityScheme
impl<'de> Deserialize<'de> for SecurityScheme
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>,
impl Eq for SecurityScheme
Source§impl PartialEq for SecurityScheme
impl PartialEq for SecurityScheme
Source§impl Serialize for SecurityScheme
impl Serialize for SecurityScheme
impl StructuralPartialEq for SecurityScheme
Auto Trait Implementations§
impl Freeze for SecurityScheme
impl RefUnwindSafe for SecurityScheme
impl Send for SecurityScheme
impl Sync for SecurityScheme
impl Unpin for SecurityScheme
impl UnsafeUnpin for SecurityScheme
impl UnwindSafe for SecurityScheme
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.