feat(import): preserve supported HTTP contracts
This commit is contained in:
1 parent
083974c27f
commit
f8ee7c9bfe
87 files changed
+7496
-534
No files matched your search
@@ -150,6 +150,7 @@ pub struct PreparedRequest {
|
||||
pub headers: BTreeMap<String, String>,
|
||||
pub trusted_header_names: BTreeSet<String>,
|
||||
pub body: Option<Value>,
|
||||
pub body_content_type: Option<String>,
|
||||
pub timeout_ms: u64,
|
||||
}
|
||||
|
||||
@@ -162,6 +163,10 @@ impl std::fmt::Debug for PreparedRequest {
|
||||
.field("header_count", &self.headers.len())
|
||||
.field("trusted_header_count", &self.trusted_header_names.len())
|
||||
.field("body_configured", &self.body.is_some())
|
||||
.field(
|
||||
"body_content_type_configured",
|
||||
&self.body_content_type.is_some(),
|
||||
)
|
||||
.field("timeout_ms", &self.timeout_ms)
|
||||
.finish()
|
||||
}
|
||||
@@ -333,6 +338,9 @@ mod tests {
|
||||
method: crate::HttpMethod::Get,
|
||||
path_template: "/health".to_owned(),
|
||||
static_headers: Default::default(),
|
||||
request_contract: None,
|
||||
response_contract: Vec::new(),
|
||||
multipart_field_mime_types: Default::default(),
|
||||
});
|
||||
|
||||
let response = adapter
|
||||
|
||||
@@ -169,7 +169,8 @@ pub use operation::{
|
||||
OperationApprovalPayloadPreviewMode, OperationApprovalPolicy, OperationApprovalRiskLevel,
|
||||
OperationAvailability, OperationLifecycle, OperationLifecycleAction, OperationLifecycleError,
|
||||
OperationSafetyClass, OperationSafetyPolicy, OperationStatus, OperationVersionState,
|
||||
ResponseCachePolicy, RestTarget, RetryPolicy, Samples, Target, ToolDescription, ToolExample,
|
||||
ResponseCachePolicy, RestRequestContract, RestRequestContractVersion, RestRequestDescriptor,
|
||||
RestResponseDescriptor, RestTarget, RetryPolicy, Samples, Target, ToolDescription, ToolExample,
|
||||
WizardState,
|
||||
};
|
||||
pub use product_event::{
|
||||
|
||||
@@ -101,6 +101,62 @@ pub struct RestTarget {
|
||||
pub path_template: String,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub static_headers: BTreeMap<String, String>,
|
||||
/// Typed request-body metadata used by Operations generated by the HTTP
|
||||
/// contract importer. `None` preserves the preparation and JSON wire
|
||||
/// behavior of Operations persisted before this contract existed.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub request_contract: Option<RestRequestContract>,
|
||||
/// The successful HTTP responses accepted by this Operation. An empty
|
||||
/// contract retains the permissive behavior of Operations persisted
|
||||
/// before response variants were made explicit.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub response_contract: Vec<RestResponseDescriptor>,
|
||||
/// Source-declared MIME choices for multipart file fields, keyed first by
|
||||
/// request media type and then by field name. Empty retains the behavior
|
||||
/// of Operations persisted before multipart contracts were explicit.
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub multipart_field_mime_types: BTreeMap<String, BTreeMap<String, Vec<String>>>,
|
||||
}
|
||||
|
||||
/// A single successful REST response branch.
|
||||
///
|
||||
/// `media_type: None` represents the explicit no-content branch. A response
|
||||
/// with a body must select a branch with the exact status and media type.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RestResponseDescriptor {
|
||||
pub status_code: u16,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub media_type: Option<String>,
|
||||
/// Index of the matching branch in `Operation.output_schema`. A scalar
|
||||
/// output schema uses index zero.
|
||||
pub schema_variant: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum RestRequestContractVersion {
|
||||
#[serde(rename = "1")]
|
||||
V1,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RestRequestContract {
|
||||
pub version: RestRequestContractVersion,
|
||||
pub body_field: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub selector_field: Option<String>,
|
||||
pub body_required: bool,
|
||||
pub variants: Vec<RestRequestDescriptor>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RestRequestDescriptor {
|
||||
pub media_type: String,
|
||||
/// Index of the matching top-level `Operation.input_schema` branch. A
|
||||
/// request contract without a top-level union uses index zero.
|
||||
pub schema_variant: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -406,6 +462,9 @@ mod tests {
|
||||
method: HttpMethod::Post,
|
||||
path_template: "/v1/leads".to_owned(),
|
||||
static_headers: BTreeMap::new(),
|
||||
request_contract: None,
|
||||
response_contract: Vec::new(),
|
||||
multipart_field_mime_types: BTreeMap::new(),
|
||||
});
|
||||
|
||||
let value = serde_json::to_value(target).unwrap();
|
||||
@@ -571,6 +630,8 @@ updated_at: 2026-03-25T08:10:00Z
|
||||
|
||||
assert_eq!(restored.security_level, OperationSecurityLevel::Standard);
|
||||
assert_eq!(restored.published_at, None);
|
||||
let Target::Rest(target) = restored.target;
|
||||
assert!(target.response_contract.is_empty());
|
||||
}
|
||||
|
||||
fn test_operation(status: OperationStatus) -> Operation<serde_json::Value, serde_json::Value> {
|
||||
@@ -588,6 +649,9 @@ updated_at: 2026-03-25T08:10:00Z
|
||||
method: HttpMethod::Post,
|
||||
path_template: "/v1/leads".to_owned(),
|
||||
static_headers: BTreeMap::new(),
|
||||
request_contract: None,
|
||||
response_contract: Vec::new(),
|
||||
multipart_field_mime_types: BTreeMap::new(),
|
||||
}),
|
||||
input_schema: json!({"type":"object","fields":{"email":{"type":"string","required":true}}}),
|
||||
output_schema: json!({"type":"object","fields":{"id":{"type":"string","required":true}}}),
|
||||
|
||||
@@ -14,6 +14,8 @@ pub enum HttpMethod {
|
||||
Put,
|
||||
Patch,
|
||||
Delete,
|
||||
Head,
|
||||
Options,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
Reference in new issue
Block a user