k8s_openapi/v1_34/api/admissionregistration/v1/
rule_with_operations.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct RuleWithOperations {
6 pub api_groups: Option<std::vec::Vec<std::string::String>>,
8
9 pub api_versions: Option<std::vec::Vec<std::string::String>>,
11
12 pub operations: Option<std::vec::Vec<std::string::String>>,
14
15 pub resources: Option<std::vec::Vec<std::string::String>>,
23
24 pub scope: Option<std::string::String>,
26}
27
28impl crate::DeepMerge for RuleWithOperations {
29 fn merge_from(&mut self, other: Self) {
30 crate::merge_strategies::list::atomic(&mut self.api_groups, other.api_groups);
31 crate::merge_strategies::list::atomic(&mut self.api_versions, other.api_versions);
32 crate::merge_strategies::list::atomic(&mut self.operations, other.operations);
33 crate::merge_strategies::list::atomic(&mut self.resources, other.resources);
34 crate::DeepMerge::merge_from(&mut self.scope, other.scope);
35 }
36}
37
38impl<'de> crate::serde::Deserialize<'de> for RuleWithOperations {
39 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40 #[allow(non_camel_case_types)]
41 enum Field {
42 Key_api_groups,
43 Key_api_versions,
44 Key_operations,
45 Key_resources,
46 Key_scope,
47 Other,
48 }
49
50 impl<'de> crate::serde::Deserialize<'de> for Field {
51 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
52 struct Visitor;
53
54 impl crate::serde::de::Visitor<'_> for Visitor {
55 type Value = Field;
56
57 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58 f.write_str("field identifier")
59 }
60
61 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
62 Ok(match v {
63 "apiGroups" => Field::Key_api_groups,
64 "apiVersions" => Field::Key_api_versions,
65 "operations" => Field::Key_operations,
66 "resources" => Field::Key_resources,
67 "scope" => Field::Key_scope,
68 _ => Field::Other,
69 })
70 }
71 }
72
73 deserializer.deserialize_identifier(Visitor)
74 }
75 }
76
77 struct Visitor;
78
79 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80 type Value = RuleWithOperations;
81
82 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83 f.write_str("RuleWithOperations")
84 }
85
86 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87 let mut value_api_groups: Option<std::vec::Vec<std::string::String>> = None;
88 let mut value_api_versions: Option<std::vec::Vec<std::string::String>> = None;
89 let mut value_operations: Option<std::vec::Vec<std::string::String>> = None;
90 let mut value_resources: Option<std::vec::Vec<std::string::String>> = None;
91 let mut value_scope: Option<std::string::String> = None;
92
93 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
94 match key {
95 Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
96 Field::Key_api_versions => value_api_versions = crate::serde::de::MapAccess::next_value(&mut map)?,
97 Field::Key_operations => value_operations = crate::serde::de::MapAccess::next_value(&mut map)?,
98 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
99 Field::Key_scope => value_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
100 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
101 }
102 }
103
104 Ok(RuleWithOperations {
105 api_groups: value_api_groups,
106 api_versions: value_api_versions,
107 operations: value_operations,
108 resources: value_resources,
109 scope: value_scope,
110 })
111 }
112 }
113
114 deserializer.deserialize_struct(
115 "RuleWithOperations",
116 &[
117 "apiGroups",
118 "apiVersions",
119 "operations",
120 "resources",
121 "scope",
122 ],
123 Visitor,
124 )
125 }
126}
127
128impl crate::serde::Serialize for RuleWithOperations {
129 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
130 let mut state = serializer.serialize_struct(
131 "RuleWithOperations",
132 self.api_groups.as_ref().map_or(0, |_| 1) +
133 self.api_versions.as_ref().map_or(0, |_| 1) +
134 self.operations.as_ref().map_or(0, |_| 1) +
135 self.resources.as_ref().map_or(0, |_| 1) +
136 self.scope.as_ref().map_or(0, |_| 1),
137 )?;
138 if let Some(value) = &self.api_groups {
139 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", value)?;
140 }
141 if let Some(value) = &self.api_versions {
142 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersions", value)?;
143 }
144 if let Some(value) = &self.operations {
145 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "operations", value)?;
146 }
147 if let Some(value) = &self.resources {
148 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
149 }
150 if let Some(value) = &self.scope {
151 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scope", value)?;
152 }
153 crate::serde::ser::SerializeStruct::end(state)
154 }
155}
156
157#[cfg(feature = "schemars")]
158impl crate::schemars::JsonSchema for RuleWithOperations {
159 fn schema_name() -> std::borrow::Cow<'static, str> {
160 "io.k8s.api.admissionregistration.v1.RuleWithOperations".into()
161 }
162
163 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
164 crate::schemars::json_schema!({
165 "description": "RuleWithOperations is a tuple of Operations and Resources. It is recommended to make sure that all the tuple expansions are valid.",
166 "type": "object",
167 "properties": {
168 "apiGroups": {
169 "description": "APIGroups is the API groups the resources belong to. '*' is all groups. If '*' is present, the length of the slice must be one. Required.",
170 "type": "array",
171 "items": {
172 "type": "string",
173 },
174 },
175 "apiVersions": {
176 "description": "APIVersions is the API versions the resources belong to. '*' is all versions. If '*' is present, the length of the slice must be one. Required.",
177 "type": "array",
178 "items": {
179 "type": "string",
180 },
181 },
182 "operations": {
183 "description": "Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.",
184 "type": "array",
185 "items": {
186 "type": "string",
187 },
188 },
189 "resources": {
190 "description": "Resources is a list of resources this rule applies to.\n\nFor example: 'pods' means pods. 'pods/log' means the log subresource of pods. '*' means all resources, but not subresources. 'pods/*' means all subresources of pods. '*/scale' means all scale subresources. '*/*' means all resources and their subresources.\n\nIf wildcard is present, the validation rule will ensure resources do not overlap with each other.\n\nDepending on the enclosing object, subresources might not be allowed. Required.",
191 "type": "array",
192 "items": {
193 "type": "string",
194 },
195 },
196 "scope": {
197 "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".",
198 "type": "string",
199 },
200 },
201 })
202 }
203}