#
k8s_openapi/v1_35/api/core/v1/
typed_object_reference.rs

    1// Generated from definition io.k8s.api.core.v1.TypedObjectReference
    2
    3/// TypedObjectReference contains enough information to let you locate the typed referenced object
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct TypedObjectReference {
    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 resource being referenced Note that when a namespace is specified, a gateway.networking.k8s.io/ReferenceGrant object is required in the referent namespace to allow that namespace's owner to accept the reference. See the ReferenceGrant documentation for details. (Alpha) This field requires the CrossNamespaceVolumeDataSource feature gate to be enabled.
    16    pub namespace: Option<std::string::String>,
    17}
    18
    19impl crate::DeepMerge for TypedObjectReference {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.api_group, other.api_group);
    22        crate::DeepMerge::merge_from(&mut self.kind, other.kind);
    23        crate::DeepMerge::merge_from(&mut self.name, other.name);
    24        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for TypedObjectReference {
    29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    30        #[allow(non_camel_case_types)]
    31        enum Field {
    32            Key_api_group,
    33            Key_kind,
    34            Key_name,
    35            Key_namespace,
    36            Other,
    37        }
    38
    39        impl<'de> crate::serde::Deserialize<'de> for Field {
    40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    41                struct Visitor;
    42
    43                impl crate::serde::de::Visitor<'_> for Visitor {
    44                    type Value = Field;
    45
    46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    47                        f.write_str("field identifier")
    48                    }
    49
    50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    51                        Ok(match v {
    52                            "apiGroup" => Field::Key_api_group,
    53                            "kind" => Field::Key_kind,
    54                            "name" => Field::Key_name,
    55                            "namespace" => Field::Key_namespace,
    56                            _ => Field::Other,
    57                        })
    58                    }
    59                }
    60
    61                deserializer.deserialize_identifier(Visitor)
    62            }
    63        }
    64
    65        struct Visitor;
    66
    67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    68            type Value = TypedObjectReference;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("TypedObjectReference")
    72            }
    73
    74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    75                let mut value_api_group: Option<std::string::String> = None;
    76                let mut value_kind: Option<std::string::String> = None;
    77                let mut value_name: Option<std::string::String> = None;
    78                let mut value_namespace: Option<std::string::String> = None;
    79
    80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    81                    match key {
    82                        Field::Key_api_group => value_api_group = crate::serde::de::MapAccess::next_value(&mut map)?,
    83                        Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
    86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    87                    }
    88                }
    89
    90                Ok(TypedObjectReference {
    91                    api_group: value_api_group,
    92                    kind: value_kind.unwrap_or_default(),
    93                    name: value_name.unwrap_or_default(),
    94                    namespace: value_namespace,
    95                })
    96            }
    97        }
    98
    99        deserializer.deserialize_struct(
    100            "TypedObjectReference",
    101            &[
    102                "apiGroup",
    103                "kind",
    104                "name",
    105                "namespace",
    106            ],
    107            Visitor,
    108        )
    109    }
    110}
    111
    112impl crate::serde::Serialize for TypedObjectReference {
    113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    114        let mut state = serializer.serialize_struct(
    115            "TypedObjectReference",
    116            2 +
    117            self.api_group.as_ref().map_or(0, |_| 1) +
    118            self.namespace.as_ref().map_or(0, |_| 1),
    119        )?;
    120        if let Some(value) = &self.api_group {
    121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroup", value)?;
    122        }
    123        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
    124        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    125        if let Some(value) = &self.namespace {
    126            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
    127        }
    128        crate::serde::ser::SerializeStruct::end(state)
    129    }
    130}
    131
    132#[cfg(feature = "schemars")]
    133impl crate::schemars::JsonSchema for TypedObjectReference {
    134    fn schema_name() -> std::borrow::Cow<'static, str> {
    135        "io.k8s.api.core.v1.TypedObjectReference".into()
    136    }
    137
    138    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    139        crate::schemars::json_schema!({
    140            "description": "TypedObjectReference contains enough information to let you locate the typed referenced object",
    141            "type": "object",
    142            "properties": {
    143                "apiGroup": {
    144                    "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.",
    145                    "type": "string",
    146                },
    147                "kind": {
    148                    "description": "Kind is the type of resource being referenced",
    149                    "type": "string",
    150                },
    151                "name": {
    152                    "description": "Name is the name of resource being referenced",
    153                    "type": "string",
    154                },
    155                "namespace": {
    156                    "description": "Namespace is the namespace of resource being referenced Note that when a namespace is specified, a gateway.networking.k8s.io/ReferenceGrant object is required in the referent namespace to allow that namespace's owner to accept the reference. See the ReferenceGrant documentation for details. (Alpha) This field requires the CrossNamespaceVolumeDataSource feature gate to be enabled.",
    157                    "type": "string",
    158                },
    159            },
    160            "required": [
    161                "kind",
    162                "name",
    163            ],
    164        })
    165    }
    166}