Skip to main content

gateway_internal/
http_rule.rs

1/// Represents a rule that maps an RPC method to one or more HTTP REST API methods.
2/// This corresponds to `google.api.HttpRule`.
3#[derive(Debug, Clone, PartialEq)]
4pub struct HttpRule {
5    /// Selects a method to which this rule applies.
6    pub selector: String,
7
8    /// The pattern for the rule.
9    pub pattern: Pattern,
10
11    /// The name of the request field whose value is mapped to the HTTP request body.
12    pub body: String,
13
14    /// The name of the response field whose value is mapped to the HTTP response body.
15    pub response_body: String,
16
17    /// Additional HTTP bindings for the selector.
18    pub additional_bindings: Vec<HttpRule>,
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn test_http_rule_creation() {
27        let rule = HttpRule {
28            selector: "example.Service.Method".to_string(),
29            pattern: Pattern::Get("/v1/example".to_string()),
30            body: "*".to_string(),
31            response_body: "".to_string(),
32            additional_bindings: vec![],
33        };
34
35        assert_eq!(rule.selector, "example.Service.Method");
36        match rule.pattern {
37            Pattern::Get(path) => assert_eq!(path, "/v1/example"),
38            _ => panic!("Expected GET pattern"),
39        }
40    }
41}
42
43#[derive(Debug, Clone, PartialEq)]
44pub enum Pattern {
45    Get(String),
46    Put(String),
47    Post(String),
48    Delete(String),
49    Patch(String),
50    Custom { kind: String, path: String },
51}