feat(import): complete OpenAPI onboarding and verify delivery
CI / Rust Checks (pull_request) Failing after 1s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped

This commit is contained in:
bsodfather committed 2026-10-09 17:50:38 +03:00
1 parent bb3e376767
commit e93de7015a
244 files changed
+57020 -5139

No files matched your search

@@ -1,7 +1,7 @@
use crank_import::rest::{
ExternalDocumentSnapshot, ImportFindingSeverity, NormalizationConfig, NormalizedSchemaKind,
SourceDigest, external_reference_uris, normalize_verified_bundle, normalize_verified_document,
preview_from_ir, reference_uris,
ExternalDocumentSnapshot, ImportFindingSeverity, ImportParseError, NormalizationConfig,
NormalizedSchemaKind, SourceDigest, external_reference_uris, normalize_verified_bundle,
normalize_verified_document, preview_from_ir, reference_uris,
};
fn digest(byte: char) -> SourceDigest {
@@ -189,6 +189,162 @@ paths:
assert!(first.unresolved_references.is_empty());
}
#[test]
fn rejects_duplicate_keys_in_external_snapshot_json_and_yaml_fallback() {
let document = r#"
openapi: 3.1.0
info: { title: Duplicate snapshot keys }
servers: [{ url: https://api.example.test }]
paths:
/items:
get:
operationId: listItems
responses:
'200':
description: ok
content: { application/json: { schema: { $ref: 'https://schemas.example.test/root.yaml#/Item' } } }
"#;
let snapshots = [
r#"{"Item":{"type":"string","type":"integer"}}"#,
"Item: { type: string }\nItem: { type: integer }",
// JSON flow syntax is also accepted by the YAML fallback, so a strict
// JSON duplicate failure must not become a last-key-wins YAML parse.
r#"{"Item":{"type":"string","type":"integer"},"title":"snapshot"}"#,
];
for snapshot in snapshots {
let result = normalize_verified_bundle(
document,
digest('a'),
&[ExternalDocumentSnapshot {
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
digest: digest('b'),
document: snapshot.to_owned(),
}],
&NormalizationConfig::default(),
);
assert!(
result.is_err(),
"duplicate snapshot keys must fail closed: {snapshot}"
);
}
}
#[test]
fn rejects_duplicate_keys_in_new_primary_json_documents() {
let document = r#"{"openapi":"3.1.0","info":{"title":"duplicates","version":"1"},"servers":[{"url":"https://api.example.test"}],"paths":{"/items":{"get":{"operationId":"firstName","operationId":"lastName","responses":{"200":{"description":"ok"}}}}}}"#;
assert!(matches!(
normalize_verified_document(document, digest('a'), &NormalizationConfig::default()),
Err(ImportParseError::InvalidDocument)
));
}
#[test]
fn strict_primary_decoder_preserves_yaml_flow_syntax() {
let document = "openapi: 3.1.0\ninfo: { title: Flow, version: '1' }\nservers: [{ url: https://api.example.test }]\npaths: { /items: { get: { operationId: listItems, responses: { '200': { description: ok } } } } }\n";
assert!(
normalize_verified_document(document, digest('a'), &NormalizationConfig::default()).is_ok()
);
}
#[test]
fn uppercase_external_scheme_is_classified_as_external_reference() {
let document = r#"
openapi: 3.1.0
info: { title: Uppercase external }
servers: [{ url: https://api.example.test }]
paths:
/items:
get:
operationId: listItems
responses:
'200':
description: ok
content: { application/json: { schema: { $ref: 'HTTPS://missing.example/schema.json' } } }
"#;
let ir = normalize(document);
assert!(
ir.operations[0]
.findings
.iter()
.any(|finding| finding.code == "external_reference_disabled"),
"uppercase HTTPS ref must be classified as an external reference, got: {:?}",
ir.operations[0].findings
);
}
#[test]
fn enabled_uppercase_https_ref_with_fragment_is_unavailable() {
let document = r#"
openapi: 3.1.0
info: { title: Uppercase external enabled }
servers: [{ url: https://api.example.test }]
paths:
/items:
get:
operationId: listItems
responses:
'200':
description: ok
content: { application/json: { schema: { $ref: 'HTTPS://missing.example/schema.json#/Item' } } }
"#;
let config = NormalizationConfig {
external_references_enabled: true,
..NormalizationConfig::default()
};
let ir = normalize_verified_document(document, digest('a'), &config).unwrap();
assert!(
ir.operations[0]
.findings
.iter()
.any(|finding| finding.code == "external_reference_unavailable"),
"enabled uppercase HTTPS ref with fragment must be classified unavailable, got: {:?}",
ir.operations[0].findings
);
}
#[test]
fn unicode_idn_reference_matches_punycode_canonical_snapshot() {
let document = r#"
openapi: 3.1.0
info: { title: IDN identity }
servers: [{ url: https://api.example.test }]
paths:
/items:
get:
operationId: listItems
responses:
'200':
description: ok
content: { application/json: { schema: { $ref: 'https://пример.example/schema.json#/Item' } } }
"#;
let snapshots = vec![ExternalDocumentSnapshot {
canonical_uri: "https://xn--e1afmkfd.example/schema.json".to_owned(),
digest: digest('b'),
document: "Item: { type: object, properties: { id: { type: string } } }".to_owned(),
}];
let config = NormalizationConfig {
external_references_enabled: true,
..NormalizationConfig::default()
};
let ir = normalize_verified_bundle(document, digest('a'), &snapshots, &config).unwrap();
assert!(
matches!(
ir.operations[0].response_schema.as_ref().map(|schema| &schema.kind),
Some(NormalizedSchemaKind::Object { properties, .. }) if properties.contains_key("id")
),
"Unicode IDN ref must match the punycode canonical snapshot"
);
assert!(
ir.operations[0]
.findings
.iter()
.all(|finding| !finding.code.starts_with("external_reference")),
"resolved IDN snapshot must not produce external findings: {:?}",
ir.operations[0].findings
);
}
#[test]
fn recursion_is_a_stable_graph_edge_without_unbounded_expansion() {
let document = r#"