aide/openapi/
security_scheme.rs

1#![allow(clippy::large_enum_variant)]
2use indexmap::IndexMap;
3use serde::{Deserialize, Serialize};
4
5/// Defines a security scheme that can be used by the operations.
6/// Supported schemes are HTTP authentication, an API key (either as a
7/// header or as a query parameter), OAuth2's common flows (implicit, password,
8/// application and access code) as defined in RFC6749, and OpenID Connect
9/// Discovery.
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
11#[serde(tag = "type")]
12#[derive(schemars::JsonSchema)]
13pub enum SecurityScheme {
14    #[serde(rename = "apiKey")]
15    ApiKey {
16        #[serde(rename = "in")]
17        location: ApiKeyLocation,
18        name: String,
19        #[serde(skip_serializing_if = "Option::is_none")]
20        description: Option<String>,
21        /// Inline extensions to this object.
22        #[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
23        extensions: IndexMap<String, serde_json::Value>,
24    },
25    #[serde(rename = "http")]
26    Http {
27        scheme: String,
28        #[serde(rename = "bearerFormat")]
29        #[serde(skip_serializing_if = "Option::is_none")]
30        bearer_format: Option<String>,
31        #[serde(skip_serializing_if = "Option::is_none")]
32        description: Option<String>,
33        /// Inline extensions to this object.
34        #[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
35        extensions: IndexMap<String, serde_json::Value>,
36    },
37    #[serde(rename = "oauth2")]
38    OAuth2 {
39        flows: OAuth2Flows,
40        #[serde(skip_serializing_if = "Option::is_none")]
41        description: Option<String>,
42        /// Inline extensions to this object.
43        #[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
44        extensions: IndexMap<String, serde_json::Value>,
45    },
46    #[serde(rename = "openIdConnect")]
47    OpenIdConnect {
48        #[serde(rename = "openIdConnectUrl")]
49        open_id_connect_url: String,
50        #[serde(skip_serializing_if = "Option::is_none")]
51        description: Option<String>,
52        /// Inline extensions to this object.
53        #[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
54        extensions: IndexMap<String, serde_json::Value>,
55    },
56    #[serde(rename = "mutualTLS")]
57    MutualTls {
58        #[serde(skip_serializing_if = "Option::is_none")]
59        description: Option<String>,
60        /// Inline extensions to this object.
61        #[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
62        extensions: IndexMap<String, serde_json::Value>,
63    },
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
67#[serde(rename_all = "camelCase")]
68#[derive(schemars::JsonSchema)]
69pub enum ApiKeyLocation {
70    Query,
71    Header,
72    Cookie,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
76#[serde(rename_all = "camelCase")]
77#[derive(schemars::JsonSchema)]
78pub struct OAuth2Flows {
79    #[serde(flatten)]
80    pub implicit: Option<OAuth2Flow>,
81    #[serde(flatten)]
82    pub password: Option<OAuth2Flow>,
83    #[serde(flatten)]
84    pub client_credentials: Option<OAuth2Flow>,
85    #[serde(flatten)]
86    pub authorization_code: Option<OAuth2Flow>,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
90#[serde(rename_all = "camelCase")]
91#[derive(schemars::JsonSchema)]
92pub enum OAuth2Flow {
93    #[serde(rename_all = "camelCase")]
94    Implicit {
95        authorization_url: String,
96        refresh_url: Option<String>,
97        #[serde(default)]
98        scopes: IndexMap<String, String>,
99    },
100    #[serde(rename_all = "camelCase")]
101    Password {
102        refresh_url: Option<String>,
103        token_url: String,
104        #[serde(default)]
105        scopes: IndexMap<String, String>,
106    },
107    #[serde(rename_all = "camelCase")]
108    ClientCredentials {
109        refresh_url: Option<String>,
110        token_url: String,
111        #[serde(default)]
112        scopes: IndexMap<String, String>,
113    },
114    #[serde(rename_all = "camelCase")]
115    AuthorizationCode {
116        authorization_url: String,
117        token_url: String,
118        refresh_url: Option<String>,
119        #[serde(default)]
120        scopes: IndexMap<String, String>,
121    },
122}