k8s_openapi/v1_34/api/discovery/v1/
endpoint_port.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct EndpointPort {
6 pub app_protocol: Option<std::string::String>,
17
18 pub name: Option<std::string::String>,
20
21 pub port: Option<i32>,
23
24 pub protocol: Option<std::string::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::string::String> = None;
85 let mut value_name: Option<std::string::String> = None;
86 let mut value_port: Option<i32> = None;
87 let mut value_protocol: Option<std::string::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() -> std::borrow::Cow<'static, str> {
149 "io.k8s.api.discovery.v1.EndpointPort".into()
150 }
151
152 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
153 crate::schemars::json_schema!({
154 "description": "EndpointPort represents a Port used by an EndpointSlice",
155 "type": "object",
156 "properties": {
157 "appProtocol": {
158 "description": "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.",
159 "type": "string",
160 },
161 "name": {
162 "description": "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.",
163 "type": "string",
164 },
165 "port": {
166 "description": "port represents the port number of the endpoint. If the EndpointSlice is derived from a Kubernetes service, this must be set to the service's target port. EndpointSlices used for other purposes may have a nil port.",
167 "type": "integer",
168 "format": "int32",
169 },
170 "protocol": {
171 "description": "protocol represents the IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.",
172 "type": "string",
173 },
174 },
175 })
176 }
177}