story 2-10-security-schemes-secrets: implemented and reviewed via bmad-loop
This commit is contained in:
1 parent
f5f40cb167
commit
ecfb4e788f
45 files changed
+6025
-829
No files matched your search
@@ -9,8 +9,10 @@ use serde_json::Value;
|
||||
/// The immutable contract used to normalize an OpenAPI source. These names
|
||||
/// deliberately travel with an import job: changing either contract must not
|
||||
/// silently reinterpret a pending preview.
|
||||
pub const NORMALIZER_VERSION: &str = "normalized-ir-v4";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v4";
|
||||
pub const NORMALIZER_VERSION: &str = "normalized-ir-v5";
|
||||
pub const PROJECTION_VERSION: &str = "preview-v5";
|
||||
pub const HISTORICAL_NORMALIZER_VERSION: &str = "normalized-ir-v4";
|
||||
pub const HISTORICAL_PROJECTION_VERSION: &str = "preview-v4";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
|
||||
pub struct SourceDigest(String);
|
||||
@@ -232,6 +234,13 @@ pub struct NormalizedOperation {
|
||||
pub key: String,
|
||||
pub method: HttpMethod,
|
||||
pub path: String,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "NormalizedSecurityRequirements::is_empty"
|
||||
)]
|
||||
pub security_requirements: NormalizedSecurityRequirements,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub security_schemes: BTreeMap<String, NormalizedSecurityScheme>,
|
||||
pub operation_id: Option<String>,
|
||||
pub summary: Option<String>,
|
||||
pub description: Option<String>,
|
||||
@@ -251,6 +260,81 @@ pub struct NormalizedOperation {
|
||||
pub findings: Vec<NormalizedFinding>,
|
||||
}
|
||||
|
||||
/// A supported OpenAPI/Swagger authentication scheme, without credential values.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct NormalizedSecurityScheme {
|
||||
pub name: String,
|
||||
pub kind: NormalizedSecuritySchemeKind,
|
||||
pub source_location: SourceLocation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "kind")]
|
||||
pub enum NormalizedSecuritySchemeKind {
|
||||
Http {
|
||||
scheme: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
format_hint: Option<String>,
|
||||
},
|
||||
ApiKey {
|
||||
location: SecurityParameterLocation,
|
||||
parameter_name: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
format_hint: Option<String>,
|
||||
},
|
||||
Unsupported {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
scheme_type: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SecurityParameterLocation {
|
||||
Header,
|
||||
Query,
|
||||
Cookie,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
pub struct NormalizedSecurityRequirements {
|
||||
pub source: SecurityRequirementsSource,
|
||||
/// Each item is one OR alternative; names within an alternative are ANDed.
|
||||
#[serde(default)]
|
||||
pub alternatives: Vec<SecurityRequirementAlternative>,
|
||||
}
|
||||
|
||||
impl NormalizedSecurityRequirements {
|
||||
fn is_empty(&self) -> bool {
|
||||
self.source == SecurityRequirementsSource::None && self.alternatives.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SecurityRequirementsSource {
|
||||
#[default]
|
||||
None,
|
||||
Document,
|
||||
Operation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
pub struct SecurityRequirementAlternative {
|
||||
#[serde(default)]
|
||||
pub schemes: Vec<String>,
|
||||
#[serde(default = "default_supported_security_alternative")]
|
||||
pub supported: bool,
|
||||
#[serde(default)]
|
||||
pub findings: Vec<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub source_location: Option<SourceLocation>,
|
||||
}
|
||||
|
||||
fn default_supported_security_alternative() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NormalizedRequestBodyVariant {
|
||||
pub content_type: String,
|
||||
@@ -387,6 +471,8 @@ pub struct NormalizedIr {
|
||||
#[serde(default)]
|
||||
pub reference_graph: ResolvedReferenceGraph,
|
||||
pub source: ImportSourcePreview,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub security_schemes: BTreeMap<String, NormalizedSecurityScheme>,
|
||||
#[serde(default)]
|
||||
pub operations: Vec<NormalizedOperation>,
|
||||
#[serde(default)]
|
||||
@@ -442,6 +528,13 @@ pub struct ImportOperationCandidate {
|
||||
pub key: String,
|
||||
pub method: HttpMethod,
|
||||
pub path: String,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "NormalizedSecurityRequirements::is_empty"
|
||||
)]
|
||||
pub security_requirements: NormalizedSecurityRequirements,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub security_schemes: BTreeMap<String, NormalizedSecurityScheme>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub operation_id: Option<String>,
|
||||
pub suggested_name: String,
|
||||
@@ -477,6 +570,8 @@ pub struct RestImportDocument {
|
||||
pub version: Option<String>,
|
||||
pub title: String,
|
||||
pub servers: Vec<String>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub security_schemes: BTreeMap<String, NormalizedSecurityScheme>,
|
||||
pub operations: Vec<RestImportOperation>,
|
||||
pub findings: Vec<ImportFinding>,
|
||||
#[serde(skip)]
|
||||
@@ -488,6 +583,11 @@ pub struct RestImportOperation {
|
||||
pub key: String,
|
||||
pub method: HttpMethod,
|
||||
pub path: String,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "NormalizedSecurityRequirements::is_empty"
|
||||
)]
|
||||
pub security_requirements: NormalizedSecurityRequirements,
|
||||
pub operation_id: Option<String>,
|
||||
pub summary: Option<String>,
|
||||
pub description: Option<String>,
|
||||
|
||||
Reference in new issue
Block a user