use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct WireFieldDescriptor {
pub rust_name: String,
pub wire_name: String,
pub ty: String,
pub required: bool,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub aliases: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct WireTypeDescriptor {
pub name: String,
pub serialized: Vec<WireFieldDescriptor>,
pub deserialized: Vec<WireFieldDescriptor>,
#[serde(default)]
pub closed: bool,
}
impl WireTypeDescriptor {
#[must_use]
pub fn produced(&self, rust_name: &str) -> Option<&WireFieldDescriptor> {
self.serialized.iter().find(|f| f.rust_name == rust_name)
}
#[must_use]
pub fn accepted(&self, rust_name: &str) -> Option<&WireFieldDescriptor> {
self.deserialized.iter().find(|f| f.rust_name == rust_name)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EndpointDescriptor {
pub service: String,
pub name: String,
pub endpoint_ident: String,
pub krate: String,
pub method: String,
pub path: String,
pub request_type: String,
pub response_type: String,
}
impl EndpointDescriptor {
#[must_use]
pub fn id(&self) -> String {
format!("{}.{}", self.service, self.name)
}
#[must_use]
pub fn artifact_file_name(&self) -> String {
format!(
"endpoint.{}.{}.{}.json",
self.krate, self.service, self.name
)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TypeDescriptor {
pub krate: String,
#[serde(flatten)]
pub shape: WireTypeDescriptor,
}
impl TypeDescriptor {
#[must_use]
pub fn artifact_file_name(&self) -> String {
format!("type.{}.{}.json", self.krate, self.shape.name)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ResolvedEndpoint {
pub endpoint: EndpointDescriptor,
pub request: WireTypeDescriptor,
pub response: WireTypeDescriptor,
}