#
k8s_openapi/v1_35/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<std::vec::Vec<std::string::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<std::string::String>,
    11
    12    /// kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')
    13    pub kind: std::string::String,
    14
    15    /// name is the plural name of the resource.
    16    pub name: std::string::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<std::vec::Vec<std::string::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: std::string::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<std::string::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: std::vec::Vec<std::string::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<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}