feat(import): complete OpenAPI onboarding and verify delivery
This commit is contained in:
1 parent
bb3e376767
commit
e93de7015a
244 files changed
+57020
-5139
No files matched your search
@@ -1,18 +1,115 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::rest::model::{
|
||||
ImportFinding, NormalizedLiteral, NormalizedOperation, NormalizedScalarKind, NormalizedSchema,
|
||||
NormalizedSchemaKind, RestImportOperation, RestImportParameter, RestRequestBodyVariant,
|
||||
RestResponseVariant,
|
||||
ImportFinding, ImportGroupPreview, ImportOperationCandidate, ImportPreview,
|
||||
ImportSourcePreview, NormalizedLiteral, NormalizedOperation, NormalizedScalarKind,
|
||||
NormalizedSchema, NormalizedSchemaKind, NormalizedSecurityScheme, RestImportDocument,
|
||||
RestImportOperation, RestImportParameter, RestRequestBodyVariant, RestResponseVariant,
|
||||
};
|
||||
|
||||
pub(super) fn preview_from_ir(ir: &crate::rest::model::NormalizedIr) -> ImportPreview {
|
||||
let operations = ir
|
||||
.operations
|
||||
.iter()
|
||||
.map(operation_from_normalized)
|
||||
.collect::<Vec<_>>();
|
||||
let findings = ir
|
||||
.findings
|
||||
.iter()
|
||||
.map(|finding| ImportFinding {
|
||||
code: finding.code.clone(),
|
||||
severity: finding.severity.clone(),
|
||||
message: finding.message.clone(),
|
||||
operation_key: finding.operation_key.clone(),
|
||||
source_location: Some(finding.location.clone()),
|
||||
})
|
||||
.collect();
|
||||
preview_from_operations(
|
||||
&ir.source,
|
||||
operations.iter(),
|
||||
findings,
|
||||
&ir.security_schemes,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn preview_from_document(document: RestImportDocument) -> ImportPreview {
|
||||
let security_schemes = document.security_schemes.clone();
|
||||
let source = ImportSourcePreview {
|
||||
format: document.format,
|
||||
version: document.version,
|
||||
title: document.title,
|
||||
servers: document.servers,
|
||||
};
|
||||
preview_from_operations(
|
||||
&source,
|
||||
document.operations.iter(),
|
||||
document.findings,
|
||||
&security_schemes,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
fn preview_from_operations<'a>(
|
||||
source: &ImportSourcePreview,
|
||||
operations: impl Iterator<Item = &'a RestImportOperation>,
|
||||
mut findings: Vec<ImportFinding>,
|
||||
security_schemes: &BTreeMap<String, NormalizedSecurityScheme>,
|
||||
legacy: bool,
|
||||
) -> ImportPreview {
|
||||
let mut groups: BTreeMap<String, ImportGroupPreview> = BTreeMap::new();
|
||||
let mut used_names = BTreeSet::new();
|
||||
|
||||
for operation in operations {
|
||||
let candidate = if legacy {
|
||||
super::legacy_payload::candidate_from_operation(
|
||||
operation,
|
||||
&source.servers,
|
||||
&mut used_names,
|
||||
)
|
||||
} else {
|
||||
crate::rest::payload::candidate_from_operation(
|
||||
operation,
|
||||
security_schemes,
|
||||
&source.servers,
|
||||
&mut used_names,
|
||||
)
|
||||
};
|
||||
let group_title = operation
|
||||
.tags
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "Без группы".to_owned());
|
||||
let group_key = crate::rest::naming::snake_name(&group_title);
|
||||
groups
|
||||
.entry(group_key.clone())
|
||||
.or_insert_with(|| ImportGroupPreview {
|
||||
key: group_key,
|
||||
title: group_title,
|
||||
operations: Vec::<ImportOperationCandidate>::new(),
|
||||
})
|
||||
.operations
|
||||
.push(candidate);
|
||||
}
|
||||
|
||||
super::normalize_security::attach_operation_findings(&mut groups, &findings);
|
||||
super::normalize::sort_findings(&mut findings);
|
||||
ImportPreview {
|
||||
source: source.clone(),
|
||||
groups: groups.into_values().collect(),
|
||||
findings,
|
||||
conflicts: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn operation_from_normalized(operation: &NormalizedOperation) -> RestImportOperation {
|
||||
RestImportOperation {
|
||||
key: operation.key.clone(),
|
||||
method: operation.method,
|
||||
path: operation.path.clone(),
|
||||
source_location: Some(operation.location.clone()),
|
||||
security_requirements: operation.security_requirements.clone(),
|
||||
operation_id: operation.operation_id.clone(),
|
||||
summary: operation.summary.clone(),
|
||||
@@ -68,6 +165,7 @@ pub(super) fn operation_from_normalized(operation: &NormalizedOperation) -> Rest
|
||||
severity: finding.severity.clone(),
|
||||
message: finding.message.clone(),
|
||||
operation_key: finding.operation_key.clone(),
|
||||
source_location: Some(finding.location.clone()),
|
||||
})
|
||||
.collect(),
|
||||
internal_finding_locations: Vec::new(),
|
||||
|
||||
Reference in new issue
Block a user