Skip to main content

gateway_internal/
body_mapping.rs

1/// Represents how an HTTP request/response body maps to a protobuf message field.
2#[derive(Debug, Clone, PartialEq)]
3pub struct BodyMapping {
4    /// The field path within the protobuf message that maps to the body.
5    /// If empty or "*", it maps to the entire message.
6    pub field_path: Option<String>,
7}
8
9impl BodyMapping {
10    pub fn is_whole_message(&self) -> bool {
11        match &self.field_path {
12            Some(path) => path == "*" || path.is_empty(),
13            None => true,
14        }
15    }
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn test_is_whole_message() {
24        assert!(BodyMapping { field_path: None }.is_whole_message());
25        assert!(BodyMapping {
26            field_path: Some("*".to_string())
27        }
28        .is_whole_message());
29        assert!(BodyMapping {
30            field_path: Some("".to_string())
31        }
32        .is_whole_message());
33        assert!(!BodyMapping {
34            field_path: Some("data".to_string())
35        }
36        .is_whole_message());
37    }
38}