#
k8s_openapi/v1_35/apiextensions_apiserver/pkg/apis/apiextensions/v1/
external_documentation.rs

    1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ExternalDocumentation
    2
    3/// ExternalDocumentation allows referencing an external resource for extended documentation.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ExternalDocumentation {
    6    pub description: Option<std::string::String>,
    7
    8    pub url: Option<std::string::String>,
    9}
    10
    11impl crate::DeepMerge for ExternalDocumentation {
    12    fn merge_from(&mut self, other: Self) {
    13        crate::DeepMerge::merge_from(&mut self.description, other.description);
    14        crate::DeepMerge::merge_from(&mut self.url, other.url);
    15    }
    16}
    17
    18impl<'de> crate::serde::Deserialize<'de> for ExternalDocumentation {
    19    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    20        #[allow(non_camel_case_types)]
    21        enum Field {
    22            Key_description,
    23            Key_url,
    24            Other,
    25        }
    26
    27        impl<'de> crate::serde::Deserialize<'de> for Field {
    28            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    29                struct Visitor;
    30
    31                impl crate::serde::de::Visitor<'_> for Visitor {
    32                    type Value = Field;
    33
    34                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    35                        f.write_str("field identifier")
    36                    }
    37
    38                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    39                        Ok(match v {
    40                            "description" => Field::Key_description,
    41                            "url" => Field::Key_url,
    42                            _ => Field::Other,
    43                        })
    44                    }
    45                }
    46
    47                deserializer.deserialize_identifier(Visitor)
    48            }
    49        }
    50
    51        struct Visitor;
    52
    53        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    54            type Value = ExternalDocumentation;
    55
    56            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    57                f.write_str("ExternalDocumentation")
    58            }
    59
    60            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    61                let mut value_description: Option<std::string::String> = None;
    62                let mut value_url: Option<std::string::String> = None;
    63
    64                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    65                    match key {
    66                        Field::Key_description => value_description = crate::serde::de::MapAccess::next_value(&mut map)?,
    67                        Field::Key_url => value_url = crate::serde::de::MapAccess::next_value(&mut map)?,
    68                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    69                    }
    70                }
    71
    72                Ok(ExternalDocumentation {
    73                    description: value_description,
    74                    url: value_url,
    75                })
    76            }
    77        }
    78
    79        deserializer.deserialize_struct(
    80            "ExternalDocumentation",
    81            &[
    82                "description",
    83                "url",
    84            ],
    85            Visitor,
    86        )
    87    }
    88}
    89
    90impl crate::serde::Serialize for ExternalDocumentation {
    91    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    92        let mut state = serializer.serialize_struct(
    93            "ExternalDocumentation",
    94            self.description.as_ref().map_or(0, |_| 1) +
    95            self.url.as_ref().map_or(0, |_| 1),
    96        )?;
    97        if let Some(value) = &self.description {
    98            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "description", value)?;
    99        }
    100        if let Some(value) = &self.url {
    101            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "url", value)?;
    102        }
    103        crate::serde::ser::SerializeStruct::end(state)
    104    }
    105}
    106
    107#[cfg(feature = "schemars")]
    108impl crate::schemars::JsonSchema for ExternalDocumentation {
    109    fn schema_name() -> std::borrow::Cow<'static, str> {
    110        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ExternalDocumentation".into()
    111    }
    112
    113    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    114        crate::schemars::json_schema!({
    115            "description": "ExternalDocumentation allows referencing an external resource for extended documentation.",
    116            "type": "object",
    117            "properties": {
    118                "description": {
    119                    "type": "string",
    120                },
    121                "url": {
    122                    "type": "string",
    123                },
    124            },
    125        })
    126    }
    127}