k8s_openapi/v1_32/api/discovery/v1/
endpoint_port.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct EndpointPort {
6 pub app_protocol: Option<String>,
17
18 pub name: Option<String>,
20
21 pub port: Option<i32>,
23
24 pub protocol: Option<String>,
26}
27
28impl crate::DeepMerge for EndpointPort {
29 fn merge_from(&mut self, other: Self) {
30 crate::DeepMerge::merge_from(&mut self.app_protocol, other.app_protocol);
31 crate::DeepMerge::merge_from(&mut self.name, other.name);
32 crate::DeepMerge::merge_from(&mut self.port, other.port);
33 crate::DeepMerge::merge_from(&mut self.protocol, other.protocol);
34 }
35}
36
37impl<'de> crate::serde::Deserialize<'de> for EndpointPort {
38 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39 #[allow(non_camel_case_types)]
40 enum Field {
41 Key_app_protocol,
42 Key_name,
43 Key_port,
44 Key_protocol,
45 Other,
46 }
47
48 impl<'de> crate::serde::Deserialize<'de> for Field {
49 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
50 struct Visitor;
51
52 impl crate::serde::de::Visitor<'_> for Visitor {
53 type Value = Field;
54
55 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 f.write_str("field identifier")
57 }
58
59 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
60 Ok(match v {
61 "appProtocol" => Field::Key_app_protocol,
62 "name" => Field::Key_name,
63 "port" => Field::Key_port,
64 "protocol" => Field::Key_protocol,
65 _ => Field::Other,
66 })
67 }
68 }
69
70 deserializer.deserialize_identifier(Visitor)
71 }
72 }
73
74 struct Visitor;
75
76 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
77 type Value = EndpointPort;
78
79 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 f.write_str("EndpointPort")
81 }
82
83 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
84 let mut value_app_protocol: Option<String> = None;
85 let mut value_name: Option<String> = None;
86 let mut value_port: Option<i32> = None;
87 let mut value_protocol: Option<String> = None;
88
89 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
90 match key {
91 Field::Key_app_protocol => value_app_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
92 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_port => value_port = crate::serde::de::MapAccess::next_value(&mut map)?,
94 Field::Key_protocol => value_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
95 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
96 }
97 }
98
99 Ok(EndpointPort {
100 app_protocol: value_app_protocol,
101 name: value_name,
102 port: value_port,
103 protocol: value_protocol,
104 })
105 }
106 }
107
108 deserializer.deserialize_struct(
109 "EndpointPort",
110 &[
111 "appProtocol",
112 "name",
113 "port",
114 "protocol",
115 ],
116 Visitor,
117 )
118 }
119}
120
121impl crate::serde::Serialize for EndpointPort {
122 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
123 let mut state = serializer.serialize_struct(
124 "EndpointPort",
125 self.app_protocol.as_ref().map_or(0, |_| 1) +
126 self.name.as_ref().map_or(0, |_| 1) +
127 self.port.as_ref().map_or(0, |_| 1) +
128 self.protocol.as_ref().map_or(0, |_| 1),
129 )?;
130 if let Some(value) = &self.app_protocol {
131 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "appProtocol", value)?;
132 }
133 if let Some(value) = &self.name {
134 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
135 }
136 if let Some(value) = &self.port {
137 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", value)?;
138 }
139 if let Some(value) = &self.protocol {
140 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "protocol", value)?;
141 }
142 crate::serde::ser::SerializeStruct::end(state)
143 }
144}
145
146#[cfg(feature = "schemars")]
147impl crate::schemars::JsonSchema for EndpointPort {
148 fn schema_name() -> String {
149 "io.k8s.api.discovery.v1.EndpointPort".to_owned()
150 }
151
152 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
153 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
154 metadata: Some(Box::new(crate::schemars::schema::Metadata {
155 description: Some("EndpointPort represents a Port used by an EndpointSlice".to_owned()),
156 ..Default::default()
157 })),
158 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
159 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
160 properties: [
161 (
162 "appProtocol".to_owned(),
163 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
164 metadata: Some(Box::new(crate::schemars::schema::Metadata {
165 description: Some("The application protocol for this port. This is used as a hint for implementations to offer richer behavior for protocols that they understand. This field follows standard Kubernetes label syntax. Valid values are either:\n\n* Un-prefixed protocol names - reserved for IANA standard service names (as per RFC-6335 and https://www.iana.org/assignments/service-names).\n\n* Kubernetes-defined prefixed names:\n * 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior-\n * 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455\n * 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455\n\n* Other protocols should use implementation-defined prefixed names such as mycompany.com/my-custom-protocol.".to_owned()),
166 ..Default::default()
167 })),
168 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
169 ..Default::default()
170 }),
171 ),
172 (
173 "name".to_owned(),
174 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
175 metadata: Some(Box::new(crate::schemars::schema::Metadata {
176 description: Some("name represents the name of this port. All ports in an EndpointSlice must have a unique name. If the EndpointSlice is derived from a Kubernetes service, this corresponds to the Service.ports[].name. Name must either be an empty string or pass DNS_LABEL validation: * must be no more than 63 characters long. * must consist of lower case alphanumeric characters or '-'. * must start and end with an alphanumeric character. Default is empty string.".to_owned()),
177 ..Default::default()
178 })),
179 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
180 ..Default::default()
181 }),
182 ),
183 (
184 "port".to_owned(),
185 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
186 metadata: Some(Box::new(crate::schemars::schema::Metadata {
187 description: Some("port represents the port number of the endpoint. If this is not specified, ports are not restricted and must be interpreted in the context of the specific consumer.".to_owned()),
188 ..Default::default()
189 })),
190 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
191 format: Some("int32".to_owned()),
192 ..Default::default()
193 }),
194 ),
195 (
196 "protocol".to_owned(),
197 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
198 metadata: Some(Box::new(crate::schemars::schema::Metadata {
199 description: Some("protocol represents the IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.".to_owned()),
200 ..Default::default()
201 })),
202 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
203 ..Default::default()
204 }),
205 ),
206 ].into(),
207 ..Default::default()
208 })),
209 ..Default::default()
210 })
211 }
212}