k8s_openapi/v1_35/kube_aggregator/pkg/apis/apiregistration/v1/
service_reference.rs

1// Generated from definition io.k8s.kube-aggregator.pkg.apis.apiregistration.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
7    pub name: Option<std::string::String>,
8
9    /// Namespace is the namespace of the service
10    pub namespace: Option<std::string::String>,
11
12    /// If specified, the port on the service that hosting webhook. Default to 443 for backward compatibility. `port` should be a valid port number (1-65535, inclusive).
13    pub port: Option<i32>,
14}
15
16impl crate::DeepMerge for ServiceReference {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.name, other.name);
19        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
20        crate::DeepMerge::merge_from(&mut self.port, other.port);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for ServiceReference {
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_name,
29            Key_namespace,
30            Key_port,
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                            "name" => Field::Key_name,
48                            "namespace" => Field::Key_namespace,
49                            "port" => Field::Key_port,
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 = ServiceReference;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("ServiceReference")
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_name: Option<std::string::String> = None;
70                let mut value_namespace: Option<std::string::String> = None;
71                let mut value_port: Option<i32> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_port => value_port = 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(ServiceReference {
83                    name: value_name,
84                    namespace: value_namespace,
85                    port: value_port,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "ServiceReference",
92            &[
93                "name",
94                "namespace",
95                "port",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for ServiceReference {
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            "ServiceReference",
106            self.name.as_ref().map_or(0, |_| 1) +
107            self.namespace.as_ref().map_or(0, |_| 1) +
108            self.port.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.name {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
112        }
113        if let Some(value) = &self.namespace {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
115        }
116        if let Some(value) = &self.port {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for ServiceReference {
125    fn schema_name() -> std::borrow::Cow<'static, str> {
126        "io.k8s.kube-aggregator.pkg.apis.apiregistration.v1.ServiceReference".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130        crate::schemars::json_schema!({
131            "description": "ServiceReference holds a reference to Service.legacy.k8s.io",
132            "type": "object",
133            "properties": {
134                "name": {
135                    "description": "Name is the name of the service",
136                    "type": "string",
137                },
138                "namespace": {
139                    "description": "Namespace is the namespace of the service",
140                    "type": "string",
141                },
142                "port": {
143                    "description": "If specified, the port on the service that hosting webhook. Default to 443 for backward compatibility. `port` should be a valid port number (1-65535, inclusive).",
144                    "type": "integer",
145                    "format": "int32",
146                },
147            },
148        })
149    }
150}