k8s_openapi/v1_30/apimachinery/pkg/apis/meta/v1/
api_resource.rs

1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.APIResource
2
3/// APIResource specifies the name of a resource and whether it is namespaced.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct APIResource {
6    /// categories is a list of the grouped resources this resource belongs to (e.g. 'all')
7    pub categories: Option<Vec<String>>,
8
9    /// 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".
10    pub group: Option<String>,
11
12    /// kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')
13    pub kind: String,
14
15    /// name is the plural name of the resource.
16    pub name: String,
17
18    /// namespaced indicates if a resource is namespaced or not.
19    pub namespaced: bool,
20
21    /// shortNames is a list of suggested short names of the resource.
22    pub short_names: Option<Vec<String>>,
23
24    /// 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.
25    pub singular_name: String,
26
27    /// 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.
28    pub storage_version_hash: Option<String>,
29
30    /// verbs is a list of supported kube verbs (this includes get, list, watch, create, update, patch, delete, deletecollection, and proxy)
31    pub verbs: Vec<String>,
32
33    /// 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)".
34    pub version: Option<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<'de> crate::serde::de::Visitor<'de> for Visitor {
74                    type Value = Field;
75
76                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::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 std::fmt::Formatter<'_>) -> std::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<Vec<String>> = None;
112                let mut value_group: Option<String> = None;
113                let mut value_kind: Option<String> = None;
114                let mut value_name: Option<String> = None;
115                let mut value_namespaced: Option<bool> = None;
116                let mut value_short_names: Option<Vec<String>> = None;
117                let mut value_singular_name: Option<String> = None;
118                let mut value_storage_version_hash: Option<String> = None;
119                let mut value_verbs: Option<Vec<String>> = None;
120                let mut value_version: Option<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() -> String {
210        "io.k8s.apimachinery.pkg.apis.meta.v1.APIResource".to_owned()
211    }
212
213    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
214        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
215            metadata: Some(Box::new(crate::schemars::schema::Metadata {
216                description: Some("APIResource specifies the name of a resource and whether it is namespaced.".to_owned()),
217                ..Default::default()
218            })),
219            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
220            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
221                properties: [
222                    (
223                        "categories".to_owned(),
224                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
225                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
226                                description: Some("categories is a list of the grouped resources this resource belongs to (e.g. 'all')".to_owned()),
227                                ..Default::default()
228                            })),
229                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
230                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
231                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
232                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
233                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
234                                        ..Default::default()
235                                    })
236                                ))),
237                                ..Default::default()
238                            })),
239                            ..Default::default()
240                        }),
241                    ),
242                    (
243                        "group".to_owned(),
244                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
245                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
246                                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\".".to_owned()),
247                                ..Default::default()
248                            })),
249                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
250                            ..Default::default()
251                        }),
252                    ),
253                    (
254                        "kind".to_owned(),
255                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
256                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
257                                description: Some("kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')".to_owned()),
258                                ..Default::default()
259                            })),
260                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
261                            ..Default::default()
262                        }),
263                    ),
264                    (
265                        "name".to_owned(),
266                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
267                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
268                                description: Some("name is the plural name of the resource.".to_owned()),
269                                ..Default::default()
270                            })),
271                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
272                            ..Default::default()
273                        }),
274                    ),
275                    (
276                        "namespaced".to_owned(),
277                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
278                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
279                                description: Some("namespaced indicates if a resource is namespaced or not.".to_owned()),
280                                ..Default::default()
281                            })),
282                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
283                            ..Default::default()
284                        }),
285                    ),
286                    (
287                        "shortNames".to_owned(),
288                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
289                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
290                                description: Some("shortNames is a list of suggested short names of the resource.".to_owned()),
291                                ..Default::default()
292                            })),
293                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
294                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
295                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
296                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
297                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
298                                        ..Default::default()
299                                    })
300                                ))),
301                                ..Default::default()
302                            })),
303                            ..Default::default()
304                        }),
305                    ),
306                    (
307                        "singularName".to_owned(),
308                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
309                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
310                                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.".to_owned()),
311                                ..Default::default()
312                            })),
313                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
314                            ..Default::default()
315                        }),
316                    ),
317                    (
318                        "storageVersionHash".to_owned(),
319                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
320                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
321                                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.".to_owned()),
322                                ..Default::default()
323                            })),
324                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
325                            ..Default::default()
326                        }),
327                    ),
328                    (
329                        "verbs".to_owned(),
330                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
331                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
332                                description: Some("verbs is a list of supported kube verbs (this includes get, list, watch, create, update, patch, delete, deletecollection, and proxy)".to_owned()),
333                                ..Default::default()
334                            })),
335                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
336                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
337                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
338                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
339                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
340                                        ..Default::default()
341                                    })
342                                ))),
343                                ..Default::default()
344                            })),
345                            ..Default::default()
346                        }),
347                    ),
348                    (
349                        "version".to_owned(),
350                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
351                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
352                                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)\".".to_owned()),
353                                ..Default::default()
354                            })),
355                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
356                            ..Default::default()
357                        }),
358                    ),
359                ].into(),
360                required: [
361                    "kind".to_owned(),
362                    "name".to_owned(),
363                    "namespaced".to_owned(),
364                    "singularName".to_owned(),
365                    "verbs".to_owned(),
366                ].into(),
367                ..Default::default()
368            })),
369            ..Default::default()
370        })
371    }
372}