aws_sdk_codepipeline/protocol_serde/
shape_webhook_definition.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_webhook_definition(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::WebhookDefinition,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    {
7        object.key("name").string(input.name.as_str());
8    }
9    {
10        object.key("targetPipeline").string(input.target_pipeline.as_str());
11    }
12    {
13        object.key("targetAction").string(input.target_action.as_str());
14    }
15    {
16        let mut array_1 = object.key("filters").start_array();
17        for item_2 in &input.filters {
18            {
19                #[allow(unused_mut)]
20                let mut object_3 = array_1.value().start_object();
21                crate::protocol_serde::shape_webhook_filter_rule::ser_webhook_filter_rule(&mut object_3, item_2)?;
22                object_3.finish();
23            }
24        }
25        array_1.finish();
26    }
27    {
28        object.key("authentication").string(input.authentication.as_str());
29    }
30    if let Some(var_4) = &input.authentication_configuration {
31        #[allow(unused_mut)]
32        let mut object_5 = object.key("authenticationConfiguration").start_object();
33        crate::protocol_serde::shape_webhook_auth_configuration::ser_webhook_auth_configuration(&mut object_5, var_4)?;
34        object_5.finish();
35    }
36    Ok(())
37}
38
39pub(crate) fn de_webhook_definition<'a, I>(
40    tokens: &mut ::std::iter::Peekable<I>,
41) -> ::std::result::Result<Option<crate::types::WebhookDefinition>, ::aws_smithy_json::deserialize::error::DeserializeError>
42where
43    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
44{
45    match tokens.next().transpose()? {
46        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
47        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
48            #[allow(unused_mut)]
49            let mut builder = crate::types::builders::WebhookDefinitionBuilder::default();
50            loop {
51                match tokens.next().transpose()? {
52                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
53                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
54                        "name" => {
55                            builder = builder.set_name(
56                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
57                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
58                                    .transpose()?,
59                            );
60                        }
61                        "targetPipeline" => {
62                            builder = builder.set_target_pipeline(
63                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
64                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
65                                    .transpose()?,
66                            );
67                        }
68                        "targetAction" => {
69                            builder = builder.set_target_action(
70                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
71                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
72                                    .transpose()?,
73                            );
74                        }
75                        "filters" => {
76                            builder = builder.set_filters(crate::protocol_serde::shape_webhook_filters::de_webhook_filters(tokens)?);
77                        }
78                        "authentication" => {
79                            builder = builder.set_authentication(
80                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
81                                    .map(|s| s.to_unescaped().map(|u| crate::types::WebhookAuthenticationType::from(u.as_ref())))
82                                    .transpose()?,
83                            );
84                        }
85                        "authenticationConfiguration" => {
86                            builder = builder.set_authentication_configuration(
87                                crate::protocol_serde::shape_webhook_auth_configuration::de_webhook_auth_configuration(tokens)?,
88                            );
89                        }
90                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
91                    },
92                    other => {
93                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
94                            "expected object key or end object, found: {:?}",
95                            other
96                        )))
97                    }
98                }
99            }
100            Ok(Some(crate::serde_util::webhook_definition_correct_errors(builder).build().map_err(
101                |err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err),
102            )?))
103        }
104        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
105            "expected start object or null",
106        )),
107    }
108}