SecurityScheme

Enum SecurityScheme 

Source
pub enum SecurityScheme {
    Bearer {
        format: Option<String>,
        description: Option<String>,
    },
    Basic {
        description: Option<String>,
    },
    ApiKey {
        name: String,
        location: ApiKeyLocation,
        description: Option<String>,
    },
    OAuth2 {
        flows: Box<OAuth2Flows>,
        description: Option<String>,
    },
    OpenIdConnect {
        open_id_connect_url: String,
        description: Option<String>,
    },
}
Expand description

OpenAPI security scheme configuration.

This enum represents the different types of security schemes supported by OpenAPI. Each variant maps directly to an OpenAPI security scheme type.

§Supported Schemes

  • Bearer: HTTP Bearer token authentication (RFC 6750)
  • Basic: HTTP Basic authentication (RFC 7617)
  • ApiKey: API key passed in header, query, or cookie
  • OAuth2: OAuth 2.0 authentication flows
  • OpenIdConnect: OpenID Connect Discovery

§Example

use clawspec_core::{SecurityScheme, ApiKeyLocation};

// Simple bearer token
let bearer = SecurityScheme::bearer();

// Bearer with JWT format hint
let jwt = SecurityScheme::bearer_with_format("JWT");

// API key in header
let api_key = SecurityScheme::api_key("X-API-Key", ApiKeyLocation::Header);

// Basic auth
let basic = SecurityScheme::basic();

Variants§

§

Bearer

HTTP Bearer authentication (RFC 6750).

Used for token-based authentication where the client sends an Authorization: Bearer <token> header.

Fields

§format: Option<String>

Optional format hint (e.g., “JWT” for JSON Web Tokens)

§description: Option<String>

Description for documentation

§

Basic

HTTP Basic authentication (RFC 7617).

Uses Authorization: Basic <base64(username:password)> header.

Fields

§description: Option<String>

Description for documentation

§

ApiKey

API Key authentication.

The API key can be passed in a header, query parameter, or cookie.

Fields

§name: String

Name of the header, query parameter, or cookie

§location: ApiKeyLocation

Where the API key is passed

§description: Option<String>

Description for documentation

§

OAuth2

OAuth 2.0 authentication.

Supports multiple OAuth2 flows: authorization code, client credentials, implicit, and password.

Fields

§flows: Box<OAuth2Flows>

OAuth2 flows configuration (boxed to reduce enum size)

§description: Option<String>

Description for documentation

§

OpenIdConnect

OpenID Connect Discovery.

Uses OpenID Connect for authentication with automatic discovery of the provider’s configuration.

Fields

§open_id_connect_url: String

OpenID Connect discovery URL

§description: Option<String>

Description for documentation

Implementations§

Source§

impl SecurityScheme

Source

pub fn bearer() -> Self

Creates a simple HTTP Bearer authentication scheme.

§Example
use clawspec_core::SecurityScheme;

let scheme = SecurityScheme::bearer();
Source

pub fn bearer_with_format(format: impl Into<String>) -> Self

Creates an HTTP Bearer authentication scheme with a format hint.

§Arguments
  • format - Format hint (e.g., “JWT” for JSON Web Tokens)
§Example
use clawspec_core::SecurityScheme;

let scheme = SecurityScheme::bearer_with_format("JWT");
Source

pub fn basic() -> Self

Creates an HTTP Basic authentication scheme.

§Example
use clawspec_core::SecurityScheme;

let scheme = SecurityScheme::basic();
Source

pub fn api_key(name: impl Into<String>, location: ApiKeyLocation) -> Self

Creates an API Key authentication scheme.

§Arguments
  • name - Name of the header, query parameter, or cookie
  • location - Where the API key is passed
§Example
use clawspec_core::{SecurityScheme, ApiKeyLocation};

let scheme = SecurityScheme::api_key("X-API-Key", ApiKeyLocation::Header);
Source

pub fn openid_connect(url: impl Into<String>) -> Self

Creates an OpenID Connect authentication scheme.

§Arguments
  • url - OpenID Connect discovery URL
§Example
use clawspec_core::SecurityScheme;

let scheme = SecurityScheme::openid_connect("https://auth.example.com/.well-known/openid-configuration");
Source

pub fn with_description(self, description: impl Into<String>) -> Self

Adds a description to the security scheme.

§Example
use clawspec_core::SecurityScheme;

let scheme = SecurityScheme::bearer()
    .with_description("JWT token obtained from /auth/login");

Trait Implementations§

Source§

impl Clone for SecurityScheme

Source§

fn clone(&self) -> SecurityScheme

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SecurityScheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SecurityScheme

Source§

fn eq(&self, other: &SecurityScheme) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SecurityScheme

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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