k8s_openapi/v1_35/apiextensions_apiserver/pkg/apis/apiextensions/v1/
json_schema_props_or_bool.rs

1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrBool
2
3/// JSONSchemaPropsOrBool represents JSONSchemaProps or a boolean value. Defaults to true for the boolean property.
4#[derive(Clone, Debug, PartialEq)]
5pub enum JSONSchemaPropsOrBool {
6    Schema(std::boxed::Box<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::JSONSchemaProps>),
7    Bool(bool),
8}
9
10impl crate::DeepMerge for JSONSchemaPropsOrBool {
11    fn merge_from(&mut self, other: Self) {
12        *self = other;
13    }
14}
15
16impl<'de> crate::serde::Deserialize<'de> for JSONSchemaPropsOrBool {
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 = JSONSchemaPropsOrBool;
22
23            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
24                f.write_str("JSONSchemaPropsOrBool")
25            }
26
27            fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
28                Ok(JSONSchemaPropsOrBool::Schema(crate::serde::de::Deserialize::deserialize(crate::serde::de::value::MapAccessDeserializer::new(map))?))
29            }
30
31            fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E> where E: crate::serde::de::Error {
32                Ok(JSONSchemaPropsOrBool::Bool(v))
33            }
34        }
35
36        deserializer.deserialize_any(Visitor)
37    }
38}
39
40impl crate::serde::Serialize for JSONSchemaPropsOrBool {
41    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
42        match self {
43            JSONSchemaPropsOrBool::Schema(value) => value.serialize(serializer),
44            JSONSchemaPropsOrBool::Bool(value) => value.serialize(serializer),
45        }
46    }
47}
48
49#[cfg(feature = "schemars")]
50impl crate::schemars::JsonSchema for JSONSchemaPropsOrBool {
51    fn schema_name() -> std::borrow::Cow<'static, str> {
52        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrBool".into()
53    }
54
55    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
56        crate::schemars::json_schema!({
57            "description": "JSONSchemaPropsOrBool represents JSONSchemaProps or a boolean value. Defaults to true for the boolean property.",
58            "oneOf": [
59                (__gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::JSONSchemaProps>()),
60                {
61                    "type": "boolean",
62                },
63            ],
64        })
65    }
66}