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

    1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrArray
    2
    3/// JSONSchemaPropsOrArray represents a value that can either be a JSONSchemaProps or an array of JSONSchemaProps. Mainly here for serialization purposes.
    4#[derive(Clone, Debug, PartialEq)]
    5pub enum JSONSchemaPropsOrArray {
    6    Schema(std::boxed::Box<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::JSONSchemaProps>),
    7    Schemas(std::vec::Vec<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::JSONSchemaProps>),
    8}
    9
    10impl crate::DeepMerge for JSONSchemaPropsOrArray {
    11    fn merge_from(&mut self, other: Self) {
    12        *self = other;
    13    }
    14}
    15
    16impl<'de> crate::serde::Deserialize<'de> for JSONSchemaPropsOrArray {
    17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    18        struct Visitor;
    19
    20        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    21            type Value = JSONSchemaPropsOrArray;
    22
    23            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    24                f.write_str("JSONSchemaPropsOrArray")
    25            }
    26
    27            fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    28                Ok(JSONSchemaPropsOrArray::Schema(crate::serde::de::Deserialize::deserialize(crate::serde::de::value::MapAccessDeserializer::new(map))?))
    29            }
    30
    31            fn visit_seq<A>(self, seq: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::SeqAccess<'de> {
    32                Ok(JSONSchemaPropsOrArray::Schemas(crate::serde::de::Deserialize::deserialize(crate::serde::de::value::SeqAccessDeserializer::new(seq))?))
    33            }
    34        }
    35
    36        deserializer.deserialize_any(Visitor)
    37    }
    38}
    39
    40impl crate::serde::Serialize for JSONSchemaPropsOrArray {
    41    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    42        match self {
    43            JSONSchemaPropsOrArray::Schema(value) => value.serialize(serializer),
    44            JSONSchemaPropsOrArray::Schemas(value) => value.serialize(serializer),
    45        }
    46    }
    47}
    48
    49#[cfg(feature = "schemars")]
    50impl crate::schemars::JsonSchema for JSONSchemaPropsOrArray {
    51    fn schema_name() -> std::borrow::Cow<'static, str> {
    52        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrArray".into()
    53    }
    54
    55    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    56        crate::schemars::json_schema!({
    57            "description": "JSONSchemaPropsOrArray represents a value that can either be a JSONSchemaProps or an array of JSONSchemaProps. Mainly here for serialization purposes.",
    58            "oneOf": [
    59                (__gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::JSONSchemaProps>()),
    60                {
    61                    "type": "array",
    62                    "items": (__gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::JSONSchemaProps>()),
    63                },
    64            ],
    65        })
    66    }
    67}