133 137 | ::std::borrow::Cow::Owned(rcb)
|
134 138 | }
|
135 139 | }
|
136 140 |
|
137 141 | #[derive(Debug)]
|
138 142 | struct GreetingWithErrorsResponseDeserializer;
|
139 143 | impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for GreetingWithErrorsResponseDeserializer {
|
140 144 | fn deserialize_nonstreaming(
|
141 145 | &self,
|
142 146 | response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
|
147 + | _cfg: &::aws_smithy_types::config_bag::ConfigBag,
|
143 148 | ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
|
144 149 | let (success, status) = (response.status().is_success(), response.status().as_u16());
|
145 - | let headers = response.headers();
|
146 - | let body = response.body().bytes().expect("body loaded");
|
147 150 | #[allow(unused_mut)]
|
148 151 | let mut force_error = false;
|
149 152 |
|
150 - | let parse_result = if !success && status != 200 || force_error {
|
151 - | crate::protocol_serde::shape_greeting_with_errors::de_greeting_with_errors_http_error(status, headers, body)
|
153 + | if !success && status != 200 || force_error {
|
154 + | let headers = response.headers();
|
155 + | let body = response.body().bytes().expect("body loaded");
|
156 + | #[allow(unused_mut)]
|
157 + | let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(status, headers, body).map_err(|e| {
|
158 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
159 + | })?;
|
160 + |
|
161 + | let generic = generic_builder.build();
|
162 + | let error_code = match generic.code() {
|
163 + | ::std::option::Option::Some(code) => code,
|
164 + | ::std::option::Option::None => {
|
165 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
166 + | ::aws_smithy_runtime_api::box_error::BoxError::from(
|
167 + | crate::operation::greeting_with_errors::GreetingWithErrorsError::unhandled(generic),
|
168 + | ),
|
169 + | ))
|
170 + | }
|
171 + | };
|
172 + | let _error_message = generic.message().map(|msg| msg.to_owned());
|
173 + | let protocol = _cfg
|
174 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
175 + | .expect("a SharedClientProtocol is required");
|
176 + | let err = match error_code {
|
177 + | "InvalidGreeting" => crate::operation::greeting_with_errors::GreetingWithErrorsError::InvalidGreeting({
|
178 + | let mut tmp = match protocol
|
179 + | .deserialize_response(response, crate::types::error::InvalidGreeting::SCHEMA, _cfg)
|
180 + | .and_then(|mut deser| {
|
181 + | crate::types::error::InvalidGreeting::deserialize_with_response(
|
182 + | &mut *deser,
|
183 + | response.headers(),
|
184 + | response.status().into(),
|
185 + | body,
|
186 + | )
|
187 + | }) {
|
188 + | ::std::result::Result::Ok(val) => val,
|
189 + | ::std::result::Result::Err(e) => {
|
190 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
191 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
192 + | ))
|
193 + | }
|
194 + | };
|
195 + | tmp.meta = generic;
|
196 + | if tmp.message.is_none() {
|
197 + | tmp.message = _error_message;
|
198 + | }
|
199 + | tmp
|
200 + | }),
|
201 + | "ComplexError" => crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError({
|
202 + | let mut tmp = match protocol
|
203 + | .deserialize_response(response, crate::types::error::ComplexError::SCHEMA, _cfg)
|
204 + | .and_then(|mut deser| {
|
205 + | crate::types::error::ComplexError::deserialize_with_response(
|
206 + | &mut *deser,
|
207 + | response.headers(),
|
208 + | response.status().into(),
|
209 + | body,
|
210 + | )
|
211 + | }) {
|
212 + | ::std::result::Result::Ok(val) => val,
|
213 + | ::std::result::Result::Err(e) => {
|
214 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
215 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
216 + | ))
|
217 + | }
|
218 + | };
|
219 + | tmp.meta = generic;
|
220 + | if tmp.message.is_none() {
|
221 + | tmp.message = _error_message;
|
222 + | }
|
223 + | tmp
|
224 + | }),
|
225 + | "FooError" => crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError({
|
226 + | let mut tmp = match protocol
|
227 + | .deserialize_response(response, crate::types::error::FooError::SCHEMA, _cfg)
|
228 + | .and_then(|mut deser| {
|
229 + | crate::types::error::FooError::deserialize_with_response(&mut *deser, response.headers(), response.status().into(), body)
|
230 + | }) {
|
231 + | ::std::result::Result::Ok(val) => val,
|
232 + | ::std::result::Result::Err(e) => {
|
233 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
234 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
235 + | ))
|
236 + | }
|
237 + | };
|
238 + | tmp.meta = generic;
|
239 + | if tmp.message.is_none() {
|
240 + | tmp.message = _error_message;
|
241 + | }
|
242 + | tmp
|
243 + | }),
|
244 + | _ => crate::operation::greeting_with_errors::GreetingWithErrorsError::generic(generic),
|
245 + | };
|
246 + | ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::operation(
|
247 + | ::aws_smithy_runtime_api::client::interceptors::context::Error::erase(err),
|
248 + | ))
|
152 249 | } else {
|
153 - | crate::protocol_serde::shape_greeting_with_errors::de_greeting_with_errors_http_response(status, headers, body)
|
154 - | };
|
155 - | crate::protocol_serde::type_erase_result(parse_result)
|
250 + | let protocol = _cfg
|
251 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
252 + | .expect("a SharedClientProtocol is required");
|
253 + | let mut deser = protocol
|
254 + | .deserialize_response(response, GreetingWithErrors::OUTPUT_SCHEMA, _cfg)
|
255 + | .map_err(|e| {
|
256 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
257 + | })?;
|
258 + | let body = response.body().bytes().expect("body loaded");
|
259 + | let output = crate::operation::greeting_with_errors::GreetingWithErrorsOutput::deserialize_with_response(
|
260 + | &mut *deser,
|
261 + | response.headers(),
|
262 + | response.status().into(),
|
263 + | body,
|
264 + | )
|
265 + | .map_err(|e| {
|
266 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
267 + | })?;
|
268 + | ::std::result::Result::Ok(::aws_smithy_runtime_api::client::interceptors::context::Output::erase(output))
|
269 + | }
|
156 270 | }
|
157 271 | }
|
158 272 | #[derive(Debug)]
|
159 273 | struct GreetingWithErrorsRequestSerializer;
|
160 274 | impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for GreetingWithErrorsRequestSerializer {
|
161 275 | #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
|
162 276 | fn serialize_input(
|
163 277 | &self,
|
164 278 | input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
|
165 279 | _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
|
166 280 | ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
|
167 281 | let input = input
|
168 282 | .downcast::<crate::operation::greeting_with_errors::GreetingWithErrorsInput>()
|
169 283 | .expect("correct type");
|
170 - | let _header_serialization_settings = _cfg
|
171 - | .load::<crate::serialization_settings::HeaderSerializationSettings>()
|
172 - | .cloned()
|
173 - | .unwrap_or_default();
|
174 - | let mut request_builder = {
|
175 - | #[allow(clippy::uninlined_format_args)]
|
176 - | fn uri_base(
|
177 - | _input: &crate::operation::greeting_with_errors::GreetingWithErrorsInput,
|
178 - | output: &mut ::std::string::String,
|
179 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
|
180 - | use ::std::fmt::Write as _;
|
181 - | ::std::write!(output, "/GreetingWithErrors").expect("formatting should succeed");
|
182 - | ::std::result::Result::Ok(())
|
183 - | }
|
184 - | #[allow(clippy::unnecessary_wraps)]
|
185 - | fn update_http_builder(
|
186 - | input: &crate::operation::greeting_with_errors::GreetingWithErrorsInput,
|
187 - | builder: ::http_1x::request::Builder,
|
188 - | ) -> ::std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
|
189 - | let mut uri = ::std::string::String::new();
|
190 - | uri_base(input, &mut uri)?;
|
191 - | ::std::result::Result::Ok(builder.method("PUT").uri(uri))
|
192 - | }
|
193 - | let mut builder = update_http_builder(&input, ::http_1x::request::Builder::new())?;
|
194 - | builder
|
195 - | };
|
196 - | let body = ::aws_smithy_types::body::SdkBody::from("");
|
197 - |
|
198 - | ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
|
284 + | let protocol = _cfg
|
285 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
286 + | .expect("a SharedClientProtocol is required");
|
287 + | let mut request = protocol
|
288 + | .serialize_request(&input, GreetingWithErrors::INPUT_SCHEMA, "", _cfg)
|
289 + | .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
|
290 + |
|
291 + | return ::std::result::Result::Ok(request);
|
199 292 | }
|
200 293 | }
|
201 294 | #[derive(Debug)]
|
202 295 | struct GreetingWithErrorsEndpointParamsInterceptor;
|
203 296 |
|
204 297 | impl ::aws_smithy_runtime_api::client::interceptors::Intercept for GreetingWithErrorsEndpointParamsInterceptor {
|
205 298 | fn name(&self) -> &'static str {
|
206 299 | "GreetingWithErrorsEndpointParamsInterceptor"
|
207 300 | }
|
208 301 |
|
267 360 | .expect("the config must have a deserializer");
|
268 361 |
|
269 362 | let parsed = de.deserialize_streaming(&mut http_response);
|
270 363 | let parsed = parsed.unwrap_or_else(|| {
|
271 364 | let http_response = http_response.map(|body| {
|
272 365 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
273 366 | body.bytes().unwrap(),
|
274 367 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
275 368 | )))
|
276 369 | });
|
277 - | de.deserialize_nonstreaming(&http_response)
|
370 + | // Build a config bag with the protocol for schema-based deserialization
|
371 + | #[allow(unused_mut)]
|
372 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
373 + | {
|
374 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
375 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
376 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
377 + | ));
|
378 + | test_cfg.push_shared_layer(layer.freeze());
|
379 + | }
|
380 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
278 381 | });
|
279 382 | let parsed = parsed
|
280 383 | .expect("should be successful response")
|
281 384 | .downcast::<crate::operation::greeting_with_errors::GreetingWithErrorsOutput>()
|
282 385 | .unwrap();
|
283 386 | ::pretty_assertions::assert_eq!(parsed.greeting, expected_output.greeting, "Unexpected value for `greeting`");
|
284 387 | }
|
285 388 |
|
286 389 | /// This test is similar to RestJsonGreetingWithErrors, but it
|
287 390 | /// ensures that clients can gracefully deal with a server
|
288 391 | /// omitting a response payload.
|
289 392 | /// Test ID: RestJsonGreetingWithErrorsNoPayload
|
290 393 | #[::tokio::test]
|
291 394 | #[::tracing_test::traced_test]
|
292 395 | async fn rest_json_greeting_with_errors_no_payload_response() {
|
293 396 | let expected_output = crate::operation::greeting_with_errors::GreetingWithErrorsOutput::builder()
|
294 397 | .set_greeting(::std::option::Option::Some("Hello".to_owned()))
|
295 398 | .build();
|
296 399 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
297 400 | ::http_1x::response::Builder::new()
|
298 401 | .header("X-Greeting", "Hello")
|
299 402 | .status(200)
|
300 403 | .body(::aws_smithy_types::body::SdkBody::from(""))
|
301 404 | .unwrap(),
|
302 405 | )
|
303 406 | .unwrap();
|
304 407 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
305 408 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
306 409 |
|
307 410 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
308 411 | let config = op.config().expect("the operation has config");
|
309 412 | let de = config
|
310 413 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
311 414 | .expect("the config must have a deserializer");
|
312 415 |
|
313 416 | let parsed = de.deserialize_streaming(&mut http_response);
|
314 417 | let parsed = parsed.unwrap_or_else(|| {
|
315 418 | let http_response = http_response.map(|body| {
|
316 419 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
317 420 | body.bytes().unwrap(),
|
318 421 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
319 422 | )))
|
320 423 | });
|
321 - | de.deserialize_nonstreaming(&http_response)
|
424 + | // Build a config bag with the protocol for schema-based deserialization
|
425 + | #[allow(unused_mut)]
|
426 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
427 + | {
|
428 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
429 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
430 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
431 + | ));
|
432 + | test_cfg.push_shared_layer(layer.freeze());
|
433 + | }
|
434 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
322 435 | });
|
323 436 | let parsed = parsed
|
324 437 | .expect("should be successful response")
|
325 438 | .downcast::<crate::operation::greeting_with_errors::GreetingWithErrorsOutput>()
|
326 439 | .unwrap();
|
327 440 | ::pretty_assertions::assert_eq!(parsed.greeting, expected_output.greeting, "Unexpected value for `greeting`");
|
328 441 | }
|
329 442 |
|
330 443 | /// Parses simple JSON errors
|
331 444 | /// Test ID: RestJsonInvalidGreetingError
|
332 445 | #[::tokio::test]
|
333 446 | #[::tracing_test::traced_test]
|
334 447 | async fn rest_json_invalid_greeting_error_response() {
|
335 448 | let expected_output = crate::types::error::InvalidGreeting::builder()
|
336 449 | .set_message(::std::option::Option::Some("Hi".to_owned()))
|
337 450 | .build();
|
338 451 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
339 452 | ::http_1x::response::Builder::new()
|
340 453 | .header("Content-Type", "application/json")
|
341 454 | .header("X-Amzn-Errortype", "InvalidGreeting")
|
342 455 | .status(400)
|
343 456 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"Message\": \"Hi\"\n}"))
|
344 457 | .unwrap(),
|
345 458 | )
|
346 459 | .unwrap();
|
347 460 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
348 461 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
349 462 |
|
350 463 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
351 464 | let config = op.config().expect("the operation has config");
|
352 465 | let de = config
|
353 466 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
354 467 | .expect("the config must have a deserializer");
|
355 468 |
|
356 469 | let parsed = de.deserialize_streaming(&mut http_response);
|
357 470 | let parsed = parsed.unwrap_or_else(|| {
|
358 471 | let http_response = http_response.map(|body| {
|
359 472 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
360 473 | body.bytes().unwrap(),
|
361 474 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
362 475 | )))
|
363 476 | });
|
364 - | de.deserialize_nonstreaming(&http_response)
|
477 + | // Build a config bag with the protocol for schema-based deserialization
|
478 + | #[allow(unused_mut)]
|
479 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
480 + | {
|
481 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
482 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
483 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
484 + | ));
|
485 + | test_cfg.push_shared_layer(layer.freeze());
|
486 + | }
|
487 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
365 488 | });
|
366 489 | let parsed = parsed.expect_err("should be error response");
|
367 490 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
368 491 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
369 492 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::InvalidGreeting(parsed) = parsed {
|
370 493 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
371 494 | } else {
|
372 495 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
373 496 | }
|
374 497 | }
|
375 498 |
|
376 499 | /// Serializes a complex error with no message member
|
377 500 | /// Test ID: RestJsonComplexErrorWithNoMessage
|
378 501 | #[::tokio::test]
|
379 502 | #[::tracing_test::traced_test]
|
380 503 | async fn rest_json_complex_error_with_no_message_response() {
|
381 504 | let expected_output = crate::types::error::ComplexError::builder()
|
382 505 | .set_header(::std::option::Option::Some("Header".to_owned()))
|
383 506 | .set_top_level(::std::option::Option::Some("Top level".to_owned()))
|
384 507 | .set_nested(::std::option::Option::Some(
|
385 508 | crate::types::ComplexNestedErrorData::builder()
|
386 509 | .set_foo(::std::option::Option::Some("bar".to_owned()))
|
387 510 | .build(),
|
388 511 | ))
|
389 512 | .build();
|
390 513 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
391 514 | ::http_1x::response::Builder::new()
|
392 515 | .header("Content-Type", "application/json")
|
393 516 | .header("X-Amzn-Errortype", "ComplexError")
|
394 517 | .header("X-Header", "Header")
|
395 518 | .status(403)
|
396 519 | .body(::aws_smithy_types::body::SdkBody::from(
|
397 520 | "{\n \"TopLevel\": \"Top level\",\n \"Nested\": {\n \"Fooooo\": \"bar\"\n }\n}",
|
398 521 | ))
|
399 522 | .unwrap(),
|
400 523 | )
|
401 524 | .unwrap();
|
402 525 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
403 526 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
404 527 |
|
405 528 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
406 529 | let config = op.config().expect("the operation has config");
|
407 530 | let de = config
|
408 531 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
409 532 | .expect("the config must have a deserializer");
|
410 533 |
|
411 534 | let parsed = de.deserialize_streaming(&mut http_response);
|
412 535 | let parsed = parsed.unwrap_or_else(|| {
|
413 536 | let http_response = http_response.map(|body| {
|
414 537 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
415 538 | body.bytes().unwrap(),
|
416 539 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
417 540 | )))
|
418 541 | });
|
419 - | de.deserialize_nonstreaming(&http_response)
|
542 + | // Build a config bag with the protocol for schema-based deserialization
|
543 + | #[allow(unused_mut)]
|
544 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
545 + | {
|
546 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
547 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
548 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
549 + | ));
|
550 + | test_cfg.push_shared_layer(layer.freeze());
|
551 + | }
|
552 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
420 553 | });
|
421 554 | let parsed = parsed.expect_err("should be error response");
|
422 555 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
423 556 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
424 557 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError(parsed) = parsed {
|
425 558 | ::pretty_assertions::assert_eq!(parsed.header, expected_output.header, "Unexpected value for `header`");
|
426 559 | ::pretty_assertions::assert_eq!(parsed.top_level, expected_output.top_level, "Unexpected value for `top_level`");
|
427 560 | ::pretty_assertions::assert_eq!(parsed.nested, expected_output.nested, "Unexpected value for `nested`");
|
428 561 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
429 562 | } else {
|
430 563 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
431 564 | }
|
432 565 | }
|
433 566 | /// Test ID: RestJsonEmptyComplexErrorWithNoMessage
|
434 567 | #[::tokio::test]
|
435 568 | #[::tracing_test::traced_test]
|
436 569 | async fn rest_json_empty_complex_error_with_no_message_response() {
|
437 570 | let expected_output = crate::types::error::ComplexError::builder().build();
|
438 571 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
439 572 | ::http_1x::response::Builder::new()
|
440 573 | .header("Content-Type", "application/json")
|
441 574 | .header("X-Amzn-Errortype", "ComplexError")
|
442 575 | .status(403)
|
443 576 | .body(::aws_smithy_types::body::SdkBody::from("{}"))
|
444 577 | .unwrap(),
|
445 578 | )
|
446 579 | .unwrap();
|
447 580 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
448 581 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
449 582 |
|
450 583 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
451 584 | let config = op.config().expect("the operation has config");
|
452 585 | let de = config
|
453 586 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
454 587 | .expect("the config must have a deserializer");
|
455 588 |
|
456 589 | let parsed = de.deserialize_streaming(&mut http_response);
|
457 590 | let parsed = parsed.unwrap_or_else(|| {
|
458 591 | let http_response = http_response.map(|body| {
|
459 592 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
460 593 | body.bytes().unwrap(),
|
461 594 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
462 595 | )))
|
463 596 | });
|
464 - | de.deserialize_nonstreaming(&http_response)
|
597 + | // Build a config bag with the protocol for schema-based deserialization
|
598 + | #[allow(unused_mut)]
|
599 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
600 + | {
|
601 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
602 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
603 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
604 + | ));
|
605 + | test_cfg.push_shared_layer(layer.freeze());
|
606 + | }
|
607 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
465 608 | });
|
466 609 | let parsed = parsed.expect_err("should be error response");
|
467 610 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
468 611 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
469 612 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError(parsed) = parsed {
|
470 613 | ::pretty_assertions::assert_eq!(parsed.header, expected_output.header, "Unexpected value for `header`");
|
471 614 | ::pretty_assertions::assert_eq!(parsed.top_level, expected_output.top_level, "Unexpected value for `top_level`");
|
472 615 | ::pretty_assertions::assert_eq!(parsed.nested, expected_output.nested, "Unexpected value for `nested`");
|
473 616 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
474 617 | } else {
|
475 618 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
476 619 | }
|
477 620 | }
|
478 621 |
|
479 622 | /// Serializes the X-Amzn-ErrorType header. For an example service, see Amazon EKS.
|
480 623 | /// Test ID: RestJsonFooErrorUsingXAmznErrorType
|
481 624 | #[::tokio::test]
|
482 625 | #[::tracing_test::traced_test]
|
483 626 | async fn rest_json_foo_error_using_x_amzn_error_type_response() {
|
484 627 | let expected_output = crate::types::error::FooError::builder().build();
|
485 628 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
486 629 | ::http_1x::response::Builder::new()
|
487 630 | .header("X-Amzn-Errortype", "FooError")
|
488 631 | .status(500)
|
489 632 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
490 633 | .unwrap(),
|
491 634 | )
|
492 635 | .unwrap();
|
493 636 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
494 637 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
495 638 |
|
496 639 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
497 640 | let config = op.config().expect("the operation has config");
|
498 641 | let de = config
|
499 642 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
500 643 | .expect("the config must have a deserializer");
|
501 644 |
|
502 645 | let parsed = de.deserialize_streaming(&mut http_response);
|
503 646 | let parsed = parsed.unwrap_or_else(|| {
|
504 647 | let http_response = http_response.map(|body| {
|
505 648 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
506 649 | body.bytes().unwrap(),
|
507 650 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
508 651 | )))
|
509 652 | });
|
510 - | de.deserialize_nonstreaming(&http_response)
|
653 + | // Build a config bag with the protocol for schema-based deserialization
|
654 + | #[allow(unused_mut)]
|
655 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
656 + | {
|
657 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
658 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
659 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
660 + | ));
|
661 + | test_cfg.push_shared_layer(layer.freeze());
|
662 + | }
|
663 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
511 664 | });
|
512 665 | let parsed = parsed.expect_err("should be error response");
|
513 666 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
514 667 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
515 668 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
516 669 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
517 670 | } else {
|
518 671 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
519 672 | }
|
520 673 | }
|
521 674 |
|
522 675 | /// Some X-Amzn-Errortype headers contain URLs. Clients need to split the URL on ':' and take only the first half of the string. For example, 'ValidationException:http://internal.amazon.com/coral/com.amazon.coral.validate/'
|
523 676 | /// is to be interpreted as 'ValidationException'.
|
524 677 | ///
|
525 678 | /// For an example service see Amazon Polly.
|
526 679 | /// Test ID: RestJsonFooErrorUsingXAmznErrorTypeWithUri
|
527 680 | #[::tokio::test]
|
528 681 | #[::tracing_test::traced_test]
|
529 682 | async fn rest_json_foo_error_using_x_amzn_error_type_with_uri_response() {
|
530 683 | let expected_output = crate::types::error::FooError::builder().build();
|
531 684 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
532 685 | ::http_1x::response::Builder::new()
|
533 686 | .header("X-Amzn-Errortype", "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/")
|
534 687 | .status(500)
|
535 688 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
536 689 | .unwrap(),
|
537 690 | )
|
538 691 | .unwrap();
|
539 692 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
540 693 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
541 694 |
|
542 695 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
543 696 | let config = op.config().expect("the operation has config");
|
544 697 | let de = config
|
545 698 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
546 699 | .expect("the config must have a deserializer");
|
547 700 |
|
548 701 | let parsed = de.deserialize_streaming(&mut http_response);
|
549 702 | let parsed = parsed.unwrap_or_else(|| {
|
550 703 | let http_response = http_response.map(|body| {
|
551 704 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
552 705 | body.bytes().unwrap(),
|
553 706 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
554 707 | )))
|
555 708 | });
|
556 - | de.deserialize_nonstreaming(&http_response)
|
709 + | // Build a config bag with the protocol for schema-based deserialization
|
710 + | #[allow(unused_mut)]
|
711 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
712 + | {
|
713 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
714 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
715 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
716 + | ));
|
717 + | test_cfg.push_shared_layer(layer.freeze());
|
718 + | }
|
719 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
557 720 | });
|
558 721 | let parsed = parsed.expect_err("should be error response");
|
559 722 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
560 723 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
561 724 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
562 725 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
563 726 | } else {
|
564 727 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
565 728 | }
|
566 729 | }
|
567 730 |
|
568 731 | /// X-Amzn-Errortype might contain a URL and a namespace. Client should extract only the shape name. This is a pathalogical case that might not actually happen in any deployed AWS service.
|
569 732 | /// Test ID: RestJsonFooErrorUsingXAmznErrorTypeWithUriAndNamespace
|
570 733 | #[::tokio::test]
|
571 734 | #[::tracing_test::traced_test]
|
572 735 | async fn rest_json_foo_error_using_x_amzn_error_type_with_uri_and_namespace_response() {
|
573 736 | let expected_output = crate::types::error::FooError::builder().build();
|
574 737 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
575 738 | ::http_1x::response::Builder::new()
|
576 739 | .header(
|
577 740 | "X-Amzn-Errortype",
|
578 741 | "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
|
579 742 | )
|
580 743 | .status(500)
|
581 744 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
582 745 | .unwrap(),
|
583 746 | )
|
584 747 | .unwrap();
|
585 748 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
586 749 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
587 750 |
|
588 751 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
589 752 | let config = op.config().expect("the operation has config");
|
590 753 | let de = config
|
591 754 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
592 755 | .expect("the config must have a deserializer");
|
593 756 |
|
594 757 | let parsed = de.deserialize_streaming(&mut http_response);
|
595 758 | let parsed = parsed.unwrap_or_else(|| {
|
596 759 | let http_response = http_response.map(|body| {
|
597 760 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
598 761 | body.bytes().unwrap(),
|
599 762 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
600 763 | )))
|
601 764 | });
|
602 - | de.deserialize_nonstreaming(&http_response)
|
765 + | // Build a config bag with the protocol for schema-based deserialization
|
766 + | #[allow(unused_mut)]
|
767 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
768 + | {
|
769 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
770 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
771 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
772 + | ));
|
773 + | test_cfg.push_shared_layer(layer.freeze());
|
774 + | }
|
775 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
603 776 | });
|
604 777 | let parsed = parsed.expect_err("should be error response");
|
605 778 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
606 779 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
607 780 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
608 781 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
609 782 | } else {
|
610 783 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
611 784 | }
|
612 785 | }
|
613 786 |
|
614 787 | /// This example uses the 'code' property in the output rather than X-Amzn-Errortype. Some services do this though it's preferable to send the X-Amzn-Errortype. Client implementations must first check for the X-Amzn-Errortype and then check for a top-level 'code' property.
|
615 788 | ///
|
616 789 | /// For example service see Amazon S3 Glacier.
|
617 790 | /// Test ID: RestJsonFooErrorUsingCode
|
618 791 | #[::tokio::test]
|
619 792 | #[::tracing_test::traced_test]
|
620 793 | async fn rest_json_foo_error_using_code_response() {
|
621 794 | let expected_output = crate::types::error::FooError::builder().build();
|
622 795 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
623 796 | ::http_1x::response::Builder::new()
|
624 797 | .header("Content-Type", "application/json")
|
625 798 | .status(500)
|
626 799 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"code\": \"FooError\"\n}"))
|
627 800 | .unwrap(),
|
628 801 | )
|
629 802 | .unwrap();
|
630 803 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
631 804 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
632 805 |
|
633 806 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
634 807 | let config = op.config().expect("the operation has config");
|
635 808 | let de = config
|
636 809 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
637 810 | .expect("the config must have a deserializer");
|
638 811 |
|
639 812 | let parsed = de.deserialize_streaming(&mut http_response);
|
640 813 | let parsed = parsed.unwrap_or_else(|| {
|
641 814 | let http_response = http_response.map(|body| {
|
642 815 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
643 816 | body.bytes().unwrap(),
|
644 817 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
645 818 | )))
|
646 819 | });
|
647 - | de.deserialize_nonstreaming(&http_response)
|
820 + | // Build a config bag with the protocol for schema-based deserialization
|
821 + | #[allow(unused_mut)]
|
822 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
823 + | {
|
824 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
825 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
826 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
827 + | ));
|
828 + | test_cfg.push_shared_layer(layer.freeze());
|
829 + | }
|
830 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
648 831 | });
|
649 832 | let parsed = parsed.expect_err("should be error response");
|
650 833 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
651 834 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
652 835 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
653 836 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
654 837 | } else {
|
655 838 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
656 839 | }
|
657 840 | }
|
658 841 |
|
659 842 | /// Some services serialize errors using code, and it might contain a namespace. Clients should just take the last part of the string after '#'.
|
660 843 | /// Test ID: RestJsonFooErrorUsingCodeAndNamespace
|
661 844 | #[::tokio::test]
|
662 845 | #[::tracing_test::traced_test]
|
663 846 | async fn rest_json_foo_error_using_code_and_namespace_response() {
|
664 847 | let expected_output = crate::types::error::FooError::builder().build();
|
665 848 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
666 849 | ::http_1x::response::Builder::new()
|
667 850 | .header("Content-Type", "application/json")
|
668 851 | .status(500)
|
669 852 | .body(::aws_smithy_types::body::SdkBody::from(
|
670 853 | "{\n \"code\": \"aws.protocoltests.restjson#FooError\"\n}",
|
671 854 | ))
|
672 855 | .unwrap(),
|
673 856 | )
|
674 857 | .unwrap();
|
675 858 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
676 859 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
677 860 |
|
678 861 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
679 862 | let config = op.config().expect("the operation has config");
|
680 863 | let de = config
|
681 864 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
682 865 | .expect("the config must have a deserializer");
|
683 866 |
|
684 867 | let parsed = de.deserialize_streaming(&mut http_response);
|
685 868 | let parsed = parsed.unwrap_or_else(|| {
|
686 869 | let http_response = http_response.map(|body| {
|
687 870 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
688 871 | body.bytes().unwrap(),
|
689 872 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
690 873 | )))
|
691 874 | });
|
692 - | de.deserialize_nonstreaming(&http_response)
|
875 + | // Build a config bag with the protocol for schema-based deserialization
|
876 + | #[allow(unused_mut)]
|
877 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
878 + | {
|
879 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
880 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
881 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
882 + | ));
|
883 + | test_cfg.push_shared_layer(layer.freeze());
|
884 + | }
|
885 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
693 886 | });
|
694 887 | let parsed = parsed.expect_err("should be error response");
|
695 888 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
696 889 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
697 890 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
698 891 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
699 892 | } else {
|
700 893 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
701 894 | }
|
702 895 | }
|
703 896 |
|
704 897 | /// Some services serialize errors using code, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
|
705 898 | /// Test ID: RestJsonFooErrorUsingCodeUriAndNamespace
|
706 899 | #[::tokio::test]
|
707 900 | #[::tracing_test::traced_test]
|
708 901 | async fn rest_json_foo_error_using_code_uri_and_namespace_response() {
|
709 902 | let expected_output = crate::types::error::FooError::builder().build();
|
710 903 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
711 904 | ::http_1x::response::Builder::new()
|
712 905 | .header("Content-Type", "application/json")
|
713 906 | .status(500)
|
714 907 | .body(::aws_smithy_types::body::SdkBody::from(
|
715 908 | "{\n \"code\": \"aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/\"\n}",
|
716 909 | ))
|
717 910 | .unwrap(),
|
718 911 | )
|
719 912 | .unwrap();
|
720 913 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
721 914 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
722 915 |
|
723 916 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
724 917 | let config = op.config().expect("the operation has config");
|
725 918 | let de = config
|
726 919 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
727 920 | .expect("the config must have a deserializer");
|
728 921 |
|
729 922 | let parsed = de.deserialize_streaming(&mut http_response);
|
730 923 | let parsed = parsed.unwrap_or_else(|| {
|
731 924 | let http_response = http_response.map(|body| {
|
732 925 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
733 926 | body.bytes().unwrap(),
|
734 927 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
735 928 | )))
|
736 929 | });
|
737 - | de.deserialize_nonstreaming(&http_response)
|
930 + | // Build a config bag with the protocol for schema-based deserialization
|
931 + | #[allow(unused_mut)]
|
932 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
933 + | {
|
934 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
935 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
936 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
937 + | ));
|
938 + | test_cfg.push_shared_layer(layer.freeze());
|
939 + | }
|
940 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
738 941 | });
|
739 942 | let parsed = parsed.expect_err("should be error response");
|
740 943 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
741 944 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
742 945 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
743 946 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
744 947 | } else {
|
745 948 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
746 949 | }
|
747 950 | }
|
748 951 |
|
749 952 | /// Some services serialize errors using __type.
|
750 953 | /// Test ID: RestJsonFooErrorWithDunderType
|
751 954 | #[::tokio::test]
|
752 955 | #[::tracing_test::traced_test]
|
753 956 | async fn rest_json_foo_error_with_dunder_type_response() {
|
754 957 | let expected_output = crate::types::error::FooError::builder().build();
|
755 958 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
756 959 | ::http_1x::response::Builder::new()
|
757 960 | .header("Content-Type", "application/json")
|
758 961 | .status(500)
|
759 962 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"__type\": \"FooError\"\n}"))
|
760 963 | .unwrap(),
|
761 964 | )
|
762 965 | .unwrap();
|
763 966 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
764 967 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
765 968 |
|
766 969 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
767 970 | let config = op.config().expect("the operation has config");
|
768 971 | let de = config
|
769 972 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
770 973 | .expect("the config must have a deserializer");
|
771 974 |
|
772 975 | let parsed = de.deserialize_streaming(&mut http_response);
|
773 976 | let parsed = parsed.unwrap_or_else(|| {
|
774 977 | let http_response = http_response.map(|body| {
|
775 978 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
776 979 | body.bytes().unwrap(),
|
777 980 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
778 981 | )))
|
779 982 | });
|
780 - | de.deserialize_nonstreaming(&http_response)
|
983 + | // Build a config bag with the protocol for schema-based deserialization
|
984 + | #[allow(unused_mut)]
|
985 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
986 + | {
|
987 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
988 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
989 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
990 + | ));
|
991 + | test_cfg.push_shared_layer(layer.freeze());
|
992 + | }
|
993 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
781 994 | });
|
782 995 | let parsed = parsed.expect_err("should be error response");
|
783 996 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
784 997 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
785 998 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
786 999 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
787 1000 | } else {
|
788 1001 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
789 1002 | }
|
790 1003 | }
|
791 1004 |
|
792 1005 | /// Some services serialize errors using __type, and it might contain a namespace. Clients should just take the last part of the string after '#'.
|
793 1006 | /// Test ID: RestJsonFooErrorWithDunderTypeAndNamespace
|
794 1007 | #[::tokio::test]
|
795 1008 | #[::tracing_test::traced_test]
|
796 1009 | async fn rest_json_foo_error_with_dunder_type_and_namespace_response() {
|
797 1010 | let expected_output = crate::types::error::FooError::builder().build();
|
798 1011 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
799 1012 | ::http_1x::response::Builder::new()
|
800 1013 | .header("Content-Type", "application/json")
|
801 1014 | .status(500)
|
802 1015 | .body(::aws_smithy_types::body::SdkBody::from(
|
803 1016 | "{\n \"__type\": \"aws.protocoltests.restjson#FooError\"\n}",
|
804 1017 | ))
|
805 1018 | .unwrap(),
|
806 1019 | )
|
807 1020 | .unwrap();
|
808 1021 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
809 1022 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
810 1023 |
|
811 1024 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
812 1025 | let config = op.config().expect("the operation has config");
|
813 1026 | let de = config
|
814 1027 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
815 1028 | .expect("the config must have a deserializer");
|
816 1029 |
|
817 1030 | let parsed = de.deserialize_streaming(&mut http_response);
|
818 1031 | let parsed = parsed.unwrap_or_else(|| {
|
819 1032 | let http_response = http_response.map(|body| {
|
820 1033 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
821 1034 | body.bytes().unwrap(),
|
822 1035 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
823 1036 | )))
|
824 1037 | });
|
825 - | de.deserialize_nonstreaming(&http_response)
|
1038 + | // Build a config bag with the protocol for schema-based deserialization
|
1039 + | #[allow(unused_mut)]
|
1040 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
1041 + | {
|
1042 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
1043 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
1044 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
1045 + | ));
|
1046 + | test_cfg.push_shared_layer(layer.freeze());
|
1047 + | }
|
1048 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
826 1049 | });
|
827 1050 | let parsed = parsed.expect_err("should be error response");
|
828 1051 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
829 1052 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
830 1053 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
831 1054 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
832 1055 | } else {
|
833 1056 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
834 1057 | }
|
835 1058 | }
|
836 1059 |
|
837 1060 | /// Some services serialize errors using __type, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
|
838 1061 | /// Test ID: RestJsonFooErrorWithDunderTypeUriAndNamespace
|
839 1062 | #[::tokio::test]
|
840 1063 | #[::tracing_test::traced_test]
|
841 1064 | async fn rest_json_foo_error_with_dunder_type_uri_and_namespace_response() {
|
842 1065 | let expected_output = crate::types::error::FooError::builder().build();
|
843 1066 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
844 1067 | ::http_1x::response::Builder::new()
|
845 1068 | .header("Content-Type", "application/json")
|
846 1069 | .status(500)
|
847 1070 | .body(::aws_smithy_types::body::SdkBody::from(
|
848 1071 | "{\n \"__type\": \"aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/\"\n}",
|
849 1072 | ))
|
850 1073 | .unwrap(),
|
851 1074 | )
|
852 1075 | .unwrap();
|
853 1076 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
854 1077 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
855 1078 |
|
856 1079 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
857 1080 | let config = op.config().expect("the operation has config");
|
858 1081 | let de = config
|
859 1082 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
860 1083 | .expect("the config must have a deserializer");
|
861 1084 |
|
862 1085 | let parsed = de.deserialize_streaming(&mut http_response);
|
863 1086 | let parsed = parsed.unwrap_or_else(|| {
|
864 1087 | let http_response = http_response.map(|body| {
|
865 1088 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
866 1089 | body.bytes().unwrap(),
|
867 1090 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
868 1091 | )))
|
869 1092 | });
|
870 - | de.deserialize_nonstreaming(&http_response)
|
1093 + | // Build a config bag with the protocol for schema-based deserialization
|
1094 + | #[allow(unused_mut)]
|
1095 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
1096 + | {
|
1097 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
1098 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
1099 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
1100 + | ));
|
1101 + | test_cfg.push_shared_layer(layer.freeze());
|
1102 + | }
|
1103 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
871 1104 | });
|
872 1105 | let parsed = parsed.expect_err("should be error response");
|
873 1106 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
874 1107 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
875 1108 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
876 1109 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
877 1110 | } else {
|
878 1111 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
879 1112 | }
|
880 1113 | }
|
881 1114 |
|
882 1115 | /// Some services serialize errors using __type, and if the response includes additional shapes that belong to a different namespace there'll be a nested __type property that must not be considered when determining which error to be surfaced.
|
883 1116 | ///
|
884 1117 | /// For an example service see Amazon DynamoDB.
|
885 1118 | /// Test ID: RestJsonFooErrorWithNestedTypeProperty
|
886 1119 | #[::tokio::test]
|
887 1120 | #[::tracing_test::traced_test]
|
888 1121 | async fn rest_json_foo_error_with_nested_type_property_response() {
|
889 1122 | let expected_output = crate::types::error::FooError::builder().build();
|
890 1123 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(::http_1x::response::Builder::new()
|
891 1124 | .header("Content-Type", "application/json")
|
892 1125 | .status(500)
|
893 1126 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"__type\": \"aws.protocoltests.restjson#FooError\",\n \"ErrorDetails\": [\n {\n \"__type\": \"com.amazon.internal#ErrorDetails\",\n \"reason\": \"Some reason\"\n }\n ]\n}"))
|
894 1127 | .unwrap()
|
895 1128 | ).unwrap();
|
896 1129 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
897 1130 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
898 1131 |
|
899 1132 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
900 1133 | let config = op.config().expect("the operation has config");
|
901 1134 | let de = config
|
902 1135 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
903 1136 | .expect("the config must have a deserializer");
|
904 1137 |
|
905 1138 | let parsed = de.deserialize_streaming(&mut http_response);
|
906 1139 | let parsed = parsed.unwrap_or_else(|| {
|
907 1140 | let http_response = http_response.map(|body| {
|
908 1141 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
909 1142 | body.bytes().unwrap(),
|
910 1143 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
911 1144 | )))
|
912 1145 | });
|
913 - | de.deserialize_nonstreaming(&http_response)
|
1146 + | // Build a config bag with the protocol for schema-based deserialization
|
1147 + | #[allow(unused_mut)]
|
1148 + | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
1149 + | {
|
1150 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
1151 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
1152 + | ::aws_smithy_json::protocol::aws_rest_json_1::AwsRestJsonProtocol::new(),
|
1153 + | ));
|
1154 + | test_cfg.push_shared_layer(layer.freeze());
|
1155 + | }
|
1156 + | de.deserialize_nonstreaming(&http_response, &test_cfg)
|
914 1157 | });
|
915 1158 | let parsed = parsed.expect_err("should be error response");
|
916 1159 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
917 1160 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
918 1161 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
919 1162 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
920 1163 | } else {
|
921 1164 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
922 1165 | }
|
923 1166 | }
|