Skip to content

Commit b7f84d2

Browse files
committed
Added type reduction for enums and some more refactoring
1 parent 0355305 commit b7f84d2

14 files changed

+871
-742
lines changed

gateway-api/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@ features = ["k8s-openapi/v1_32"]
4141
default = ["processed"]
4242
standard = []
4343
experimental = []
44-
processed=[]
44+
processed=[]
45+
46+
47+
[lints.clippy]
48+
derivable_impls="allow"
49+
doc_lazy_continuation="allow"
50+
tabs_in_doc_comments="allow"
51+
empty_line_after_doc_comments="allow"

gateway-api/src/apis/processed/common_types.rs

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@ mod prelude {
1010
}
1111
use self::prelude::*;
1212
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
13-
pub struct HeaderModifierRules {
14-
pub name: String,
15-
pub value: String,
16-
}
17-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
18-
pub struct Kind {
19-
#[serde(default, skip_serializing_if = "Option::is_none")]
20-
pub group: Option<String>,
21-
pub kind: String,
22-
}
23-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
24-
pub struct MirrorBackendRef {
13+
pub struct RouteRef {
2514
#[serde(default, skip_serializing_if = "Option::is_none")]
2615
pub group: Option<String>,
2716
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -31,9 +20,11 @@ pub struct MirrorBackendRef {
3120
pub namespace: Option<String>,
3221
#[serde(default, skip_serializing_if = "Option::is_none")]
3322
pub port: Option<i32>,
23+
#[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")]
24+
pub section_name: Option<String>,
3425
}
3526
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
36-
pub struct RouteRef {
27+
pub struct MirrorBackendRef {
3728
#[serde(default, skip_serializing_if = "Option::is_none")]
3829
pub group: Option<String>,
3930
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -43,8 +34,18 @@ pub struct RouteRef {
4334
pub namespace: Option<String>,
4435
#[serde(default, skip_serializing_if = "Option::is_none")]
4536
pub port: Option<i32>,
46-
#[serde(default, skip_serializing_if = "Option::is_none", rename = "sectionName")]
47-
pub section_name: Option<String>,
37+
}
38+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
39+
pub struct Kind {
40+
#[serde(default, skip_serializing_if = "Option::is_none")]
41+
pub group: Option<String>,
42+
pub kind: String,
43+
}
44+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
45+
pub struct ExtensionBackendRef {
46+
pub group: String,
47+
pub kind: String,
48+
pub name: String,
4849
}
4950
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
5051
pub struct GatewayAddress {
@@ -53,10 +54,77 @@ pub struct GatewayAddress {
5354
pub value: String,
5455
}
5556
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
56-
pub struct ExtensionBackendRef {
57-
pub group: String,
58-
pub kind: String,
57+
pub struct HeaderModifierRules {
5958
pub name: String,
59+
pub value: String,
60+
}
61+
/// RequestRedirect defines a schema for a filter that responds to the
62+
/// request with an HTTP redirection.
63+
///
64+
/// Support: Core
65+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
66+
pub enum FiltersHTTPRedirectRequestRouteRulesScheme {
67+
#[serde(rename = "http")]
68+
Http,
69+
#[serde(rename = "https")]
70+
Https,
71+
}
72+
/// RequestRedirect defines a schema for a filter that responds to the
73+
/// request with an HTTP redirection.
74+
///
75+
/// Support: Core
76+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
77+
pub enum CodeFiltersHTTPRedirectRequestRouteRulesStatus {
78+
#[serde(rename = "301")]
79+
r#_301,
80+
#[serde(rename = "302")]
81+
r#_302,
82+
}
83+
/// GRPCRouteFilter defines processing steps that must be completed during the
84+
/// request or response lifecycle. GRPCRouteFilters are meant as an extension
85+
/// point to express processing that may be done in Gateway implementations. Some
86+
/// examples include request or response modification, implementing
87+
/// authentication strategies, rate-limiting, and traffic shaping. API
88+
/// guarantee/conformance is defined based on the type of the filter.
89+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
90+
pub enum FiltersGRPCRouteRulesType {
91+
ResponseHeaderModifier,
92+
RequestHeaderModifier,
93+
RequestMirror,
94+
ExtensionRef,
95+
}
96+
/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request
97+
/// headers.
98+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
99+
pub enum MatchesRouteRulesType {
100+
Exact,
101+
RegularExpression,
102+
}
103+
/// Path defines parameters used to modify the path of the incoming request.
104+
/// The modified path is then used to construct the `Location` header. When
105+
/// empty, the request path is used as-is.
106+
///
107+
/// Support: Extended
108+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
109+
pub enum FiltersHTTPPathRouteRulesType {
110+
ReplaceFullPath,
111+
ReplacePrefixMatch,
112+
}
113+
/// HTTPRouteFilter defines processing steps that must be completed during the
114+
/// request or response lifecycle. HTTPRouteFilters are meant as an extension
115+
/// point to express processing that may be done in Gateway implementations. Some
116+
/// examples include request or response modification, implementing
117+
/// authentication strategies, rate-limiting, and traffic shaping. API
118+
/// guarantee/conformance is defined based on the type of the filter.
119+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
120+
pub enum FiltersHTTPRouteRulesType {
121+
RequestHeaderModifier,
122+
ResponseHeaderModifier,
123+
RequestMirror,
124+
RequestRedirect,
125+
#[serde(rename = "URLRewrite")]
126+
UrlRewrite,
127+
ExtensionRef,
60128
}
61129

62130

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,26 @@
1-
// WARNING! generated file do not edit
1+
use super::common_types::*;
2+
// WARNING: generated file - manual changes will be overriden
23

3-
use super::httproutes::{
4-
HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType,
5-
HTTPRouteRulesBackendRefsFiltersType,
6-
HTTPRouteRulesBackendRefsFiltersUrlRewritePathType,
7-
HTTPRouteRulesFiltersRequestRedirectPathType, HTTPRouteRulesFiltersType,
8-
HTTPRouteRulesFiltersUrlRewritePathType,
9-
};
10-
use super::grpcroutes::{GRPCRouteRulesBackendRefsFiltersType, GRPCRouteRulesFiltersType};
11-
impl Default for GRPCRouteRulesBackendRefsFiltersType {
4+
impl Default for FiltersGRPCRouteRulesType {
125
fn default() -> Self {
13-
GRPCRouteRulesBackendRefsFiltersType::RequestHeaderModifier
6+
FiltersGRPCRouteRulesType::RequestHeaderModifier
147
}
158
}
16-
impl Default for GRPCRouteRulesFiltersType {
17-
fn default() -> Self {
18-
GRPCRouteRulesFiltersType::RequestHeaderModifier
19-
}
20-
}
21-
impl Default for HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType {
22-
fn default() -> Self {
23-
HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType::ReplaceFullPath
24-
}
25-
}
26-
impl Default for HTTPRouteRulesBackendRefsFiltersType {
27-
fn default() -> Self {
28-
HTTPRouteRulesBackendRefsFiltersType::RequestHeaderModifier
29-
}
30-
}
31-
impl Default for HTTPRouteRulesBackendRefsFiltersUrlRewritePathType {
32-
fn default() -> Self {
33-
HTTPRouteRulesBackendRefsFiltersUrlRewritePathType::ReplaceFullPath
34-
}
35-
}
36-
impl Default for HTTPRouteRulesFiltersRequestRedirectPathType {
9+
10+
impl Default for FiltersHTTPPathRouteRulesType {
3711
fn default() -> Self {
38-
HTTPRouteRulesFiltersRequestRedirectPathType::ReplaceFullPath
12+
FiltersHTTPPathRouteRulesType::ReplaceFullPath
3913
}
4014
}
41-
impl Default for HTTPRouteRulesFiltersType {
15+
16+
impl Default for FiltersHTTPRedirectRequestRouteRulesScheme {
4217
fn default() -> Self {
43-
HTTPRouteRulesFiltersType::RequestHeaderModifier
18+
FiltersHTTPRedirectRequestRouteRulesScheme::Http
4419
}
4520
}
46-
impl Default for HTTPRouteRulesFiltersUrlRewritePathType {
21+
22+
impl Default for FiltersHTTPRouteRulesType {
4723
fn default() -> Self {
48-
HTTPRouteRulesFiltersUrlRewritePathType::ReplaceFullPath
24+
FiltersHTTPRouteRulesType::RequestHeaderModifier
4925
}
5026
}

gateway-api/src/apis/processed/grpcroutes.rs

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -428,20 +428,7 @@ pub struct GRPCRouteRulesBackendRefsFilters {
428428
///
429429
///
430430
#[serde(rename = "type")]
431-
pub r#type: GRPCRouteRulesBackendRefsFiltersType,
432-
}
433-
/// GRPCRouteFilter defines processing steps that must be completed during the
434-
/// request or response lifecycle. GRPCRouteFilters are meant as an extension
435-
/// point to express processing that may be done in Gateway implementations. Some
436-
/// examples include request or response modification, implementing
437-
/// authentication strategies, rate-limiting, and traffic shaping. API
438-
/// guarantee/conformance is defined based on the type of the filter.
439-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
440-
pub enum GRPCRouteRulesBackendRefsFiltersType {
441-
ResponseHeaderModifier,
442-
RequestHeaderModifier,
443-
RequestMirror,
444-
ExtensionRef,
431+
pub r#type: FiltersGRPCRouteRulesType,
445432
}
446433
/// GRPCRouteFilter defines processing steps that must be completed during the
447434
/// request or response lifecycle. GRPCRouteFilters are meant as an extension
@@ -521,20 +508,7 @@ pub struct GRPCRouteRulesFilters {
521508
///
522509
///
523510
#[serde(rename = "type")]
524-
pub r#type: GRPCRouteRulesFiltersType,
525-
}
526-
/// GRPCRouteFilter defines processing steps that must be completed during the
527-
/// request or response lifecycle. GRPCRouteFilters are meant as an extension
528-
/// point to express processing that may be done in Gateway implementations. Some
529-
/// examples include request or response modification, implementing
530-
/// authentication strategies, rate-limiting, and traffic shaping. API
531-
/// guarantee/conformance is defined based on the type of the filter.
532-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
533-
pub enum GRPCRouteRulesFiltersType {
534-
ResponseHeaderModifier,
535-
RequestHeaderModifier,
536-
RequestMirror,
537-
ExtensionRef,
511+
pub r#type: FiltersGRPCRouteRulesType,
538512
}
539513
/// GRPCRouteMatch defines the predicate used to match requests to a given
540514
/// action. Multiple match types are ANDed together, i.e. the match will
@@ -579,17 +553,10 @@ pub struct GRPCRouteRulesMatchesHeaders {
579553
pub name: String,
580554
/// Type specifies how to match against the value of the header.
581555
#[serde(default, skip_serializing_if = "Option::is_none", rename = "type")]
582-
pub r#type: Option<GRPCRouteRulesMatchesHeadersType>,
556+
pub r#type: Option<MatchesRouteRulesType>,
583557
/// Value is the value of the gRPC Header to be matched.
584558
pub value: String,
585559
}
586-
/// GRPCHeaderMatch describes how to select a gRPC route by matching gRPC request
587-
/// headers.
588-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
589-
pub enum GRPCRouteRulesMatchesHeadersType {
590-
Exact,
591-
RegularExpression,
592-
}
593560
/// Method specifies a gRPC request service/method matcher. If this field is
594561
/// not specified, all services and methods will match.
595562
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]
@@ -613,14 +580,7 @@ pub struct GRPCRouteRulesMatchesMethod {
613580
///
614581
/// Support: Implementation-specific (RegularExpression)
615582
#[serde(default, skip_serializing_if = "Option::is_none", rename = "type")]
616-
pub r#type: Option<GRPCRouteRulesMatchesMethodType>,
617-
}
618-
/// Method specifies a gRPC request service/method matcher. If this field is
619-
/// not specified, all services and methods will match.
620-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
621-
pub enum GRPCRouteRulesMatchesMethodType {
622-
Exact,
623-
RegularExpression,
583+
pub r#type: Option<MatchesRouteRulesType>,
624584
}
625585
/// Status defines the current state of GRPCRoute.
626586
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq)]

0 commit comments

Comments
 (0)