Skip to main content

k8s_openapi/v1_36/api/admissionregistration/v1/
service_reference.rs

1// Generated from definition io.k8s.api.admissionregistration.v1.ServiceReference
2
3/// ServiceReference holds a reference to Service.legacy.k8s.io
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ServiceReference {
6    /// name is the name of the service. Required
7    pub name: std::string::String,
8
9    /// namespace is the namespace of the service. Required
10    pub namespace: std::string::String,
11
12    /// path is an optional URL path which will be sent in any request to this service.
13    pub path: Option<std::string::String>,
14
15    /// port is the port on the service that hosts the webhook. Default to 443 for backward compatibility. `port` should be a valid port number (1-65535, inclusive).
16    pub port: Option<i32>,
17}
18
19impl crate::DeepMerge for ServiceReference {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.name, other.name);
22        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
23        crate::DeepMerge::merge_from(&mut self.path, other.path);
24        crate::DeepMerge::merge_from(&mut self.port, other.port);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for ServiceReference {
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_name,
33            Key_namespace,
34            Key_path,
35            Key_port,
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                            "name" => Field::Key_name,
53                            "namespace" => Field::Key_namespace,
54                            "path" => Field::Key_path,
55                            "port" => Field::Key_port,
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 = ServiceReference;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("ServiceReference")
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_name: Option<std::string::String> = None;
76                let mut value_namespace: Option<std::string::String> = None;
77                let mut value_path: Option<std::string::String> = None;
78                let mut value_port: Option<i32> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Key_path => value_path = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_port => value_port = 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(ServiceReference {
91                    name: value_name.unwrap_or_default(),
92                    namespace: value_namespace.unwrap_or_default(),
93                    path: value_path,
94                    port: value_port,
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "ServiceReference",
101            &[
102                "name",
103                "namespace",
104                "path",
105                "port",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for ServiceReference {
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            "ServiceReference",
116            2 +
117            self.path.as_ref().map_or(0, |_| 1) +
118            self.port.as_ref().map_or(0, |_| 1),
119        )?;
120        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
121        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", &self.namespace)?;
122        if let Some(value) = &self.path {
123            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "path", value)?;
124        }
125        if let Some(value) = &self.port {
126            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", value)?;
127        }
128        crate::serde::ser::SerializeStruct::end(state)
129    }
130}
131
132#[cfg(feature = "schemars")]
133impl crate::schemars::JsonSchema for ServiceReference {
134    fn schema_name() -> std::borrow::Cow<'static, str> {
135        "io.k8s.api.admissionregistration.v1.ServiceReference".into()
136    }
137
138    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
139        crate::schemars::json_schema!({
140            "description": "ServiceReference holds a reference to Service.legacy.k8s.io",
141            "type": "object",
142            "properties": {
143                "name": {
144                    "description": "name is the name of the service. Required",
145                    "type": "string",
146                },
147                "namespace": {
148                    "description": "namespace is the namespace of the service. Required",
149                    "type": "string",
150                },
151                "path": {
152                    "description": "path is an optional URL path which will be sent in any request to this service.",
153                    "type": "string",
154                },
155                "port": {
156                    "description": "port is the port on the service that hosts the webhook. Default to 443 for backward compatibility. `port` should be a valid port number (1-65535, inclusive).",
157                    "type": "integer",
158                    "format": "int32",
159                },
160            },
161            "required": [
162                "name",
163                "namespace",
164            ],
165        })
166    }
167}
168
169#[cfg(feature = "schemars08")]
170impl crate::schemars08::JsonSchema for ServiceReference {
171    fn schema_name() -> std::string::String {
172        "io.k8s.api.admissionregistration.v1.ServiceReference".into()
173    }
174
175    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
176        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
177            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
178                description: Some("ServiceReference holds a reference to Service.legacy.k8s.io".into()),
179                ..Default::default()
180            })),
181            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
182            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
183                properties: [
184                    (
185                        "name".into(),
186                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
187                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
188                                description: Some("name is the name of the service. Required".into()),
189                                ..Default::default()
190                            })),
191                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
192                            ..Default::default()
193                        }),
194                    ),
195                    (
196                        "namespace".into(),
197                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
198                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
199                                description: Some("namespace is the namespace of the service. Required".into()),
200                                ..Default::default()
201                            })),
202                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
203                            ..Default::default()
204                        }),
205                    ),
206                    (
207                        "path".into(),
208                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
209                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
210                                description: Some("path is an optional URL path which will be sent in any request to this service.".into()),
211                                ..Default::default()
212                            })),
213                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
214                            ..Default::default()
215                        }),
216                    ),
217                    (
218                        "port".into(),
219                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
220                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
221                                description: Some("port is the port on the service that hosts the webhook. Default to 443 for backward compatibility. `port` should be a valid port number (1-65535, inclusive).".into()),
222                                ..Default::default()
223                            })),
224                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
225                            format: Some("int32".into()),
226                            ..Default::default()
227                        }),
228                    ),
229                ].into(),
230                required: [
231                    "name".into(),
232                    "namespace".into(),
233                ].into(),
234                ..Default::default()
235            })),
236            ..Default::default()
237        })
238    }
239}