Skip to content

Commit 92bfcd6

Browse files
authoredFeb 27, 2023
Fixes parsing issue #39. (#40)
Moves to actual structs from newtypes for the HttpPathModifier. Signed-off-by: Ryan Thomas <ryan@fl0.com>
1 parent 16bcf65 commit 92bfcd6

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed
 

‎src/httproute.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,13 @@ pub enum HttpPathModifier {
488488
/// ReplaceFullPath specifies the value with which to replace the full path
489489
/// of a request during a rewrite or redirect.
490490
#[serde(rename_all = "camelCase")]
491-
ReplaceFullPath(String),
491+
ReplaceFullPath { replace_full_path: String },
492492

493493
/// ReplacePrefixMatch specifies the value with which to replace the prefix
494494
/// match of a request during a rewrite or redirect. For example, a request
495495
/// to "/foo/bar" with a prefix match of "/foo" would be modified to "/bar".
496496
#[serde(rename_all = "camelCase")]
497-
ReplacePrefixMatch(String),
497+
ReplacePrefixMatch { replace_prefix_match: String },
498498
}
499499

500500
/// HTTPRequestRedirect defines a filter that redirects a request. This filter
@@ -629,3 +629,36 @@ pub struct HttpRouteStatus {
629629
#[serde(flatten)]
630630
pub inner: RouteStatus,
631631
}
632+
633+
#[cfg(test)]
634+
mod test {
635+
use super::*;
636+
637+
#[test]
638+
fn test_deserialize_http_route() {
639+
// Test json with a URLRewrote
640+
let test_json = r#"{
641+
"apiVersion":"gateway.networking.k8s.io/v1beta1",
642+
"kind":"HTTPRoute",
643+
"metadata":{"name":"route_name"},
644+
"spec":{
645+
"parentRefs":null,
646+
"hostnames":null,
647+
"rules":[{
648+
"matches":null,
649+
"filters":[{
650+
"type":"URLRewrite",
651+
"urlRewrite":{
652+
"hostname":null,
653+
"path":{
654+
"type":"ReplacePrefixMatch",
655+
"replacePrefixMatch":"/"
656+
}
657+
}
658+
}],
659+
"backendRefs":null
660+
}]}}"#;
661+
let route: Result<HttpRoute, _> = serde_json::from_str(test_json);
662+
assert!(route.is_ok());
663+
}
664+
}

0 commit comments

Comments
 (0)