use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProtocolSupport {
pub protocol: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub endpoint: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiSchema {
pub schema_type: String,
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InteroperabilitySection {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub protocols: Vec<ProtocolSupport>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub api_schemas: Vec<ApiSchema>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub auth_methods: Vec<String>,
}
pub mod protocols {
pub const MCP: &str = "mcp";
pub const A2A: &str = "a2a";
pub const REST: &str = "rest";
pub const GRAPHQL: &str = "graphql";
pub const GRPC: &str = "grpc";
pub const WEBSOCKET: &str = "websocket";
pub const OAS_MAP: &str = "oas-map";
}
pub mod auth_methods {
pub const DID_AUTH: &str = "did-auth";
pub const API_KEY: &str = "api-key";
pub const OAUTH2: &str = "oauth2";
pub const MTLS: &str = "mtls";
pub const BEARER_TOKEN: &str = "bearer-token";
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serde_round_trip() {
let interop = InteroperabilitySection {
protocols: vec![ProtocolSupport {
protocol: protocols::MCP.to_string(),
version: Some("2025-01".to_string()),
endpoint: None,
}],
api_schemas: vec![ApiSchema {
schema_type: "openapi".to_string(),
url: "https://example.com/api.json".to_string(),
version: None,
}],
auth_methods: vec![auth_methods::DID_AUTH.to_string()],
};
let json = serde_json::to_string(&interop).unwrap_or_default();
let parsed: InteroperabilitySection =
serde_json::from_str(&json).unwrap_or_else(|_| interop.clone());
assert_eq!(interop, parsed);
}
#[test]
fn empty_section_deserializes() {
let json = r#"{}"#;
let interop: Result<InteroperabilitySection, _> = serde_json::from_str(json);
assert!(interop.is_ok());
}
}