k8s_openapi/v1_30/api/resource/v1alpha2/
resource_claim_parameters_reference.rs

1// Generated from definition io.k8s.api.resource.v1alpha2.ResourceClaimParametersReference
2
3/// ResourceClaimParametersReference contains enough information to let you locate the parameters for a ResourceClaim. The object must be in the same namespace as the ResourceClaim.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceClaimParametersReference {
6    /// APIGroup is the group for the resource being referenced. It is empty for the core API. This matches the group in the APIVersion that is used when creating the resources.
7    pub api_group: Option<std::string::String>,
8
9    /// Kind is the type of resource being referenced. This is the same value as in the parameter object's metadata, for example "ConfigMap".
10    pub kind: std::string::String,
11
12    /// Name is the name of resource being referenced.
13    pub name: std::string::String,
14}
15
16impl crate::DeepMerge for ResourceClaimParametersReference {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.api_group, other.api_group);
19        crate::DeepMerge::merge_from(&mut self.kind, other.kind);
20        crate::DeepMerge::merge_from(&mut self.name, other.name);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for ResourceClaimParametersReference {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_api_group,
29            Key_kind,
30            Key_name,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "apiGroup" => Field::Key_api_group,
48                            "kind" => Field::Key_kind,
49                            "name" => Field::Key_name,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = ResourceClaimParametersReference;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("ResourceClaimParametersReference")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_api_group: Option<std::string::String> = None;
70                let mut value_kind: Option<std::string::String> = None;
71                let mut value_name: Option<std::string::String> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_api_group => value_api_group = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(ResourceClaimParametersReference {
83                    api_group: value_api_group,
84                    kind: value_kind.unwrap_or_default(),
85                    name: value_name.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "ResourceClaimParametersReference",
92            &[
93                "apiGroup",
94                "kind",
95                "name",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for ResourceClaimParametersReference {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "ResourceClaimParametersReference",
106            2 +
107            self.api_group.as_ref().map_or(0, |_| 1),
108        )?;
109        if let Some(value) = &self.api_group {
110            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroup", value)?;
111        }
112        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
113        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
114        crate::serde::ser::SerializeStruct::end(state)
115    }
116}
117
118#[cfg(feature = "schemars")]
119impl crate::schemars::JsonSchema for ResourceClaimParametersReference {
120    fn schema_name() -> std::borrow::Cow<'static, str> {
121        "io.k8s.api.resource.v1alpha2.ResourceClaimParametersReference".into()
122    }
123
124    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
125        crate::schemars::json_schema!({
126            "description": "ResourceClaimParametersReference contains enough information to let you locate the parameters for a ResourceClaim. The object must be in the same namespace as the ResourceClaim.",
127            "type": "object",
128            "properties": {
129                "apiGroup": {
130                    "description": "APIGroup is the group for the resource being referenced. It is empty for the core API. This matches the group in the APIVersion that is used when creating the resources.",
131                    "type": "string",
132                },
133                "kind": {
134                    "description": "Kind is the type of resource being referenced. This is the same value as in the parameter object's metadata, for example \"ConfigMap\".",
135                    "type": "string",
136                },
137                "name": {
138                    "description": "Name is the name of resource being referenced.",
139                    "type": "string",
140                },
141            },
142            "required": [
143                "kind",
144                "name",
145            ],
146        })
147    }
148}