k8s_openapi/v1_35/api/core/v1/
grpc_action.rs

1// Generated from definition io.k8s.api.core.v1.GRPCAction
2
3/// GRPCAction specifies an action involving a GRPC service.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct GRPCAction {
6    /// Port number of the gRPC service. Number must be in the range 1 to 65535.
7    pub port: i32,
8
9    /// Service is the name of the service to place in the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md).
10    ///
11    /// If this is not specified, the default behavior is defined by gRPC.
12    pub service: Option<std::string::String>,
13}
14
15impl crate::DeepMerge for GRPCAction {
16    fn merge_from(&mut self, other: Self) {
17        crate::DeepMerge::merge_from(&mut self.port, other.port);
18        crate::DeepMerge::merge_from(&mut self.service, other.service);
19    }
20}
21
22impl<'de> crate::serde::Deserialize<'de> for GRPCAction {
23    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
24        #[allow(non_camel_case_types)]
25        enum Field {
26            Key_port,
27            Key_service,
28            Other,
29        }
30
31        impl<'de> crate::serde::Deserialize<'de> for Field {
32            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
33                struct Visitor;
34
35                impl crate::serde::de::Visitor<'_> for Visitor {
36                    type Value = Field;
37
38                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
39                        f.write_str("field identifier")
40                    }
41
42                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
43                        Ok(match v {
44                            "port" => Field::Key_port,
45                            "service" => Field::Key_service,
46                            _ => Field::Other,
47                        })
48                    }
49                }
50
51                deserializer.deserialize_identifier(Visitor)
52            }
53        }
54
55        struct Visitor;
56
57        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
58            type Value = GRPCAction;
59
60            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61                f.write_str("GRPCAction")
62            }
63
64            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
65                let mut value_port: Option<i32> = None;
66                let mut value_service: Option<std::string::String> = None;
67
68                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
69                    match key {
70                        Field::Key_port => value_port = crate::serde::de::MapAccess::next_value(&mut map)?,
71                        Field::Key_service => value_service = crate::serde::de::MapAccess::next_value(&mut map)?,
72                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
73                    }
74                }
75
76                Ok(GRPCAction {
77                    port: value_port.unwrap_or_default(),
78                    service: value_service,
79                })
80            }
81        }
82
83        deserializer.deserialize_struct(
84            "GRPCAction",
85            &[
86                "port",
87                "service",
88            ],
89            Visitor,
90        )
91    }
92}
93
94impl crate::serde::Serialize for GRPCAction {
95    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
96        let mut state = serializer.serialize_struct(
97            "GRPCAction",
98            1 +
99            self.service.as_ref().map_or(0, |_| 1),
100        )?;
101        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", &self.port)?;
102        if let Some(value) = &self.service {
103            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "service", value)?;
104        }
105        crate::serde::ser::SerializeStruct::end(state)
106    }
107}
108
109#[cfg(feature = "schemars")]
110impl crate::schemars::JsonSchema for GRPCAction {
111    fn schema_name() -> std::borrow::Cow<'static, str> {
112        "io.k8s.api.core.v1.GRPCAction".into()
113    }
114
115    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
116        crate::schemars::json_schema!({
117            "description": "GRPCAction specifies an action involving a GRPC service.",
118            "type": "object",
119            "properties": {
120                "port": {
121                    "description": "Port number of the gRPC service. Number must be in the range 1 to 65535.",
122                    "type": "integer",
123                    "format": "int32",
124                },
125                "service": {
126                    "description": "Service is the name of the service to place in the gRPC HealthCheckRequest (see https://github.com/grpc/grpc/blob/master/doc/health-checking.md).\n\nIf this is not specified, the default behavior is defined by gRPC.",
127                    "type": "string",
128                },
129            },
130            "required": [
131                "port",
132            ],
133        })
134    }
135}