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