k8s_openapi/v1_32/api/flowcontrol/v1/
flow_schema_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct FlowSchemaSpec {
6 pub distinguisher_method: Option<crate::api::flowcontrol::v1::FlowDistinguisherMethod>,
8
9 pub matching_precedence: Option<i32>,
11
12 pub priority_level_configuration: crate::api::flowcontrol::v1::PriorityLevelConfigurationReference,
14
15 pub rules: Option<Vec<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>>,
17}
18
19impl crate::DeepMerge for FlowSchemaSpec {
20 fn merge_from(&mut self, other: Self) {
21 crate::DeepMerge::merge_from(&mut self.distinguisher_method, other.distinguisher_method);
22 crate::DeepMerge::merge_from(&mut self.matching_precedence, other.matching_precedence);
23 crate::DeepMerge::merge_from(&mut self.priority_level_configuration, other.priority_level_configuration);
24 crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
25 }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for FlowSchemaSpec {
29 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30 #[allow(non_camel_case_types)]
31 enum Field {
32 Key_distinguisher_method,
33 Key_matching_precedence,
34 Key_priority_level_configuration,
35 Key_rules,
36 Other,
37 }
38
39 impl<'de> crate::serde::Deserialize<'de> for Field {
40 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41 struct Visitor;
42
43 impl crate::serde::de::Visitor<'_> for Visitor {
44 type Value = Field;
45
46 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 f.write_str("field identifier")
48 }
49
50 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51 Ok(match v {
52 "distinguisherMethod" => Field::Key_distinguisher_method,
53 "matchingPrecedence" => Field::Key_matching_precedence,
54 "priorityLevelConfiguration" => Field::Key_priority_level_configuration,
55 "rules" => Field::Key_rules,
56 _ => Field::Other,
57 })
58 }
59 }
60
61 deserializer.deserialize_identifier(Visitor)
62 }
63 }
64
65 struct Visitor;
66
67 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68 type Value = FlowSchemaSpec;
69
70 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 f.write_str("FlowSchemaSpec")
72 }
73
74 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75 let mut value_distinguisher_method: Option<crate::api::flowcontrol::v1::FlowDistinguisherMethod> = None;
76 let mut value_matching_precedence: Option<i32> = None;
77 let mut value_priority_level_configuration: Option<crate::api::flowcontrol::v1::PriorityLevelConfigurationReference> = None;
78 let mut value_rules: Option<Vec<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>> = None;
79
80 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81 match key {
82 Field::Key_distinguisher_method => value_distinguisher_method = crate::serde::de::MapAccess::next_value(&mut map)?,
83 Field::Key_matching_precedence => value_matching_precedence = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_priority_level_configuration => value_priority_level_configuration = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_rules => value_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87 }
88 }
89
90 Ok(FlowSchemaSpec {
91 distinguisher_method: value_distinguisher_method,
92 matching_precedence: value_matching_precedence,
93 priority_level_configuration: value_priority_level_configuration.unwrap_or_default(),
94 rules: value_rules,
95 })
96 }
97 }
98
99 deserializer.deserialize_struct(
100 "FlowSchemaSpec",
101 &[
102 "distinguisherMethod",
103 "matchingPrecedence",
104 "priorityLevelConfiguration",
105 "rules",
106 ],
107 Visitor,
108 )
109 }
110}
111
112impl crate::serde::Serialize for FlowSchemaSpec {
113 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114 let mut state = serializer.serialize_struct(
115 "FlowSchemaSpec",
116 1 +
117 self.distinguisher_method.as_ref().map_or(0, |_| 1) +
118 self.matching_precedence.as_ref().map_or(0, |_| 1) +
119 self.rules.as_ref().map_or(0, |_| 1),
120 )?;
121 if let Some(value) = &self.distinguisher_method {
122 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "distinguisherMethod", value)?;
123 }
124 if let Some(value) = &self.matching_precedence {
125 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchingPrecedence", value)?;
126 }
127 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "priorityLevelConfiguration", &self.priority_level_configuration)?;
128 if let Some(value) = &self.rules {
129 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
130 }
131 crate::serde::ser::SerializeStruct::end(state)
132 }
133}
134
135#[cfg(feature = "schemars")]
136impl crate::schemars::JsonSchema for FlowSchemaSpec {
137 fn schema_name() -> String {
138 "io.k8s.api.flowcontrol.v1.FlowSchemaSpec".to_owned()
139 }
140
141 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
142 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
143 metadata: Some(Box::new(crate::schemars::schema::Metadata {
144 description: Some("FlowSchemaSpec describes how the FlowSchema's specification looks like.".to_owned()),
145 ..Default::default()
146 })),
147 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
148 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
149 properties: [
150 (
151 "distinguisherMethod".to_owned(),
152 {
153 let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::FlowDistinguisherMethod>().into_object();
154 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
155 description: Some("`distinguisherMethod` defines how to compute the flow distinguisher for requests that match this schema. `nil` specifies that the distinguisher is disabled and thus will always be the empty string.".to_owned()),
156 ..Default::default()
157 }));
158 crate::schemars::schema::Schema::Object(schema_obj)
159 },
160 ),
161 (
162 "matchingPrecedence".to_owned(),
163 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
164 metadata: Some(Box::new(crate::schemars::schema::Metadata {
165 description: Some("`matchingPrecedence` is used to choose among the FlowSchemas that match a given request. The chosen FlowSchema is among those with the numerically lowest (which we take to be logically highest) MatchingPrecedence. Each MatchingPrecedence value must be ranged in [1,10000]. Note that if the precedence is not specified, it will be set to 1000 as default.".to_owned()),
166 ..Default::default()
167 })),
168 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
169 format: Some("int32".to_owned()),
170 ..Default::default()
171 }),
172 ),
173 (
174 "priorityLevelConfiguration".to_owned(),
175 {
176 let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::PriorityLevelConfigurationReference>().into_object();
177 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
178 description: Some("`priorityLevelConfiguration` should reference a PriorityLevelConfiguration in the cluster. If the reference cannot be resolved, the FlowSchema will be ignored and marked as invalid in its status. Required.".to_owned()),
179 ..Default::default()
180 }));
181 crate::schemars::schema::Schema::Object(schema_obj)
182 },
183 ),
184 (
185 "rules".to_owned(),
186 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
187 metadata: Some(Box::new(crate::schemars::schema::Metadata {
188 description: Some("`rules` describes which requests will match this flow schema. This FlowSchema matches a request if and only if at least one member of rules matches the request. if it is an empty slice, there will be no requests matching the FlowSchema.".to_owned()),
189 ..Default::default()
190 })),
191 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
192 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
193 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::flowcontrol::v1::PolicyRulesWithSubjects>()))),
194 ..Default::default()
195 })),
196 ..Default::default()
197 }),
198 ),
199 ].into(),
200 required: [
201 "priorityLevelConfiguration".to_owned(),
202 ].into(),
203 ..Default::default()
204 })),
205 ..Default::default()
206 })
207 }
208}