k8s_openapi/v1_32/api/admissionregistration/v1alpha1/
mutation.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Mutation {
6 pub apply_configuration: Option<crate::api::admissionregistration::v1alpha1::ApplyConfiguration>,
8
9 pub json_patch: Option<crate::api::admissionregistration::v1alpha1::JSONPatch>,
11
12 pub patch_type: String,
14}
15
16impl crate::DeepMerge for Mutation {
17 fn merge_from(&mut self, other: Self) {
18 crate::DeepMerge::merge_from(&mut self.apply_configuration, other.apply_configuration);
19 crate::DeepMerge::merge_from(&mut self.json_patch, other.json_patch);
20 crate::DeepMerge::merge_from(&mut self.patch_type, other.patch_type);
21 }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for Mutation {
25 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26 #[allow(non_camel_case_types)]
27 enum Field {
28 Key_apply_configuration,
29 Key_json_patch,
30 Key_patch_type,
31 Other,
32 }
33
34 impl<'de> crate::serde::Deserialize<'de> for Field {
35 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36 struct Visitor;
37
38 impl crate::serde::de::Visitor<'_> for Visitor {
39 type Value = Field;
40
41 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 f.write_str("field identifier")
43 }
44
45 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46 Ok(match v {
47 "applyConfiguration" => Field::Key_apply_configuration,
48 "jsonPatch" => Field::Key_json_patch,
49 "patchType" => Field::Key_patch_type,
50 _ => Field::Other,
51 })
52 }
53 }
54
55 deserializer.deserialize_identifier(Visitor)
56 }
57 }
58
59 struct Visitor;
60
61 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62 type Value = Mutation;
63
64 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 f.write_str("Mutation")
66 }
67
68 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69 let mut value_apply_configuration: Option<crate::api::admissionregistration::v1alpha1::ApplyConfiguration> = None;
70 let mut value_json_patch: Option<crate::api::admissionregistration::v1alpha1::JSONPatch> = None;
71 let mut value_patch_type: Option<String> = None;
72
73 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74 match key {
75 Field::Key_apply_configuration => value_apply_configuration = crate::serde::de::MapAccess::next_value(&mut map)?,
76 Field::Key_json_patch => value_json_patch = crate::serde::de::MapAccess::next_value(&mut map)?,
77 Field::Key_patch_type => value_patch_type = crate::serde::de::MapAccess::next_value(&mut map)?,
78 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79 }
80 }
81
82 Ok(Mutation {
83 apply_configuration: value_apply_configuration,
84 json_patch: value_json_patch,
85 patch_type: value_patch_type.unwrap_or_default(),
86 })
87 }
88 }
89
90 deserializer.deserialize_struct(
91 "Mutation",
92 &[
93 "applyConfiguration",
94 "jsonPatch",
95 "patchType",
96 ],
97 Visitor,
98 )
99 }
100}
101
102impl crate::serde::Serialize for Mutation {
103 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104 let mut state = serializer.serialize_struct(
105 "Mutation",
106 1 +
107 self.apply_configuration.as_ref().map_or(0, |_| 1) +
108 self.json_patch.as_ref().map_or(0, |_| 1),
109 )?;
110 if let Some(value) = &self.apply_configuration {
111 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "applyConfiguration", value)?;
112 }
113 if let Some(value) = &self.json_patch {
114 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "jsonPatch", value)?;
115 }
116 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "patchType", &self.patch_type)?;
117 crate::serde::ser::SerializeStruct::end(state)
118 }
119}
120
121#[cfg(feature = "schemars")]
122impl crate::schemars::JsonSchema for Mutation {
123 fn schema_name() -> String {
124 "io.k8s.api.admissionregistration.v1alpha1.Mutation".to_owned()
125 }
126
127 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
128 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
129 metadata: Some(Box::new(crate::schemars::schema::Metadata {
130 description: Some("Mutation specifies the CEL expression which is used to apply the Mutation.".to_owned()),
131 ..Default::default()
132 })),
133 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
134 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
135 properties: [
136 (
137 "applyConfiguration".to_owned(),
138 {
139 let mut schema_obj = __gen.subschema_for::<crate::api::admissionregistration::v1alpha1::ApplyConfiguration>().into_object();
140 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
141 description: Some("applyConfiguration defines the desired configuration values of an object. The configuration is applied to the admission object using [structured merge diff](https://github.com/kubernetes-sigs/structured-merge-diff). A CEL expression is used to create apply configuration.".to_owned()),
142 ..Default::default()
143 }));
144 crate::schemars::schema::Schema::Object(schema_obj)
145 },
146 ),
147 (
148 "jsonPatch".to_owned(),
149 {
150 let mut schema_obj = __gen.subschema_for::<crate::api::admissionregistration::v1alpha1::JSONPatch>().into_object();
151 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
152 description: Some("jsonPatch defines a [JSON patch](https://jsonpatch.com/) operation to perform a mutation to the object. A CEL expression is used to create the JSON patch.".to_owned()),
153 ..Default::default()
154 }));
155 crate::schemars::schema::Schema::Object(schema_obj)
156 },
157 ),
158 (
159 "patchType".to_owned(),
160 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
161 metadata: Some(Box::new(crate::schemars::schema::Metadata {
162 description: Some("patchType indicates the patch strategy used. Allowed values are \"ApplyConfiguration\" and \"JSONPatch\". Required.".to_owned()),
163 ..Default::default()
164 })),
165 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
166 ..Default::default()
167 }),
168 ),
169 ].into(),
170 required: [
171 "patchType".to_owned(),
172 ].into(),
173 ..Default::default()
174 })),
175 ..Default::default()
176 })
177 }
178}