#
k8s_openapi/v1_35/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<std::string::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<std::string::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<std::string::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 crate::serde::de::Visitor<'_> for Visitor {
    43                    type Value = Field;
    44
    45                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::string::String> = None;
    74                let mut value_message: Option<std::string::String> = None;
    75                let mut value_reason: Option<std::string::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() -> std::borrow::Cow<'static, str> {
    130        "io.k8s.apimachinery.pkg.apis.meta.v1.StatusCause".into()
    131    }
    132
    133    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    134        crate::schemars::json_schema!({
    135            "description": "StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.",
    136            "type": "object",
    137            "properties": {
    138                "field": {
    139                    "description": "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\"",
    140                    "type": "string",
    141                },
    142                "message": {
    143                    "description": "A human-readable description of the cause of the error.  This field may be presented as-is to a reader.",
    144                    "type": "string",
    145                },
    146                "reason": {
    147                    "description": "A machine-readable description of the cause of the error. If this value is empty there is no information available.",
    148                    "type": "string",
    149                },
    150            },
    151        })
    152    }
    153}