k8s_openapi/v1_30/apimachinery/pkg/apis/meta/v1/
status_cause.rs

1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause
2
3/// StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct StatusCause {
6    /// The field of the resource that has caused this error, as named by its JSON serialization. May include dot and postfix notation for nested attributes. Arrays are zero-indexed.  Fields may appear more than once in an array of causes due to fields having multiple errors. Optional.
7    ///
8    /// Examples:
9    ///   "name" - the field "name" on the current resource
10    ///   "items\[0\].name" - the field "name" on the first array entry in "items"
11    pub field: Option<String>,
12
13    /// A human-readable description of the cause of the error.  This field may be presented as-is to a reader.
14    pub message: Option<String>,
15
16    /// A machine-readable description of the cause of the error. If this value is empty there is no information available.
17    pub reason: Option<String>,
18}
19
20impl crate::DeepMerge for StatusCause {
21    fn merge_from(&mut self, other: Self) {
22        crate::DeepMerge::merge_from(&mut self.field, other.field);
23        crate::DeepMerge::merge_from(&mut self.message, other.message);
24        crate::DeepMerge::merge_from(&mut self.reason, other.reason);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for StatusCause {
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_field,
33            Key_message,
34            Key_reason,
35            Other,
36        }
37
38        impl<'de> crate::serde::Deserialize<'de> for Field {
39            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40                struct Visitor;
41
42                impl<'de> crate::serde::de::Visitor<'de> for Visitor {
43                    type Value = Field;
44
45                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46                        f.write_str("field identifier")
47                    }
48
49                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
50                        Ok(match v {
51                            "field" => Field::Key_field,
52                            "message" => Field::Key_message,
53                            "reason" => Field::Key_reason,
54                            _ => Field::Other,
55                        })
56                    }
57                }
58
59                deserializer.deserialize_identifier(Visitor)
60            }
61        }
62
63        struct Visitor;
64
65        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66            type Value = StatusCause;
67
68            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69                f.write_str("StatusCause")
70            }
71
72            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73                let mut value_field: Option<String> = None;
74                let mut value_message: Option<String> = None;
75                let mut value_reason: Option<String> = None;
76
77                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
78                    match key {
79                        Field::Key_field => value_field = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Key_message => value_message = crate::serde::de::MapAccess::next_value(&mut map)?,
81                        Field::Key_reason => value_reason = crate::serde::de::MapAccess::next_value(&mut map)?,
82                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
83                    }
84                }
85
86                Ok(StatusCause {
87                    field: value_field,
88                    message: value_message,
89                    reason: value_reason,
90                })
91            }
92        }
93
94        deserializer.deserialize_struct(
95            "StatusCause",
96            &[
97                "field",
98                "message",
99                "reason",
100            ],
101            Visitor,
102        )
103    }
104}
105
106impl crate::serde::Serialize for StatusCause {
107    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
108        let mut state = serializer.serialize_struct(
109            "StatusCause",
110            self.field.as_ref().map_or(0, |_| 1) +
111            self.message.as_ref().map_or(0, |_| 1) +
112            self.reason.as_ref().map_or(0, |_| 1),
113        )?;
114        if let Some(value) = &self.field {
115            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "field", value)?;
116        }
117        if let Some(value) = &self.message {
118            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "message", value)?;
119        }
120        if let Some(value) = &self.reason {
121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reason", value)?;
122        }
123        crate::serde::ser::SerializeStruct::end(state)
124    }
125}
126
127#[cfg(feature = "schemars")]
128impl crate::schemars::JsonSchema for StatusCause {
129    fn schema_name() -> String {
130        "io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause".to_owned()
131    }
132
133    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
134        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
135            metadata: Some(Box::new(crate::schemars::schema::Metadata {
136                description: Some("StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.".to_owned()),
137                ..Default::default()
138            })),
139            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
140            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
141                properties: [
142                    (
143                        "field".to_owned(),
144                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
145                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
146                                description: Some("The field of the resource that has caused this error, as named by its JSON serialization. May include dot and postfix notation for nested attributes. Arrays are zero-indexed.  Fields may appear more than once in an array of causes due to fields having multiple errors. Optional.\n\nExamples:\n  \"name\" - the field \"name\" on the current resource\n  \"items[0].name\" - the field \"name\" on the first array entry in \"items\"".to_owned()),
147                                ..Default::default()
148                            })),
149                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
150                            ..Default::default()
151                        }),
152                    ),
153                    (
154                        "message".to_owned(),
155                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
156                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
157                                description: Some("A human-readable description of the cause of the error.  This field may be presented as-is to a reader.".to_owned()),
158                                ..Default::default()
159                            })),
160                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
161                            ..Default::default()
162                        }),
163                    ),
164                    (
165                        "reason".to_owned(),
166                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
167                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
168                                description: Some("A machine-readable description of the cause of the error. If this value is empty there is no information available.".to_owned()),
169                                ..Default::default()
170                            })),
171                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
172                            ..Default::default()
173                        }),
174                    ),
175                ].into(),
176                ..Default::default()
177            })),
178            ..Default::default()
179        })
180    }
181}