k8s_openapi/v1_30/api/networking/v1alpha1/
parent_reference.rs
1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ParentReference {
6 pub group: Option<String>,
8
9 pub name: String,
11
12 pub namespace: Option<String>,
14
15 pub resource: String,
17}
18
19impl crate::DeepMerge for ParentReference {
20 fn merge_from(&mut self, other: Self) {
21 crate::DeepMerge::merge_from(&mut self.group, other.group);
22 crate::DeepMerge::merge_from(&mut self.name, other.name);
23 crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
24 crate::DeepMerge::merge_from(&mut self.resource, other.resource);
25 }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for ParentReference {
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_group,
33 Key_name,
34 Key_namespace,
35 Key_resource,
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<'de> crate::serde::de::Visitor<'de> for Visitor {
44 type Value = Field;
45
46 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::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 "group" => Field::Key_group,
53 "name" => Field::Key_name,
54 "namespace" => Field::Key_namespace,
55 "resource" => Field::Key_resource,
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 = ParentReference;
69
70 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 f.write_str("ParentReference")
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_group: Option<String> = None;
76 let mut value_name: Option<String> = None;
77 let mut value_namespace: Option<String> = None;
78 let mut value_resource: Option<String> = None;
79
80 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81 match key {
82 Field::Key_group => value_group = crate::serde::de::MapAccess::next_value(&mut map)?,
83 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_resource => value_resource = 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(ParentReference {
91 group: value_group,
92 name: value_name.unwrap_or_default(),
93 namespace: value_namespace,
94 resource: value_resource.unwrap_or_default(),
95 })
96 }
97 }
98
99 deserializer.deserialize_struct(
100 "ParentReference",
101 &[
102 "group",
103 "name",
104 "namespace",
105 "resource",
106 ],
107 Visitor,
108 )
109 }
110}
111
112impl crate::serde::Serialize for ParentReference {
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 "ParentReference",
116 2 +
117 self.group.as_ref().map_or(0, |_| 1) +
118 self.namespace.as_ref().map_or(0, |_| 1),
119 )?;
120 if let Some(value) = &self.group {
121 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "group", value)?;
122 }
123 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
124 if let Some(value) = &self.namespace {
125 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
126 }
127 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resource", &self.resource)?;
128 crate::serde::ser::SerializeStruct::end(state)
129 }
130}
131
132#[cfg(feature = "schemars")]
133impl crate::schemars::JsonSchema for ParentReference {
134 fn schema_name() -> String {
135 "io.k8s.api.networking.v1alpha1.ParentReference".to_owned()
136 }
137
138 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
139 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
140 metadata: Some(Box::new(crate::schemars::schema::Metadata {
141 description: Some("ParentReference describes a reference to a parent object.".to_owned()),
142 ..Default::default()
143 })),
144 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
145 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
146 properties: [
147 (
148 "group".to_owned(),
149 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
150 metadata: Some(Box::new(crate::schemars::schema::Metadata {
151 description: Some("Group is the group of the object being referenced.".to_owned()),
152 ..Default::default()
153 })),
154 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
155 ..Default::default()
156 }),
157 ),
158 (
159 "name".to_owned(),
160 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
161 metadata: Some(Box::new(crate::schemars::schema::Metadata {
162 description: Some("Name is the name of the object being referenced.".to_owned()),
163 ..Default::default()
164 })),
165 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
166 ..Default::default()
167 }),
168 ),
169 (
170 "namespace".to_owned(),
171 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
172 metadata: Some(Box::new(crate::schemars::schema::Metadata {
173 description: Some("Namespace is the namespace of the object being referenced.".to_owned()),
174 ..Default::default()
175 })),
176 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
177 ..Default::default()
178 }),
179 ),
180 (
181 "resource".to_owned(),
182 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
183 metadata: Some(Box::new(crate::schemars::schema::Metadata {
184 description: Some("Resource is the resource of the object being referenced.".to_owned()),
185 ..Default::default()
186 })),
187 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
188 ..Default::default()
189 }),
190 ),
191 ].into(),
192 required: [
193 "name".to_owned(),
194 "resource".to_owned(),
195 ].into(),
196 ..Default::default()
197 })),
198 ..Default::default()
199 })
200 }
201}