feat(import): preserve supported HTTP contracts

This commit is contained in:
bsodfather committed 2026-09-13 03:30:31 +03:00
1 parent 083974c27f
commit f8ee7c9bfe
87 files changed
+7496 -534

No files matched your search

+3
View File
@@ -421,6 +421,9 @@ fn demo_rest_operation_payload() -> OperationPayload {
method: crank_core::HttpMethod::Get,
path_template: "/v1/latest".to_owned(),
static_headers: BTreeMap::from([("Accept".to_owned(), "application/json".to_owned())]),
request_contract: None,
response_contract: Vec::new(),
multipart_field_mime_types: BTreeMap::new(),
}),
input_schema: Schema::from_json_sample(&input),
output_schema: Schema::from_json_sample(&output),
+6 -1
View File
@@ -639,7 +639,12 @@ fn import_replay_contract(
if normalizer == NORMALIZER_VERSION && projection == PROJECTION_VERSION {
return Ok(ImportReplayContract::Current);
}
if normalizer != "normalized-ir-v2" || projection != "preview-v2" {
// Historical preview payloads are replayed as their persisted projection.
// They must never be parsed again with the current v4 semantics.
if !matches!(
(normalizer, projection),
("normalized-ir-v2", "preview-v2") | ("normalized-ir-v3", "preview-v3")
) {
return Err(ApiError::openapi_upload(locale, "source_integrity"));
}
@@ -93,7 +93,14 @@ pub(super) fn validate_idempotency_policy(
}
match target {
Target::Rest(rest_target) if rest_target.method != crank_core::HttpMethod::Get => {}
Target::Rest(rest_target)
if matches!(
rest_target.method,
crank_core::HttpMethod::Post
| crank_core::HttpMethod::Put
| crank_core::HttpMethod::Patch
| crank_core::HttpMethod::Delete
) => {}
_ => {
return Err(ApiError::validation_with_context(
"idempotency is supported only for mutating REST operations".to_owned(),
@@ -206,6 +213,9 @@ mod tests {
method: HttpMethod::Get,
path_template: "/catalog".to_owned(),
static_headers: BTreeMap::new(),
request_contract: None,
response_contract: Vec::new(),
multipart_field_mime_types: BTreeMap::new(),
});
let result = validate_response_cache_policy(&target, &cacheable_execution_config());
@@ -233,6 +243,9 @@ mod tests {
method: HttpMethod::Post,
path_template: "/catalog".to_owned(),
static_headers: BTreeMap::new(),
request_contract: None,
response_contract: Vec::new(),
multipart_field_mime_types: BTreeMap::new(),
});
let error =
@@ -252,6 +265,9 @@ mod tests {
method: HttpMethod::Post,
path_template: "/orders".to_owned(),
static_headers: BTreeMap::new(),
request_contract: None,
response_contract: Vec::new(),
multipart_field_mime_types: BTreeMap::new(),
});
let result = validate_idempotency_policy(
@@ -269,6 +285,9 @@ mod tests {
method: HttpMethod::Get,
path_template: "/orders".to_owned(),
static_headers: BTreeMap::new(),
request_contract: None,
response_contract: Vec::new(),
multipart_field_mime_types: BTreeMap::new(),
});
let error = validate_idempotency_policy(
@@ -291,6 +310,9 @@ mod tests {
method: HttpMethod::Post,
path_template: "/orders".to_owned(),
static_headers: BTreeMap::new(),
request_contract: None,
response_contract: Vec::new(),
multipart_field_mime_types: BTreeMap::new(),
});
let mut config = idempotent_execution_config(IdempotencyMode::Required);
let policy = config.idempotency.as_mut().unwrap();