use std::borrow::Cow;
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SecurityScheme {
#[serde(rename = "type")]
kind: &'static str,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<Cow<'static, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<Cow<'static, str>>,
#[serde(rename = "in", skip_serializing_if = "Option::is_none")]
location: Option<&'static str>,
#[serde(skip_serializing_if = "Option::is_none")]
scheme: Option<&'static str>,
#[serde(skip_serializing_if = "Option::is_none")]
bearer_format: Option<Cow<'static, str>>,
}
impl SecurityScheme {
fn http(scheme: &'static str) -> Self {
Self {
kind: "http",
description: None,
name: None,
location: None,
scheme: Some(scheme),
bearer_format: None,
}
}
fn api_key(location: &'static str, name: impl Into<Cow<'static, str>>) -> Self {
Self {
kind: "apiKey",
description: None,
name: Some(name.into()),
location: Some(location),
scheme: None,
bearer_format: None,
}
}
#[must_use]
pub fn bearer() -> Self {
Self::http("bearer")
}
#[must_use]
pub fn basic() -> Self {
Self::http("basic")
}
#[must_use]
pub fn api_key_header(name: impl Into<Cow<'static, str>>) -> Self {
Self::api_key("header", name)
}
#[must_use]
pub fn api_key_query(name: impl Into<Cow<'static, str>>) -> Self {
Self::api_key("query", name)
}
#[must_use]
pub fn api_key_cookie(name: impl Into<Cow<'static, str>>) -> Self {
Self::api_key("cookie", name)
}
#[must_use]
pub fn description(mut self, description: impl Into<Cow<'static, str>>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn bearer_format(mut self, format: impl Into<Cow<'static, str>>) -> Self {
self.bearer_format = Some(format.into());
self
}
}