#
k8s_openapi/v1_35/apiextensions_apiserver/pkg/apis/apiextensions/v1/
custom_resource_definition_names.rs

    1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionNames
    2
    3/// CustomResourceDefinitionNames indicates the names to serve this CustomResourceDefinition
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct CustomResourceDefinitionNames {
    6    /// categories is a list of grouped resources this custom resource belongs to (e.g. 'all'). This is published in API discovery documents, and used by clients to support invocations like `kubectl get all`.
    7    pub categories: Option<std::vec::Vec<std::string::String>>,
    8
    9    /// kind is the serialized kind of the resource. It is normally CamelCase and singular. Custom resource instances will use this value as the `kind` attribute in API calls.
    10    pub kind: std::string::String,
    11
    12    /// listKind is the serialized kind of the list for this resource. Defaults to "`kind`List".
    13    pub list_kind: Option<std::string::String>,
    14
    15    /// plural is the plural name of the resource to serve. The custom resources are served under `/apis/\<group\>/\<version\>/.../\<plural\>`. Must match the name of the CustomResourceDefinition (in the form `\<names.plural\>.\<group\>`). Must be all lowercase.
    16    pub plural: std::string::String,
    17
    18    /// shortNames are short names for the resource, exposed in API discovery documents, and used by clients to support invocations like `kubectl get \<shortname\>`. It must be all lowercase.
    19    pub short_names: Option<std::vec::Vec<std::string::String>>,
    20
    21    /// singular is the singular name of the resource. It must be all lowercase. Defaults to lowercased `kind`.
    22    pub singular: Option<std::string::String>,
    23}
    24
    25impl crate::DeepMerge for CustomResourceDefinitionNames {
    26    fn merge_from(&mut self, other: Self) {
    27        crate::merge_strategies::list::atomic(&mut self.categories, other.categories);
    28        crate::DeepMerge::merge_from(&mut self.kind, other.kind);
    29        crate::DeepMerge::merge_from(&mut self.list_kind, other.list_kind);
    30        crate::DeepMerge::merge_from(&mut self.plural, other.plural);
    31        crate::merge_strategies::list::atomic(&mut self.short_names, other.short_names);
    32        crate::DeepMerge::merge_from(&mut self.singular, other.singular);
    33    }
    34}
    35
    36impl<'de> crate::serde::Deserialize<'de> for CustomResourceDefinitionNames {
    37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    38        #[allow(non_camel_case_types)]
    39        enum Field {
    40            Key_categories,
    41            Key_kind,
    42            Key_list_kind,
    43            Key_plural,
    44            Key_short_names,
    45            Key_singular,
    46            Other,
    47        }
    48
    49        impl<'de> crate::serde::Deserialize<'de> for Field {
    50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    51                struct Visitor;
    52
    53                impl crate::serde::de::Visitor<'_> for Visitor {
    54                    type Value = Field;
    55
    56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    57                        f.write_str("field identifier")
    58                    }
    59
    60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    61                        Ok(match v {
    62                            "categories" => Field::Key_categories,
    63                            "kind" => Field::Key_kind,
    64                            "listKind" => Field::Key_list_kind,
    65                            "plural" => Field::Key_plural,
    66                            "shortNames" => Field::Key_short_names,
    67                            "singular" => Field::Key_singular,
    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 = CustomResourceDefinitionNames;
    81
    82            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    83                f.write_str("CustomResourceDefinitionNames")
    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_categories: Option<std::vec::Vec<std::string::String>> = None;
    88                let mut value_kind: Option<std::string::String> = None;
    89                let mut value_list_kind: Option<std::string::String> = None;
    90                let mut value_plural: Option<std::string::String> = None;
    91                let mut value_short_names: Option<std::vec::Vec<std::string::String>> = None;
    92                let mut value_singular: Option<std::string::String> = None;
    93
    94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    95                    match key {
    96                        Field::Key_categories => value_categories = crate::serde::de::MapAccess::next_value(&mut map)?,
    97                        Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
    98                        Field::Key_list_kind => value_list_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
    99                        Field::Key_plural => value_plural = crate::serde::de::MapAccess::next_value(&mut map)?,
    100                        Field::Key_short_names => value_short_names = crate::serde::de::MapAccess::next_value(&mut map)?,
    101                        Field::Key_singular => value_singular = crate::serde::de::MapAccess::next_value(&mut map)?,
    102                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    103                    }
    104                }
    105
    106                Ok(CustomResourceDefinitionNames {
    107                    categories: value_categories,
    108                    kind: value_kind.unwrap_or_default(),
    109                    list_kind: value_list_kind,
    110                    plural: value_plural.unwrap_or_default(),
    111                    short_names: value_short_names,
    112                    singular: value_singular,
    113                })
    114            }
    115        }
    116
    117        deserializer.deserialize_struct(
    118            "CustomResourceDefinitionNames",
    119            &[
    120                "categories",
    121                "kind",
    122                "listKind",
    123                "plural",
    124                "shortNames",
    125                "singular",
    126            ],
    127            Visitor,
    128        )
    129    }
    130}
    131
    132impl crate::serde::Serialize for CustomResourceDefinitionNames {
    133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    134        let mut state = serializer.serialize_struct(
    135            "CustomResourceDefinitionNames",
    136            2 +
    137            self.categories.as_ref().map_or(0, |_| 1) +
    138            self.list_kind.as_ref().map_or(0, |_| 1) +
    139            self.short_names.as_ref().map_or(0, |_| 1) +
    140            self.singular.as_ref().map_or(0, |_| 1),
    141        )?;
    142        if let Some(value) = &self.categories {
    143            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "categories", value)?;
    144        }
    145        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
    146        if let Some(value) = &self.list_kind {
    147            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "listKind", value)?;
    148        }
    149        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "plural", &self.plural)?;
    150        if let Some(value) = &self.short_names {
    151            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "shortNames", value)?;
    152        }
    153        if let Some(value) = &self.singular {
    154            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "singular", value)?;
    155        }
    156        crate::serde::ser::SerializeStruct::end(state)
    157    }
    158}
    159
    160#[cfg(feature = "schemars")]
    161impl crate::schemars::JsonSchema for CustomResourceDefinitionNames {
    162    fn schema_name() -> std::borrow::Cow<'static, str> {
    163        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionNames".into()
    164    }
    165
    166    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    167        crate::schemars::json_schema!({
    168            "description": "CustomResourceDefinitionNames indicates the names to serve this CustomResourceDefinition",
    169            "type": "object",
    170            "properties": {
    171                "categories": {
    172                    "description": "categories is a list of grouped resources this custom resource belongs to (e.g. 'all'). This is published in API discovery documents, and used by clients to support invocations like `kubectl get all`.",
    173                    "type": "array",
    174                    "items": {
    175                        "type": "string",
    176                    },
    177                },
    178                "kind": {
    179                    "description": "kind is the serialized kind of the resource. It is normally CamelCase and singular. Custom resource instances will use this value as the `kind` attribute in API calls.",
    180                    "type": "string",
    181                },
    182                "listKind": {
    183                    "description": "listKind is the serialized kind of the list for this resource. Defaults to \"`kind`List\".",
    184                    "type": "string",
    185                },
    186                "plural": {
    187                    "description": "plural is the plural name of the resource to serve. The custom resources are served under `/apis/<group>/<version>/.../<plural>`. Must match the name of the CustomResourceDefinition (in the form `<names.plural>.<group>`). Must be all lowercase.",
    188                    "type": "string",
    189                },
    190                "shortNames": {
    191                    "description": "shortNames are short names for the resource, exposed in API discovery documents, and used by clients to support invocations like `kubectl get <shortname>`. It must be all lowercase.",
    192                    "type": "array",
    193                    "items": {
    194                        "type": "string",
    195                    },
    196                },
    197                "singular": {
    198                    "description": "singular is the singular name of the resource. It must be all lowercase. Defaults to lowercased `kind`.",
    199                    "type": "string",
    200                },
    201            },
    202            "required": [
    203                "kind",
    204                "plural",
    205            ],
    206        })
    207    }
    208}