1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct APIResource {
6 pub categories: Option<std::vec::Vec<std::string::String>>,
8
9 pub group: Option<std::string::String>,
11
12 pub kind: std::string::String,
14
15 pub name: std::string::String,
17
18 pub namespaced: bool,
20
21 pub short_names: Option<std::vec::Vec<std::string::String>>,
23
24 pub singular_name: std::string::String,
26
27 pub storage_version_hash: Option<std::string::String>,
29
30 pub verbs: std::vec::Vec<std::string::String>,
32
33 pub version: Option<std::string::String>,
35}
36
37impl crate::DeepMerge for APIResource {
38 fn merge_from(&mut self, other: Self) {
39 crate::merge_strategies::list::atomic(&mut self.categories, other.categories);
40 crate::DeepMerge::merge_from(&mut self.group, other.group);
41 crate::DeepMerge::merge_from(&mut self.kind, other.kind);
42 crate::DeepMerge::merge_from(&mut self.name, other.name);
43 crate::DeepMerge::merge_from(&mut self.namespaced, other.namespaced);
44 crate::merge_strategies::list::atomic(&mut self.short_names, other.short_names);
45 crate::DeepMerge::merge_from(&mut self.singular_name, other.singular_name);
46 crate::DeepMerge::merge_from(&mut self.storage_version_hash, other.storage_version_hash);
47 crate::merge_strategies::list::atomic(&mut self.verbs, other.verbs);
48 crate::DeepMerge::merge_from(&mut self.version, other.version);
49 }
50}
51
52impl<'de> crate::serde::Deserialize<'de> for APIResource {
53 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
54 #[allow(non_camel_case_types)]
55 enum Field {
56 Key_categories,
57 Key_group,
58 Key_kind,
59 Key_name,
60 Key_namespaced,
61 Key_short_names,
62 Key_singular_name,
63 Key_storage_version_hash,
64 Key_verbs,
65 Key_version,
66 Other,
67 }
68
69 impl<'de> crate::serde::Deserialize<'de> for Field {
70 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
71 struct Visitor;
72
73 impl crate::serde::de::Visitor<'_> for Visitor {
74 type Value = Field;
75
76 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 f.write_str("field identifier")
78 }
79
80 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
81 Ok(match v {
82 "categories" => Field::Key_categories,
83 "group" => Field::Key_group,
84 "kind" => Field::Key_kind,
85 "name" => Field::Key_name,
86 "namespaced" => Field::Key_namespaced,
87 "shortNames" => Field::Key_short_names,
88 "singularName" => Field::Key_singular_name,
89 "storageVersionHash" => Field::Key_storage_version_hash,
90 "verbs" => Field::Key_verbs,
91 "version" => Field::Key_version,
92 _ => Field::Other,
93 })
94 }
95 }
96
97 deserializer.deserialize_identifier(Visitor)
98 }
99 }
100
101 struct Visitor;
102
103 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
104 type Value = APIResource;
105
106 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
107 f.write_str("APIResource")
108 }
109
110 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
111 let mut value_categories: Option<std::vec::Vec<std::string::String>> = None;
112 let mut value_group: Option<std::string::String> = None;
113 let mut value_kind: Option<std::string::String> = None;
114 let mut value_name: Option<std::string::String> = None;
115 let mut value_namespaced: Option<bool> = None;
116 let mut value_short_names: Option<std::vec::Vec<std::string::String>> = None;
117 let mut value_singular_name: Option<std::string::String> = None;
118 let mut value_storage_version_hash: Option<std::string::String> = None;
119 let mut value_verbs: Option<std::vec::Vec<std::string::String>> = None;
120 let mut value_version: Option<std::string::String> = None;
121
122 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
123 match key {
124 Field::Key_categories => value_categories = crate::serde::de::MapAccess::next_value(&mut map)?,
125 Field::Key_group => value_group = crate::serde::de::MapAccess::next_value(&mut map)?,
126 Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
127 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
128 Field::Key_namespaced => value_namespaced = crate::serde::de::MapAccess::next_value(&mut map)?,
129 Field::Key_short_names => value_short_names = crate::serde::de::MapAccess::next_value(&mut map)?,
130 Field::Key_singular_name => value_singular_name = crate::serde::de::MapAccess::next_value(&mut map)?,
131 Field::Key_storage_version_hash => value_storage_version_hash = crate::serde::de::MapAccess::next_value(&mut map)?,
132 Field::Key_verbs => value_verbs = crate::serde::de::MapAccess::next_value(&mut map)?,
133 Field::Key_version => value_version = crate::serde::de::MapAccess::next_value(&mut map)?,
134 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
135 }
136 }
137
138 Ok(APIResource {
139 categories: value_categories,
140 group: value_group,
141 kind: value_kind.unwrap_or_default(),
142 name: value_name.unwrap_or_default(),
143 namespaced: value_namespaced.unwrap_or_default(),
144 short_names: value_short_names,
145 singular_name: value_singular_name.unwrap_or_default(),
146 storage_version_hash: value_storage_version_hash,
147 verbs: value_verbs.unwrap_or_default(),
148 version: value_version,
149 })
150 }
151 }
152
153 deserializer.deserialize_struct(
154 "APIResource",
155 &[
156 "categories",
157 "group",
158 "kind",
159 "name",
160 "namespaced",
161 "shortNames",
162 "singularName",
163 "storageVersionHash",
164 "verbs",
165 "version",
166 ],
167 Visitor,
168 )
169 }
170}
171
172impl crate::serde::Serialize for APIResource {
173 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
174 let mut state = serializer.serialize_struct(
175 "APIResource",
176 5 +
177 self.categories.as_ref().map_or(0, |_| 1) +
178 self.group.as_ref().map_or(0, |_| 1) +
179 self.short_names.as_ref().map_or(0, |_| 1) +
180 self.storage_version_hash.as_ref().map_or(0, |_| 1) +
181 self.version.as_ref().map_or(0, |_| 1),
182 )?;
183 if let Some(value) = &self.categories {
184 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "categories", value)?;
185 }
186 if let Some(value) = &self.group {
187 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "group", value)?;
188 }
189 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
190 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
191 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaced", &self.namespaced)?;
192 if let Some(value) = &self.short_names {
193 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "shortNames", value)?;
194 }
195 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "singularName", &self.singular_name)?;
196 if let Some(value) = &self.storage_version_hash {
197 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "storageVersionHash", value)?;
198 }
199 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
200 if let Some(value) = &self.version {
201 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "version", value)?;
202 }
203 crate::serde::ser::SerializeStruct::end(state)
204 }
205}
206
207#[cfg(feature = "schemars")]
208impl crate::schemars::JsonSchema for APIResource {
209 fn schema_name() -> std::borrow::Cow<'static, str> {
210 "io.k8s.apimachinery.pkg.apis.meta.v1.APIResource".into()
211 }
212
213 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
214 crate::schemars::json_schema!({
215 "description": "APIResource specifies the name of a resource and whether it is namespaced.",
216 "type": "object",
217 "properties": {
218 "categories": {
219 "description": "categories is a list of the grouped resources this resource belongs to (e.g. 'all')",
220 "type": "array",
221 "items": {
222 "type": "string",
223 },
224 },
225 "group": {
226 "description": "group is the preferred group of the resource. Empty implies the group of the containing resource list. For subresources, this may have a different value, for example: Scale\".",
227 "type": "string",
228 },
229 "kind": {
230 "description": "kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')",
231 "type": "string",
232 },
233 "name": {
234 "description": "name is the plural name of the resource.",
235 "type": "string",
236 },
237 "namespaced": {
238 "description": "namespaced indicates if a resource is namespaced or not.",
239 "type": "boolean",
240 },
241 "shortNames": {
242 "description": "shortNames is a list of suggested short names of the resource.",
243 "type": "array",
244 "items": {
245 "type": "string",
246 },
247 },
248 "singularName": {
249 "description": "singularName is the singular name of the resource. This allows clients to handle plural and singular opaquely. The singularName is more correct for reporting status on a single item and both singular and plural are allowed from the kubectl CLI interface.",
250 "type": "string",
251 },
252 "storageVersionHash": {
253 "description": "The hash value of the storage version, the version this resource is converted to when written to the data store. Value must be treated as opaque by clients. Only equality comparison on the value is valid. This is an alpha feature and may change or be removed in the future. The field is populated by the apiserver only if the StorageVersionHash feature gate is enabled. This field will remain optional even if it graduates.",
254 "type": "string",
255 },
256 "verbs": {
257 "description": "verbs is a list of supported kube verbs (this includes get, list, watch, create, update, patch, delete, deletecollection, and proxy)",
258 "type": "array",
259 "items": {
260 "type": "string",
261 },
262 },
263 "version": {
264 "description": "version is the preferred version of the resource. Empty implies the version of the containing resource list For subresources, this may have a different value, for example: v1 (while inside a v1beta1 version of the core resource's group)\".",
265 "type": "string",
266 },
267 },
268 "required": [
269 "kind",
270 "name",
271 "namespaced",
272 "singularName",
273 "verbs",
274 ],
275 })
276 }
277}
278
279#[cfg(feature = "schemars08")]
280impl crate::schemars08::JsonSchema for APIResource {
281 fn schema_name() -> std::string::String {
282 "io.k8s.apimachinery.pkg.apis.meta.v1.APIResource".into()
283 }
284
285 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
286 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
287 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
288 description: Some("APIResource specifies the name of a resource and whether it is namespaced.".into()),
289 ..Default::default()
290 })),
291 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
292 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
293 properties: [
294 (
295 "categories".into(),
296 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
297 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
298 description: Some("categories is a list of the grouped resources this resource belongs to (e.g. 'all')".into()),
299 ..Default::default()
300 })),
301 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
302 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
303 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
304 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
305 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
306 ..Default::default()
307 })
308 ))),
309 ..Default::default()
310 })),
311 ..Default::default()
312 }),
313 ),
314 (
315 "group".into(),
316 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
317 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
318 description: Some("group is the preferred group of the resource. Empty implies the group of the containing resource list. For subresources, this may have a different value, for example: Scale\".".into()),
319 ..Default::default()
320 })),
321 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
322 ..Default::default()
323 }),
324 ),
325 (
326 "kind".into(),
327 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
328 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
329 description: Some("kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')".into()),
330 ..Default::default()
331 })),
332 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
333 ..Default::default()
334 }),
335 ),
336 (
337 "name".into(),
338 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
339 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
340 description: Some("name is the plural name of the resource.".into()),
341 ..Default::default()
342 })),
343 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
344 ..Default::default()
345 }),
346 ),
347 (
348 "namespaced".into(),
349 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
350 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
351 description: Some("namespaced indicates if a resource is namespaced or not.".into()),
352 ..Default::default()
353 })),
354 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
355 ..Default::default()
356 }),
357 ),
358 (
359 "shortNames".into(),
360 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
361 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
362 description: Some("shortNames is a list of suggested short names of the resource.".into()),
363 ..Default::default()
364 })),
365 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
366 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
367 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
368 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
369 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
370 ..Default::default()
371 })
372 ))),
373 ..Default::default()
374 })),
375 ..Default::default()
376 }),
377 ),
378 (
379 "singularName".into(),
380 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
381 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
382 description: Some("singularName is the singular name of the resource. This allows clients to handle plural and singular opaquely. The singularName is more correct for reporting status on a single item and both singular and plural are allowed from the kubectl CLI interface.".into()),
383 ..Default::default()
384 })),
385 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
386 ..Default::default()
387 }),
388 ),
389 (
390 "storageVersionHash".into(),
391 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
392 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
393 description: Some("The hash value of the storage version, the version this resource is converted to when written to the data store. Value must be treated as opaque by clients. Only equality comparison on the value is valid. This is an alpha feature and may change or be removed in the future. The field is populated by the apiserver only if the StorageVersionHash feature gate is enabled. This field will remain optional even if it graduates.".into()),
394 ..Default::default()
395 })),
396 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
397 ..Default::default()
398 }),
399 ),
400 (
401 "verbs".into(),
402 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
403 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
404 description: Some("verbs is a list of supported kube verbs (this includes get, list, watch, create, update, patch, delete, deletecollection, and proxy)".into()),
405 ..Default::default()
406 })),
407 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
408 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
409 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
410 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
411 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
412 ..Default::default()
413 })
414 ))),
415 ..Default::default()
416 })),
417 ..Default::default()
418 }),
419 ),
420 (
421 "version".into(),
422 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
423 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
424 description: Some("version is the preferred version of the resource. Empty implies the version of the containing resource list For subresources, this may have a different value, for example: v1 (while inside a v1beta1 version of the core resource's group)\".".into()),
425 ..Default::default()
426 })),
427 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
428 ..Default::default()
429 }),
430 ),
431 ].into(),
432 required: [
433 "kind".into(),
434 "name".into(),
435 "namespaced".into(),
436 "singularName".into(),
437 "verbs".into(),
438 ].into(),
439 ..Default::default()
440 })),
441 ..Default::default()
442 })
443 }
444}