#
k8s_openapi/v1_35/api/networking/v1/
ingress_class_parameters_reference.rs

    1// Generated from definition io.k8s.api.networking.v1.IngressClassParametersReference
    2
    3/// IngressClassParametersReference identifies an API object. This can be used to specify a cluster or namespace-scoped resource.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct IngressClassParametersReference {
    6    /// apiGroup is the group for the resource being referenced. If APIGroup is not specified, the specified Kind must be in the core API group. For any other third-party types, APIGroup is required.
    7    pub api_group: Option<std::string::String>,
    8
    9    /// kind is the type of resource being referenced.
    10    pub kind: std::string::String,
    11
    12    /// name is the name of resource being referenced.
    13    pub name: std::string::String,
    14
    15    /// namespace is the namespace of the resource being referenced. This field is required when scope is set to "Namespace" and must be unset when scope is set to "Cluster".
    16    pub namespace: Option<std::string::String>,
    17
    18    /// scope represents if this refers to a cluster or namespace scoped resource. This may be set to "Cluster" (default) or "Namespace".
    19    pub scope: Option<std::string::String>,
    20}
    21
    22impl crate::DeepMerge for IngressClassParametersReference {
    23    fn merge_from(&mut self, other: Self) {
    24        crate::DeepMerge::merge_from(&mut self.api_group, other.api_group);
    25        crate::DeepMerge::merge_from(&mut self.kind, other.kind);
    26        crate::DeepMerge::merge_from(&mut self.name, other.name);
    27        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
    28        crate::DeepMerge::merge_from(&mut self.scope, other.scope);
    29    }
    30}
    31
    32impl<'de> crate::serde::Deserialize<'de> for IngressClassParametersReference {
    33    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    34        #[allow(non_camel_case_types)]
    35        enum Field {
    36            Key_api_group,
    37            Key_kind,
    38            Key_name,
    39            Key_namespace,
    40            Key_scope,
    41            Other,
    42        }
    43
    44        impl<'de> crate::serde::Deserialize<'de> for Field {
    45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    46                struct Visitor;
    47
    48                impl crate::serde::de::Visitor<'_> for Visitor {
    49                    type Value = Field;
    50
    51                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    52                        f.write_str("field identifier")
    53                    }
    54
    55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    56                        Ok(match v {
    57                            "apiGroup" => Field::Key_api_group,
    58                            "kind" => Field::Key_kind,
    59                            "name" => Field::Key_name,
    60                            "namespace" => Field::Key_namespace,
    61                            "scope" => Field::Key_scope,
    62                            _ => Field::Other,
    63                        })
    64                    }
    65                }
    66
    67                deserializer.deserialize_identifier(Visitor)
    68            }
    69        }
    70
    71        struct Visitor;
    72
    73        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    74            type Value = IngressClassParametersReference;
    75
    76            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    77                f.write_str("IngressClassParametersReference")
    78            }
    79
    80            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    81                let mut value_api_group: Option<std::string::String> = None;
    82                let mut value_kind: Option<std::string::String> = None;
    83                let mut value_name: Option<std::string::String> = None;
    84                let mut value_namespace: Option<std::string::String> = None;
    85                let mut value_scope: Option<std::string::String> = None;
    86
    87                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    88                    match key {
    89                        Field::Key_api_group => value_api_group = crate::serde::de::MapAccess::next_value(&mut map)?,
    90                        Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
    91                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    92                        Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
    93                        Field::Key_scope => value_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
    94                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    95                    }
    96                }
    97
    98                Ok(IngressClassParametersReference {
    99                    api_group: value_api_group,
    100                    kind: value_kind.unwrap_or_default(),
    101                    name: value_name.unwrap_or_default(),
    102                    namespace: value_namespace,
    103                    scope: value_scope,
    104                })
    105            }
    106        }
    107
    108        deserializer.deserialize_struct(
    109            "IngressClassParametersReference",
    110            &[
    111                "apiGroup",
    112                "kind",
    113                "name",
    114                "namespace",
    115                "scope",
    116            ],
    117            Visitor,
    118        )
    119    }
    120}
    121
    122impl crate::serde::Serialize for IngressClassParametersReference {
    123    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    124        let mut state = serializer.serialize_struct(
    125            "IngressClassParametersReference",
    126            2 +
    127            self.api_group.as_ref().map_or(0, |_| 1) +
    128            self.namespace.as_ref().map_or(0, |_| 1) +
    129            self.scope.as_ref().map_or(0, |_| 1),
    130        )?;
    131        if let Some(value) = &self.api_group {
    132            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroup", value)?;
    133        }
    134        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
    135        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    136        if let Some(value) = &self.namespace {
    137            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
    138        }
    139        if let Some(value) = &self.scope {
    140            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scope", value)?;
    141        }
    142        crate::serde::ser::SerializeStruct::end(state)
    143    }
    144}
    145
    146#[cfg(feature = "schemars")]
    147impl crate::schemars::JsonSchema for IngressClassParametersReference {
    148    fn schema_name() -> std::borrow::Cow<'static, str> {
    149        "io.k8s.api.networking.v1.IngressClassParametersReference".into()
    150    }
    151
    152    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    153        crate::schemars::json_schema!({
    154            "description": "IngressClassParametersReference identifies an API object. This can be used to specify a cluster or namespace-scoped resource.",
    155            "type": "object",
    156            "properties": {
    157                "apiGroup": {
    158                    "description": "apiGroup is the group for the resource being referenced. If APIGroup is not specified, the specified Kind must be in the core API group. For any other third-party types, APIGroup is required.",
    159                    "type": "string",
    160                },
    161                "kind": {
    162                    "description": "kind is the type of resource being referenced.",
    163                    "type": "string",
    164                },
    165                "name": {
    166                    "description": "name is the name of resource being referenced.",
    167                    "type": "string",
    168                },
    169                "namespace": {
    170                    "description": "namespace is the namespace of the resource being referenced. This field is required when scope is set to \"Namespace\" and must be unset when scope is set to \"Cluster\".",
    171                    "type": "string",
    172                },
    173                "scope": {
    174                    "description": "scope represents if this refers to a cluster or namespace scoped resource. This may be set to \"Cluster\" (default) or \"Namespace\".",
    175                    "type": "string",
    176                },
    177            },
    178            "required": [
    179                "kind",
    180                "name",
    181            ],
    182        })
    183    }
    184}