1 1 | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 2 | /// Orchestration and serialization glue logic for `GreetingWithErrors`.
|
3 3 | #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
|
4 4 | #[non_exhaustive]
|
5 5 | pub struct GreetingWithErrors;
|
6 6 | impl GreetingWithErrors {
|
7 7 | /// Creates a new `GreetingWithErrors`
|
8 8 | pub fn new() -> Self {
|
9 9 | Self
|
10 10 | }
|
11 + | /// The schema for this operation's input shape.
|
12 + | pub const INPUT_SCHEMA: &'static ::aws_smithy_schema::Schema = crate::operation::greeting_with_errors::GreetingWithErrorsInput::SCHEMA;
|
13 + | /// The schema for this operation's output shape.
|
14 + | pub const OUTPUT_SCHEMA: &'static ::aws_smithy_schema::Schema = crate::operation::greeting_with_errors::GreetingWithErrorsOutput::SCHEMA;
|
11 15 | pub(crate) async fn orchestrate(
|
12 16 | runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
|
13 17 | input: crate::operation::greeting_with_errors::GreetingWithErrorsInput,
|
14 18 | ) -> ::std::result::Result<
|
15 19 | crate::operation::greeting_with_errors::GreetingWithErrorsOutput,
|
16 20 | ::aws_smithy_runtime_api::client::result::SdkError<
|
17 21 | crate::operation::greeting_with_errors::GreetingWithErrorsError,
|
18 22 | ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
|
19 23 | >,
|
20 24 | > {
|
263 268 | .expect("the config must have a deserializer");
|
264 269 |
|
265 270 | let parsed = de.deserialize_streaming(&mut http_response);
|
266 271 | let parsed = parsed.unwrap_or_else(|| {
|
267 272 | let http_response = http_response.map(|body| {
|
268 273 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
269 274 | body.bytes().unwrap(),
|
270 275 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
271 276 | )))
|
272 277 | });
|
273 - | de.deserialize_nonstreaming(&http_response)
|
278 + | // Build a config bag with the protocol for schema-based deserialization
|
279 + | #[allow(unused_mut)]
|
280 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
281 + |
|
282 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
274 283 | });
|
275 284 | let parsed = parsed
|
276 285 | .expect("should be successful response")
|
277 286 | .downcast::<crate::operation::greeting_with_errors::GreetingWithErrorsOutput>()
|
278 287 | .unwrap();
|
279 288 | ::pretty_assertions::assert_eq!(parsed.greeting, expected_output.greeting, "Unexpected value for `greeting`");
|
280 289 | }
|
281 290 |
|
282 291 | /// Parses simple XML errors
|
283 292 | /// Test ID: InvalidGreetingError
|
284 293 | #[::tokio::test]
|
285 294 | #[::tracing_test::traced_test]
|
286 295 | async fn invalid_greeting_error_response() {
|
287 296 | let expected_output = crate::types::error::InvalidGreeting::builder()
|
288 297 | .set_message(::std::option::Option::Some("Hi".to_owned()))
|
289 298 | .build();
|
290 299 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(::http_1x::response::Builder::new()
|
291 300 | .header("Content-Type", "application/xml")
|
292 301 | .status(400)
|
293 302 | .body(::aws_smithy_types::body::SdkBody::from("<ErrorResponse>\n <Error>\n <Type>Sender</Type>\n <Code>InvalidGreeting</Code>\n <Message>Hi</Message>\n <AnotherSetting>setting</AnotherSetting>\n </Error>\n <RequestId>foo-id</RequestId>\n</ErrorResponse>\n"))
|
294 303 | .unwrap()
|
295 304 | ).unwrap();
|
296 305 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
297 306 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
298 307 |
|
299 308 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
300 309 | let config = op.config().expect("the operation has config");
|
301 310 | let de = config
|
302 311 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
303 312 | .expect("the config must have a deserializer");
|
304 313 |
|
305 314 | let parsed = de.deserialize_streaming(&mut http_response);
|
306 315 | let parsed = parsed.unwrap_or_else(|| {
|
307 316 | let http_response = http_response.map(|body| {
|
308 317 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
309 318 | body.bytes().unwrap(),
|
310 319 | ::aws_smithy_protocol_test::MediaType::from("application/xml"),
|
311 320 | )))
|
312 321 | });
|
313 - | de.deserialize_nonstreaming(&http_response)
|
322 + | // Build a config bag with the protocol for schema-based deserialization
|
323 + | #[allow(unused_mut)]
|
324 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
325 + |
|
326 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
314 327 | });
|
315 328 | let parsed = parsed.expect_err("should be error response");
|
316 329 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
317 330 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
318 331 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::InvalidGreeting(parsed) = parsed {
|
319 332 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
320 333 | } else {
|
321 334 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
322 335 | }
|
323 336 | }
|
324 337 | /// Test ID: ComplexError
|
325 338 | #[::tokio::test]
|
326 339 | #[::tracing_test::traced_test]
|
327 340 | async fn complex_error_response() {
|
328 341 | let expected_output = crate::types::error::ComplexError::builder()
|
329 342 | .set_header(::std::option::Option::Some("Header".to_owned()))
|
330 343 | .set_top_level(::std::option::Option::Some("Top level".to_owned()))
|
331 344 | .set_nested(::std::option::Option::Some(
|
332 345 | crate::types::ComplexNestedErrorData::builder()
|
333 346 | .set_foo(::std::option::Option::Some("bar".to_owned()))
|
334 347 | .build(),
|
335 348 | ))
|
336 349 | .build();
|
337 350 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(::http_1x::response::Builder::new()
|
338 351 | .header("Content-Type", "application/xml")
|
339 352 | .header("X-Header", "Header")
|
340 353 | .status(403)
|
341 354 | .body(::aws_smithy_types::body::SdkBody::from("<ErrorResponse>\n <Error>\n <Type>Sender</Type>\n <Code>ComplexError</Code>\n <Message>Hi</Message>\n <TopLevel>Top level</TopLevel>\n <Nested>\n <Foo>bar</Foo>\n </Nested>\n </Error>\n <RequestId>foo-id</RequestId>\n</ErrorResponse>\n"))
|
342 355 | .unwrap()
|
343 356 | ).unwrap();
|
344 357 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
345 358 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
346 359 |
|
347 360 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
348 361 | let config = op.config().expect("the operation has config");
|
349 362 | let de = config
|
350 363 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
351 364 | .expect("the config must have a deserializer");
|
352 365 |
|
353 366 | let parsed = de.deserialize_streaming(&mut http_response);
|
354 367 | let parsed = parsed.unwrap_or_else(|| {
|
355 368 | let http_response = http_response.map(|body| {
|
356 369 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
357 370 | body.bytes().unwrap(),
|
358 371 | ::aws_smithy_protocol_test::MediaType::from("application/xml"),
|
359 372 | )))
|
360 373 | });
|
361 - | de.deserialize_nonstreaming(&http_response)
|
374 + | // Build a config bag with the protocol for schema-based deserialization
|
375 + | #[allow(unused_mut)]
|
376 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
377 + |
|
378 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
362 379 | });
|
363 380 | let parsed = parsed.expect_err("should be error response");
|
364 381 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
365 382 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
366 383 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError(parsed) = parsed {
|
367 384 | ::pretty_assertions::assert_eq!(parsed.header, expected_output.header, "Unexpected value for `header`");
|
368 385 | ::pretty_assertions::assert_eq!(parsed.top_level, expected_output.top_level, "Unexpected value for `top_level`");
|
369 386 | ::pretty_assertions::assert_eq!(parsed.nested, expected_output.nested, "Unexpected value for `nested`");
|
370 387 | } else {
|
371 388 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|