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 + | }
|
165 + | };
|
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),
|
148 239 | };
|
149 - | crate::protocol_serde::type_erase_result(parse_result)
|
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.1");
|
189 - | builder = _header_serialization_settings.set_default_header(
|
190 - | builder,
|
191 - | ::http_1x::header::HeaderName::from_static("x-amz-target"),
|
192 - | "JsonProtocol.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)?);
|
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)?;
|
198 284 |
|
199 - | ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
|
285 + | return ::std::result::Result::Ok(request);
|
200 286 | }
|
201 287 | }
|
202 288 | #[derive(Debug)]
|
203 289 | struct GreetingWithErrorsEndpointParamsInterceptor;
|
204 290 |
|
205 291 | impl ::aws_smithy_runtime_api::client::interceptors::Intercept for GreetingWithErrorsEndpointParamsInterceptor {
|
206 292 | fn name(&self) -> &'static str {
|
207 293 | "GreetingWithErrorsEndpointParamsInterceptor"
|
208 294 | }
|
209 295 |
|
266 352 | .expect("the config must have a deserializer");
|
267 353 |
|
268 354 | let parsed = de.deserialize_streaming(&mut http_response);
|
269 355 | let parsed = parsed.unwrap_or_else(|| {
|
270 356 | let http_response = http_response.map(|body| {
|
271 357 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
272 358 | body.bytes().unwrap(),
|
273 359 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
274 360 | )))
|
275 361 | });
|
276 - | 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_1("JsonProtocol"),
|
369 + | ));
|
370 + | test_cfg.push_shared_layer(layer.freeze());
|
371 + | }
|
372 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
277 373 | });
|
278 374 | let parsed = parsed.expect_err("should be error response");
|
279 375 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
280 376 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
281 377 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::InvalidGreeting(parsed) = parsed {
|
282 378 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
283 379 | } else {
|
284 380 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
285 381 | }
|
286 382 | }
|
287 383 |
|
288 384 | /// Parses a complex error with no message member
|
289 385 | /// Test ID: AwsJson11ComplexError
|
290 386 | #[::tokio::test]
|
291 387 | #[::tracing_test::traced_test]
|
292 388 | async fn aws_json11_complex_error_response() {
|
293 389 | let expected_output = crate::types::error::ComplexError::builder()
|
294 390 | .set_top_level(::std::option::Option::Some("Top level".to_owned()))
|
295 391 | .set_nested(::std::option::Option::Some(
|
296 392 | crate::types::ComplexNestedErrorData::builder()
|
297 393 | .set_foo(::std::option::Option::Some("bar".to_owned()))
|
298 394 | .build(),
|
299 395 | ))
|
300 396 | .build();
|
301 397 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
302 398 | ::http_1x::response::Builder::new()
|
303 399 | .header("Content-Type", "application/x-amz-json-1.1")
|
304 400 | .status(400)
|
305 401 | .body(::aws_smithy_types::body::SdkBody::from(
|
306 402 | "{\n \"__type\": \"ComplexError\",\n \"TopLevel\": \"Top level\",\n \"Nested\": {\n \"Foo\": \"bar\"\n }\n}",
|
307 403 | ))
|
308 404 | .unwrap(),
|
309 405 | )
|
310 406 | .unwrap();
|
311 407 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
312 408 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
313 409 |
|
314 410 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
315 411 | let config = op.config().expect("the operation has config");
|
316 412 | let de = config
|
317 413 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
318 414 | .expect("the config must have a deserializer");
|
319 415 |
|
320 416 | let parsed = de.deserialize_streaming(&mut http_response);
|
321 417 | let parsed = parsed.unwrap_or_else(|| {
|
322 418 | let http_response = http_response.map(|body| {
|
323 419 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
324 420 | body.bytes().unwrap(),
|
325 421 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
326 422 | )))
|
327 423 | });
|
328 - | 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_json_rpc::AwsJsonRpcProtocol::aws_json_1_1("JsonProtocol"),
|
431 + | ));
|
432 + | test_cfg.push_shared_layer(layer.freeze());
|
433 + | }
|
434 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
329 435 | });
|
330 436 | let parsed = parsed.expect_err("should be error response");
|
331 437 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
332 438 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
333 439 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError(parsed) = parsed {
|
334 440 | ::pretty_assertions::assert_eq!(parsed.top_level, expected_output.top_level, "Unexpected value for `top_level`");
|
335 441 | ::pretty_assertions::assert_eq!(parsed.nested, expected_output.nested, "Unexpected value for `nested`");
|
336 442 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
337 443 | } else {
|
338 444 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
339 445 | }
|
340 446 | }
|
341 447 | /// Test ID: AwsJson11EmptyComplexError
|
342 448 | #[::tokio::test]
|
343 449 | #[::tracing_test::traced_test]
|
344 450 | async fn aws_json11_empty_complex_error_response() {
|
345 451 | let expected_output = crate::types::error::ComplexError::builder().build();
|
346 452 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
347 453 | ::http_1x::response::Builder::new()
|
348 454 | .header("Content-Type", "application/x-amz-json-1.1")
|
349 455 | .status(400)
|
350 456 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"__type\": \"ComplexError\"\n}"))
|
351 457 | .unwrap(),
|
352 458 | )
|
353 459 | .unwrap();
|
354 460 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
355 461 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
356 462 |
|
357 463 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
358 464 | let config = op.config().expect("the operation has config");
|
359 465 | let de = config
|
360 466 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
361 467 | .expect("the config must have a deserializer");
|
362 468 |
|
363 469 | let parsed = de.deserialize_streaming(&mut http_response);
|
364 470 | let parsed = parsed.unwrap_or_else(|| {
|
365 471 | let http_response = http_response.map(|body| {
|
366 472 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
367 473 | body.bytes().unwrap(),
|
368 474 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
369 475 | )))
|
370 476 | });
|
371 - | 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_1("JsonProtocol"),
|
484 + | ));
|
485 + | test_cfg.push_shared_layer(layer.freeze());
|
486 + | }
|
487 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
372 488 | });
|
373 489 | let parsed = parsed.expect_err("should be error response");
|
374 490 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
375 491 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
376 492 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError(parsed) = parsed {
|
377 493 | ::pretty_assertions::assert_eq!(parsed.top_level, expected_output.top_level, "Unexpected value for `top_level`");
|
378 494 | ::pretty_assertions::assert_eq!(parsed.nested, expected_output.nested, "Unexpected value for `nested`");
|
379 495 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
380 496 | } else {
|
381 497 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
382 498 | }
|
383 499 | }
|
384 500 |
|
385 501 | /// Serializes the X-Amzn-ErrorType header. For an example service, see Amazon EKS.
|
386 502 | /// Test ID: AwsJson11FooErrorUsingXAmznErrorType
|
387 503 | #[::tokio::test]
|
388 504 | #[::tracing_test::traced_test]
|
389 505 | async fn aws_json11_foo_error_using_x_amzn_error_type_response() {
|
390 506 | let expected_output = crate::types::error::FooError::builder().build();
|
391 507 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
392 508 | ::http_1x::response::Builder::new()
|
393 509 | .header("X-Amzn-Errortype", "FooError")
|
394 510 | .status(500)
|
395 511 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
396 512 | .unwrap(),
|
397 513 | )
|
398 514 | .unwrap();
|
399 515 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
400 516 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
401 517 |
|
402 518 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
403 519 | let config = op.config().expect("the operation has config");
|
404 520 | let de = config
|
405 521 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
406 522 | .expect("the config must have a deserializer");
|
407 523 |
|
408 524 | let parsed = de.deserialize_streaming(&mut http_response);
|
409 525 | let parsed = parsed.unwrap_or_else(|| {
|
410 526 | let http_response = http_response.map(|body| {
|
411 527 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
412 528 | body.bytes().unwrap(),
|
413 529 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
414 530 | )))
|
415 531 | });
|
416 - | 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_1("JsonProtocol"),
|
539 + | ));
|
540 + | test_cfg.push_shared_layer(layer.freeze());
|
541 + | }
|
542 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
417 543 | });
|
418 544 | let parsed = parsed.expect_err("should be error response");
|
419 545 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
420 546 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
421 547 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
422 548 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
423 549 | } else {
|
424 550 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
425 551 | }
|
426 552 | }
|
427 553 |
|
428 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/'
|
429 555 | /// is to be interpreted as 'ValidationException'.
|
430 556 | ///
|
431 557 | /// For an example service see Amazon Polly.
|
432 558 | /// Test ID: AwsJson11FooErrorUsingXAmznErrorTypeWithUri
|
433 559 | #[::tokio::test]
|
434 560 | #[::tracing_test::traced_test]
|
435 561 | async fn aws_json11_foo_error_using_x_amzn_error_type_with_uri_response() {
|
436 562 | let expected_output = crate::types::error::FooError::builder().build();
|
437 563 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
438 564 | ::http_1x::response::Builder::new()
|
439 565 | .header("X-Amzn-Errortype", "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/")
|
440 566 | .status(500)
|
441 567 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
442 568 | .unwrap(),
|
443 569 | )
|
444 570 | .unwrap();
|
445 571 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
446 572 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
447 573 |
|
448 574 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
449 575 | let config = op.config().expect("the operation has config");
|
450 576 | let de = config
|
451 577 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
452 578 | .expect("the config must have a deserializer");
|
453 579 |
|
454 580 | let parsed = de.deserialize_streaming(&mut http_response);
|
455 581 | let parsed = parsed.unwrap_or_else(|| {
|
456 582 | let http_response = http_response.map(|body| {
|
457 583 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
458 584 | body.bytes().unwrap(),
|
459 585 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
460 586 | )))
|
461 587 | });
|
462 - | 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_1("JsonProtocol"),
|
595 + | ));
|
596 + | test_cfg.push_shared_layer(layer.freeze());
|
597 + | }
|
598 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
463 599 | });
|
464 600 | let parsed = parsed.expect_err("should be error response");
|
465 601 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
466 602 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
467 603 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
468 604 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
469 605 | } else {
|
470 606 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
471 607 | }
|
472 608 | }
|
473 609 |
|
474 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.
|
475 611 | /// Test ID: AwsJson11FooErrorUsingXAmznErrorTypeWithUriAndNamespace
|
476 612 | #[::tokio::test]
|
477 613 | #[::tracing_test::traced_test]
|
478 614 | async fn aws_json11_foo_error_using_x_amzn_error_type_with_uri_and_namespace_response() {
|
479 615 | let expected_output = crate::types::error::FooError::builder().build();
|
480 616 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
481 617 | ::http_1x::response::Builder::new()
|
482 618 | .header(
|
483 619 | "X-Amzn-Errortype",
|
484 620 | "aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
|
485 621 | )
|
486 622 | .status(500)
|
487 623 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
488 624 | .unwrap(),
|
489 625 | )
|
490 626 | .unwrap();
|
491 627 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
492 628 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
493 629 |
|
494 630 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
495 631 | let config = op.config().expect("the operation has config");
|
496 632 | let de = config
|
497 633 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
498 634 | .expect("the config must have a deserializer");
|
499 635 |
|
500 636 | let parsed = de.deserialize_streaming(&mut http_response);
|
501 637 | let parsed = parsed.unwrap_or_else(|| {
|
502 638 | let http_response = http_response.map(|body| {
|
503 639 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
504 640 | body.bytes().unwrap(),
|
505 641 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
506 642 | )))
|
507 643 | });
|
508 - | 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_1("JsonProtocol"),
|
651 + | ));
|
652 + | test_cfg.push_shared_layer(layer.freeze());
|
653 + | }
|
654 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
509 655 | });
|
510 656 | let parsed = parsed.expect_err("should be error response");
|
511 657 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
512 658 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
513 659 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
514 660 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
515 661 | } else {
|
516 662 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
517 663 | }
|
518 664 | }
|
519 665 |
|
520 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.
|
521 667 | ///
|
522 668 | /// For example service see Amazon S3 Glacier.
|
523 669 | /// Test ID: AwsJson11FooErrorUsingCode
|
524 670 | #[::tokio::test]
|
525 671 | #[::tracing_test::traced_test]
|
526 672 | async fn aws_json11_foo_error_using_code_response() {
|
527 673 | let expected_output = crate::types::error::FooError::builder().build();
|
528 674 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
529 675 | ::http_1x::response::Builder::new()
|
530 676 | .header("Content-Type", "application/x-amz-json-1.1")
|
531 677 | .status(500)
|
532 678 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"code\": \"FooError\"\n}"))
|
533 679 | .unwrap(),
|
534 680 | )
|
535 681 | .unwrap();
|
536 682 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
537 683 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
538 684 |
|
539 685 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
540 686 | let config = op.config().expect("the operation has config");
|
541 687 | let de = config
|
542 688 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
543 689 | .expect("the config must have a deserializer");
|
544 690 |
|
545 691 | let parsed = de.deserialize_streaming(&mut http_response);
|
546 692 | let parsed = parsed.unwrap_or_else(|| {
|
547 693 | let http_response = http_response.map(|body| {
|
548 694 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
549 695 | body.bytes().unwrap(),
|
550 696 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
551 697 | )))
|
552 698 | });
|
553 - | 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_1("JsonProtocol"),
|
706 + | ));
|
707 + | test_cfg.push_shared_layer(layer.freeze());
|
708 + | }
|
709 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
554 710 | });
|
555 711 | let parsed = parsed.expect_err("should be error response");
|
556 712 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
557 713 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
558 714 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
559 715 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
560 716 | } else {
|
561 717 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
562 718 | }
|
563 719 | }
|
564 720 |
|
565 721 | /// Some services serialize errors using code, and it might contain a namespace. Clients should just take the last part of the string after '#'.
|
566 722 | /// Test ID: AwsJson11FooErrorUsingCodeAndNamespace
|
567 723 | #[::tokio::test]
|
568 724 | #[::tracing_test::traced_test]
|
569 725 | async fn aws_json11_foo_error_using_code_and_namespace_response() {
|
570 726 | let expected_output = crate::types::error::FooError::builder().build();
|
571 727 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
572 728 | ::http_1x::response::Builder::new()
|
573 729 | .header("Content-Type", "application/x-amz-json-1.1")
|
574 730 | .status(500)
|
575 731 | .body(::aws_smithy_types::body::SdkBody::from(
|
576 732 | "{\n \"code\": \"aws.protocoltests.restjson#FooError\"\n}",
|
577 733 | ))
|
578 734 | .unwrap(),
|
579 735 | )
|
580 736 | .unwrap();
|
581 737 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
582 738 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
583 739 |
|
584 740 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
585 741 | let config = op.config().expect("the operation has config");
|
586 742 | let de = config
|
587 743 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
588 744 | .expect("the config must have a deserializer");
|
589 745 |
|
590 746 | let parsed = de.deserialize_streaming(&mut http_response);
|
591 747 | let parsed = parsed.unwrap_or_else(|| {
|
592 748 | let http_response = http_response.map(|body| {
|
593 749 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
594 750 | body.bytes().unwrap(),
|
595 751 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
596 752 | )))
|
597 753 | });
|
598 - | 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_1("JsonProtocol"),
|
761 + | ));
|
762 + | test_cfg.push_shared_layer(layer.freeze());
|
763 + | }
|
764 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
599 765 | });
|
600 766 | let parsed = parsed.expect_err("should be error response");
|
601 767 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
602 768 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
603 769 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
604 770 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
605 771 | } else {
|
606 772 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
607 773 | }
|
608 774 | }
|
609 775 |
|
610 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.
|
611 777 | /// Test ID: AwsJson11FooErrorUsingCodeUriAndNamespace
|
612 778 | #[::tokio::test]
|
613 779 | #[::tracing_test::traced_test]
|
614 780 | async fn aws_json11_foo_error_using_code_uri_and_namespace_response() {
|
615 781 | let expected_output = crate::types::error::FooError::builder().build();
|
616 782 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
617 783 | ::http_1x::response::Builder::new()
|
618 784 | .header("Content-Type", "application/x-amz-json-1.1")
|
619 785 | .status(500)
|
620 786 | .body(::aws_smithy_types::body::SdkBody::from(
|
621 787 | "{\n \"code\": \"aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/\"\n}",
|
622 788 | ))
|
623 789 | .unwrap(),
|
624 790 | )
|
625 791 | .unwrap();
|
626 792 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
627 793 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
628 794 |
|
629 795 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
630 796 | let config = op.config().expect("the operation has config");
|
631 797 | let de = config
|
632 798 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
633 799 | .expect("the config must have a deserializer");
|
634 800 |
|
635 801 | let parsed = de.deserialize_streaming(&mut http_response);
|
636 802 | let parsed = parsed.unwrap_or_else(|| {
|
637 803 | let http_response = http_response.map(|body| {
|
638 804 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
639 805 | body.bytes().unwrap(),
|
640 806 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
641 807 | )))
|
642 808 | });
|
643 - | 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_1("JsonProtocol"),
|
816 + | ));
|
817 + | test_cfg.push_shared_layer(layer.freeze());
|
818 + | }
|
819 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
644 820 | });
|
645 821 | let parsed = parsed.expect_err("should be error response");
|
646 822 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
647 823 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
648 824 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
649 825 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
650 826 | } else {
|
651 827 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
652 828 | }
|
653 829 | }
|
654 830 |
|
655 831 | /// Some services serialize errors using __type.
|
656 832 | /// Test ID: AwsJson11FooErrorWithDunderType
|
657 833 | #[::tokio::test]
|
658 834 | #[::tracing_test::traced_test]
|
659 835 | async fn aws_json11_foo_error_with_dunder_type_response() {
|
660 836 | let expected_output = crate::types::error::FooError::builder().build();
|
661 837 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
662 838 | ::http_1x::response::Builder::new()
|
663 839 | .header("Content-Type", "application/x-amz-json-1.1")
|
664 840 | .status(500)
|
665 841 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"__type\": \"FooError\"\n}"))
|
666 842 | .unwrap(),
|
667 843 | )
|
668 844 | .unwrap();
|
669 845 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
670 846 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
671 847 |
|
672 848 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
673 849 | let config = op.config().expect("the operation has config");
|
674 850 | let de = config
|
675 851 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
676 852 | .expect("the config must have a deserializer");
|
677 853 |
|
678 854 | let parsed = de.deserialize_streaming(&mut http_response);
|
679 855 | let parsed = parsed.unwrap_or_else(|| {
|
680 856 | let http_response = http_response.map(|body| {
|
681 857 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
682 858 | body.bytes().unwrap(),
|
683 859 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
684 860 | )))
|
685 861 | });
|
686 - | 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_1("JsonProtocol"),
|
869 + | ));
|
870 + | test_cfg.push_shared_layer(layer.freeze());
|
871 + | }
|
872 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
687 873 | });
|
688 874 | let parsed = parsed.expect_err("should be error response");
|
689 875 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
690 876 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
691 877 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
692 878 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
693 879 | } else {
|
694 880 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
695 881 | }
|
696 882 | }
|
697 883 |
|
698 884 | /// Some services serialize errors using __type, and it might contain a namespace. Clients should just take the last part of the string after '#'.
|
699 885 | /// Test ID: AwsJson11FooErrorWithDunderTypeAndNamespace
|
700 886 | #[::tokio::test]
|
701 887 | #[::tracing_test::traced_test]
|
702 888 | async fn aws_json11_foo_error_with_dunder_type_and_namespace_response() {
|
703 889 | let expected_output = crate::types::error::FooError::builder().build();
|
704 890 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
705 891 | ::http_1x::response::Builder::new()
|
706 892 | .header("Content-Type", "application/x-amz-json-1.1")
|
707 893 | .status(500)
|
708 894 | .body(::aws_smithy_types::body::SdkBody::from(
|
709 895 | "{\n \"__type\": \"aws.protocoltests.restjson#FooError\"\n}",
|
710 896 | ))
|
711 897 | .unwrap(),
|
712 898 | )
|
713 899 | .unwrap();
|
714 900 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
715 901 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
716 902 |
|
717 903 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
718 904 | let config = op.config().expect("the operation has config");
|
719 905 | let de = config
|
720 906 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
721 907 | .expect("the config must have a deserializer");
|
722 908 |
|
723 909 | let parsed = de.deserialize_streaming(&mut http_response);
|
724 910 | let parsed = parsed.unwrap_or_else(|| {
|
725 911 | let http_response = http_response.map(|body| {
|
726 912 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
727 913 | body.bytes().unwrap(),
|
728 914 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
729 915 | )))
|
730 916 | });
|
731 - | 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_1("JsonProtocol"),
|
924 + | ));
|
925 + | test_cfg.push_shared_layer(layer.freeze());
|
926 + | }
|
927 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
732 928 | });
|
733 929 | let parsed = parsed.expect_err("should be error response");
|
734 930 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
735 931 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
736 932 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
737 933 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
738 934 | } else {
|
739 935 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
740 936 | }
|
741 937 | }
|
742 938 |
|
743 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.
|
744 940 | /// Test ID: AwsJson11FooErrorWithDunderTypeUriAndNamespace
|
745 941 | #[::tokio::test]
|
746 942 | #[::tracing_test::traced_test]
|
747 943 | async fn aws_json11_foo_error_with_dunder_type_uri_and_namespace_response() {
|
748 944 | let expected_output = crate::types::error::FooError::builder().build();
|
749 945 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
750 946 | ::http_1x::response::Builder::new()
|
751 947 | .header("Content-Type", "application/x-amz-json-1.1")
|
752 948 | .status(500)
|
753 949 | .body(::aws_smithy_types::body::SdkBody::from(
|
754 950 | "{\n \"__type\": \"aws.protocoltests.restjson#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/\"\n}",
|
755 951 | ))
|
756 952 | .unwrap(),
|
757 953 | )
|
758 954 | .unwrap();
|
759 955 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
760 956 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
761 957 |
|
762 958 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
763 959 | let config = op.config().expect("the operation has config");
|
764 960 | let de = config
|
765 961 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
766 962 | .expect("the config must have a deserializer");
|
767 963 |
|
768 964 | let parsed = de.deserialize_streaming(&mut http_response);
|
769 965 | let parsed = parsed.unwrap_or_else(|| {
|
770 966 | let http_response = http_response.map(|body| {
|
771 967 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
772 968 | body.bytes().unwrap(),
|
773 969 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
774 970 | )))
|
775 971 | });
|
776 - | 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_1("JsonProtocol"),
|
979 + | ));
|
980 + | test_cfg.push_shared_layer(layer.freeze());
|
981 + | }
|
982 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
777 983 | });
|
778 984 | let parsed = parsed.expect_err("should be error response");
|
779 985 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
780 986 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
781 987 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
782 988 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
783 989 | } else {
|
784 990 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
785 991 | }
|
786 992 | }
|
787 993 |
|
788 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.
|
789 995 | ///
|
790 996 | /// For an example service see Amazon DynamoDB.
|
791 997 | /// Test ID: AwsJson11FooErrorWithNestedTypeProperty
|
792 998 | #[::tokio::test]
|
793 999 | #[::tracing_test::traced_test]
|
794 1000 | async fn aws_json11_foo_error_with_nested_type_property_response() {
|
795 1001 | let expected_output = crate::types::error::FooError::builder().build();
|
796 1002 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(::http_1x::response::Builder::new()
|
797 1003 | .header("Content-Type", "application/x-amz-json-1.1")
|
798 1004 | .status(500)
|
799 1005 | .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}"))
|
800 1006 | .unwrap()
|
801 1007 | ).unwrap();
|
802 1008 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
803 1009 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
804 1010 |
|
805 1011 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
806 1012 | let config = op.config().expect("the operation has config");
|
807 1013 | let de = config
|
808 1014 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
809 1015 | .expect("the config must have a deserializer");
|
810 1016 |
|
811 1017 | let parsed = de.deserialize_streaming(&mut http_response);
|
812 1018 | let parsed = parsed.unwrap_or_else(|| {
|
813 1019 | let http_response = http_response.map(|body| {
|
814 1020 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
815 1021 | body.bytes().unwrap(),
|
816 1022 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
817 1023 | )))
|
818 1024 | });
|
819 - | 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_1("JsonProtocol"),
|
1032 + | ));
|
1033 + | test_cfg.push_shared_layer(layer.freeze());
|
1034 + | }
|
1035 + | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
820 1036 | });
|
821 1037 | let parsed = parsed.expect_err("should be error response");
|
822 1038 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
823 1039 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
824 1040 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
825 1041 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
826 1042 | } else {
|
827 1043 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
828 1044 | }
|
829 1045 | }
|