Server Test

Server Test

rev. 03e6e47f15dfd569240d570d98975ebba692c405

Files changed:

tmp-codegen-diff/codegen-server-test/rest_json_validation-http0x/rust-server-codegen/src/protocol_serde/shape_malformed_range.rs

@@ -0,1 +0,272 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
#[allow(clippy::unnecessary_wraps)]
           3  +
pub async fn de_malformed_range_http_request<B>(
           4  +
    #[allow(unused_variables)] request: ::http::Request<B>,
           5  +
) -> std::result::Result<
           6  +
    crate::input::MalformedRangeInput,
           7  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection,
           8  +
>
           9  +
where
          10  +
    B: ::aws_smithy_legacy_http_server::body::HttpBody + Send,
          11  +
    B::Data: Send,
          12  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection:
          13  +
        From<<B as ::aws_smithy_legacy_http_server::body::HttpBody>::Error>,
          14  +
{
          15  +
    Ok({
          16  +
        #[allow(unused_mut)]
          17  +
        let mut input = crate::input::malformed_range_input::Builder::default();
          18  +
        #[allow(unused_variables)]
          19  +
        let ::aws_smithy_runtime_api::http::RequestParts {
          20  +
            uri, headers, body, ..
          21  +
        } = ::aws_smithy_runtime_api::http::Request::try_from(request)?.into_parts();
          22  +
        let bytes = ::hyper::body::to_bytes(body).await?;
          23  +
        if !bytes.is_empty() {
          24  +
            ::aws_smithy_legacy_http_server::protocol::content_type_header_classifier_smithy(
          25  +
                &headers,
          26  +
                Some("application/json"),
          27  +
            )?;
          28  +
            input = crate::protocol_serde::shape_malformed_range::de_malformed_range(
          29  +
                bytes.as_ref(),
          30  +
                input,
          31  +
            )?;
          32  +
        }
          33  +
        input.build()?
          34  +
    })
          35  +
}
          36  +
          37  +
#[allow(clippy::unnecessary_wraps)]
          38  +
pub fn ser_malformed_range_http_response(
          39  +
    #[allow(unused_variables)] output: crate::output::MalformedRangeOutput,
          40  +
) -> std::result::Result<
          41  +
    ::aws_smithy_legacy_http_server::response::Response,
          42  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          43  +
> {
          44  +
    Ok({
          45  +
        #[allow(unused_mut)]
          46  +
        let mut builder = ::http::Response::builder();
          47  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          48  +
            builder,
          49  +
            ::http::header::CONTENT_TYPE,
          50  +
            "application/json",
          51  +
        );
          52  +
        let http_status: u16 = 200;
          53  +
        builder = builder.status(http_status);
          54  +
        let payload = "";
          55  +
        let content_length = payload.len();
          56  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          57  +
            builder,
          58  +
            ::http::header::CONTENT_LENGTH,
          59  +
            content_length,
          60  +
        );
          61  +
        let body = ::aws_smithy_legacy_http_server::body::to_boxed(payload);
          62  +
        builder.body(body)?
          63  +
    })
          64  +
}
          65  +
          66  +
#[allow(clippy::unnecessary_wraps)]
          67  +
pub fn ser_malformed_range_http_error(
          68  +
    error: &crate::error::MalformedRangeError,
          69  +
) -> std::result::Result<
          70  +
    ::aws_smithy_legacy_http_server::response::Response,
          71  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          72  +
> {
          73  +
    Ok({
          74  +
        match error {
          75  +
            crate::error::MalformedRangeError::ValidationException(output) => {
          76  +
                let payload = crate::protocol_serde::shape_validation_exception::ser_validation_exception_error(output)?;
          77  +
                #[allow(unused_mut)]
          78  +
                let mut builder = ::http::Response::builder();
          79  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          80  +
                    builder,
          81  +
                    ::http::header::CONTENT_TYPE,
          82  +
                    "application/json",
          83  +
                );
          84  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          85  +
                    builder,
          86  +
                    ::http::header::HeaderName::from_static("x-amzn-errortype"),
          87  +
                    "ValidationException",
          88  +
                );
          89  +
                let content_length = payload.len();
          90  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          91  +
                    builder,
          92  +
                    ::http::header::CONTENT_LENGTH,
          93  +
                    content_length,
          94  +
                );
          95  +
                builder
          96  +
                    .status(400)
          97  +
                    .body(::aws_smithy_legacy_http_server::body::to_boxed(payload))?
          98  +
            }
          99  +
        }
         100  +
    })
         101  +
}
         102  +
         103  +
pub(crate) fn de_malformed_range(
         104  +
    value: &[u8],
         105  +
    mut builder: crate::input::malformed_range_input::Builder,
         106  +
) -> ::std::result::Result<
         107  +
    crate::input::malformed_range_input::Builder,
         108  +
    ::aws_smithy_json::deserialize::error::DeserializeError,
         109  +
> {
         110  +
    let mut tokens_owned =
         111  +
        ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value))
         112  +
            .peekable();
         113  +
    let tokens = &mut tokens_owned;
         114  +
    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
         115  +
    loop {
         116  +
        match tokens.next().transpose()? {
         117  +
            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
         118  +
            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
         119  +
                match key.to_unescaped()?.as_ref() {
         120  +
                    "byte" => {
         121  +
                        builder = builder.set_byte(
         122  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         123  +
                                tokens.next(),
         124  +
                            )?
         125  +
                            .map(i8::try_from)
         126  +
                            .transpose()?,
         127  +
                        );
         128  +
                    }
         129  +
                    "float" => {
         130  +
                        builder = builder.set_float(
         131  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         132  +
                                tokens.next(),
         133  +
                            )?
         134  +
                            .map(|v| v.to_f32_lossy()),
         135  +
                        );
         136  +
                    }
         137  +
                    "integer" => {
         138  +
                        builder = builder.set_integer(
         139  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         140  +
                                tokens.next(),
         141  +
                            )?
         142  +
                            .map(i32::try_from)
         143  +
                            .transpose()?,
         144  +
                        );
         145  +
                    }
         146  +
                    "long" => {
         147  +
                        builder = builder.set_long(
         148  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         149  +
                                tokens.next(),
         150  +
                            )?
         151  +
                            .map(i64::try_from)
         152  +
                            .transpose()?,
         153  +
                        );
         154  +
                    }
         155  +
                    "maxByte" => {
         156  +
                        builder = builder.set_max_byte(
         157  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         158  +
                                tokens.next(),
         159  +
                            )?
         160  +
                            .map(i8::try_from)
         161  +
                            .transpose()?,
         162  +
                        );
         163  +
                    }
         164  +
                    "maxFloat" => {
         165  +
                        builder = builder.set_max_float(
         166  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         167  +
                                tokens.next(),
         168  +
                            )?
         169  +
                            .map(|v| v.to_f32_lossy()),
         170  +
                        );
         171  +
                    }
         172  +
                    "maxInteger" => {
         173  +
                        builder = builder.set_max_integer(
         174  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         175  +
                                tokens.next(),
         176  +
                            )?
         177  +
                            .map(i32::try_from)
         178  +
                            .transpose()?,
         179  +
                        );
         180  +
                    }
         181  +
                    "maxLong" => {
         182  +
                        builder = builder.set_max_long(
         183  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         184  +
                                tokens.next(),
         185  +
                            )?
         186  +
                            .map(i64::try_from)
         187  +
                            .transpose()?,
         188  +
                        );
         189  +
                    }
         190  +
                    "maxShort" => {
         191  +
                        builder = builder.set_max_short(
         192  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         193  +
                                tokens.next(),
         194  +
                            )?
         195  +
                            .map(i16::try_from)
         196  +
                            .transpose()?,
         197  +
                        );
         198  +
                    }
         199  +
                    "minByte" => {
         200  +
                        builder = builder.set_min_byte(
         201  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         202  +
                                tokens.next(),
         203  +
                            )?
         204  +
                            .map(i8::try_from)
         205  +
                            .transpose()?,
         206  +
                        );
         207  +
                    }
         208  +
                    "minFloat" => {
         209  +
                        builder = builder.set_min_float(
         210  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         211  +
                                tokens.next(),
         212  +
                            )?
         213  +
                            .map(|v| v.to_f32_lossy()),
         214  +
                        );
         215  +
                    }
         216  +
                    "minInteger" => {
         217  +
                        builder = builder.set_min_integer(
         218  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         219  +
                                tokens.next(),
         220  +
                            )?
         221  +
                            .map(i32::try_from)
         222  +
                            .transpose()?,
         223  +
                        );
         224  +
                    }
         225  +
                    "minLong" => {
         226  +
                        builder = builder.set_min_long(
         227  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         228  +
                                tokens.next(),
         229  +
                            )?
         230  +
                            .map(i64::try_from)
         231  +
                            .transpose()?,
         232  +
                        );
         233  +
                    }
         234  +
                    "minShort" => {
         235  +
                        builder = builder.set_min_short(
         236  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         237  +
                                tokens.next(),
         238  +
                            )?
         239  +
                            .map(i16::try_from)
         240  +
                            .transpose()?,
         241  +
                        );
         242  +
                    }
         243  +
                    "short" => {
         244  +
                        builder = builder.set_short(
         245  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         246  +
                                tokens.next(),
         247  +
                            )?
         248  +
                            .map(i16::try_from)
         249  +
                            .transpose()?,
         250  +
                        );
         251  +
                    }
         252  +
                    _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
         253  +
                }
         254  +
            }
         255  +
            other => {
         256  +
                return Err(
         257  +
                    ::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
         258  +
                        "expected object key or end object, found: {other:?}"
         259  +
                    )),
         260  +
                )
         261  +
            }
         262  +
        }
         263  +
    }
         264  +
    if tokens.next().is_some() {
         265  +
        return Err(
         266  +
            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
         267  +
                "found more JSON tokens after completing parsing",
         268  +
            ),
         269  +
        );
         270  +
    }
         271  +
    Ok(builder)
         272  +
}

tmp-codegen-diff/codegen-server-test/rest_json_validation-http0x/rust-server-codegen/src/protocol_serde/shape_malformed_range_override.rs

@@ -0,1 +0,273 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
#[allow(clippy::unnecessary_wraps)]
           3  +
pub async fn de_malformed_range_override_http_request<B>(
           4  +
    #[allow(unused_variables)] request: ::http::Request<B>,
           5  +
) -> std::result::Result<
           6  +
    crate::input::MalformedRangeOverrideInput,
           7  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection,
           8  +
>
           9  +
where
          10  +
    B: ::aws_smithy_legacy_http_server::body::HttpBody + Send,
          11  +
    B::Data: Send,
          12  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection:
          13  +
        From<<B as ::aws_smithy_legacy_http_server::body::HttpBody>::Error>,
          14  +
{
          15  +
    Ok({
          16  +
        #[allow(unused_mut)]
          17  +
        let mut input = crate::input::malformed_range_override_input::Builder::default();
          18  +
        #[allow(unused_variables)]
          19  +
        let ::aws_smithy_runtime_api::http::RequestParts {
          20  +
            uri, headers, body, ..
          21  +
        } = ::aws_smithy_runtime_api::http::Request::try_from(request)?.into_parts();
          22  +
        let bytes = ::hyper::body::to_bytes(body).await?;
          23  +
        if !bytes.is_empty() {
          24  +
            ::aws_smithy_legacy_http_server::protocol::content_type_header_classifier_smithy(
          25  +
                &headers,
          26  +
                Some("application/json"),
          27  +
            )?;
          28  +
            input =
          29  +
                crate::protocol_serde::shape_malformed_range_override::de_malformed_range_override(
          30  +
                    bytes.as_ref(),
          31  +
                    input,
          32  +
                )?;
          33  +
        }
          34  +
        input.build()?
          35  +
    })
          36  +
}
          37  +
          38  +
#[allow(clippy::unnecessary_wraps)]
          39  +
pub fn ser_malformed_range_override_http_response(
          40  +
    #[allow(unused_variables)] output: crate::output::MalformedRangeOverrideOutput,
          41  +
) -> std::result::Result<
          42  +
    ::aws_smithy_legacy_http_server::response::Response,
          43  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          44  +
> {
          45  +
    Ok({
          46  +
        #[allow(unused_mut)]
          47  +
        let mut builder = ::http::Response::builder();
          48  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          49  +
            builder,
          50  +
            ::http::header::CONTENT_TYPE,
          51  +
            "application/json",
          52  +
        );
          53  +
        let http_status: u16 = 200;
          54  +
        builder = builder.status(http_status);
          55  +
        let payload = "";
          56  +
        let content_length = payload.len();
          57  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          58  +
            builder,
          59  +
            ::http::header::CONTENT_LENGTH,
          60  +
            content_length,
          61  +
        );
          62  +
        let body = ::aws_smithy_legacy_http_server::body::to_boxed(payload);
          63  +
        builder.body(body)?
          64  +
    })
          65  +
}
          66  +
          67  +
#[allow(clippy::unnecessary_wraps)]
          68  +
pub fn ser_malformed_range_override_http_error(
          69  +
    error: &crate::error::MalformedRangeOverrideError,
          70  +
) -> std::result::Result<
          71  +
    ::aws_smithy_legacy_http_server::response::Response,
          72  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          73  +
> {
          74  +
    Ok({
          75  +
        match error {
          76  +
            crate::error::MalformedRangeOverrideError::ValidationException(output) => {
          77  +
                let payload = crate::protocol_serde::shape_validation_exception::ser_validation_exception_error(output)?;
          78  +
                #[allow(unused_mut)]
          79  +
                let mut builder = ::http::Response::builder();
          80  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          81  +
                    builder,
          82  +
                    ::http::header::CONTENT_TYPE,
          83  +
                    "application/json",
          84  +
                );
          85  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          86  +
                    builder,
          87  +
                    ::http::header::HeaderName::from_static("x-amzn-errortype"),
          88  +
                    "ValidationException",
          89  +
                );
          90  +
                let content_length = payload.len();
          91  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          92  +
                    builder,
          93  +
                    ::http::header::CONTENT_LENGTH,
          94  +
                    content_length,
          95  +
                );
          96  +
                builder
          97  +
                    .status(400)
          98  +
                    .body(::aws_smithy_legacy_http_server::body::to_boxed(payload))?
          99  +
            }
         100  +
        }
         101  +
    })
         102  +
}
         103  +
         104  +
pub(crate) fn de_malformed_range_override(
         105  +
    value: &[u8],
         106  +
    mut builder: crate::input::malformed_range_override_input::Builder,
         107  +
) -> ::std::result::Result<
         108  +
    crate::input::malformed_range_override_input::Builder,
         109  +
    ::aws_smithy_json::deserialize::error::DeserializeError,
         110  +
> {
         111  +
    let mut tokens_owned =
         112  +
        ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value))
         113  +
            .peekable();
         114  +
    let tokens = &mut tokens_owned;
         115  +
    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
         116  +
    loop {
         117  +
        match tokens.next().transpose()? {
         118  +
            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
         119  +
            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
         120  +
                match key.to_unescaped()?.as_ref() {
         121  +
                    "byte" => {
         122  +
                        builder = builder.set_byte(
         123  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         124  +
                                tokens.next(),
         125  +
                            )?
         126  +
                            .map(i8::try_from)
         127  +
                            .transpose()?,
         128  +
                        );
         129  +
                    }
         130  +
                    "float" => {
         131  +
                        builder = builder.set_float(
         132  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         133  +
                                tokens.next(),
         134  +
                            )?
         135  +
                            .map(|v| v.to_f32_lossy()),
         136  +
                        );
         137  +
                    }
         138  +
                    "integer" => {
         139  +
                        builder = builder.set_integer(
         140  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         141  +
                                tokens.next(),
         142  +
                            )?
         143  +
                            .map(i32::try_from)
         144  +
                            .transpose()?,
         145  +
                        );
         146  +
                    }
         147  +
                    "long" => {
         148  +
                        builder = builder.set_long(
         149  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         150  +
                                tokens.next(),
         151  +
                            )?
         152  +
                            .map(i64::try_from)
         153  +
                            .transpose()?,
         154  +
                        );
         155  +
                    }
         156  +
                    "maxByte" => {
         157  +
                        builder = builder.set_max_byte(
         158  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         159  +
                                tokens.next(),
         160  +
                            )?
         161  +
                            .map(i8::try_from)
         162  +
                            .transpose()?,
         163  +
                        );
         164  +
                    }
         165  +
                    "maxFloat" => {
         166  +
                        builder = builder.set_max_float(
         167  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         168  +
                                tokens.next(),
         169  +
                            )?
         170  +
                            .map(|v| v.to_f32_lossy()),
         171  +
                        );
         172  +
                    }
         173  +
                    "maxInteger" => {
         174  +
                        builder = builder.set_max_integer(
         175  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         176  +
                                tokens.next(),
         177  +
                            )?
         178  +
                            .map(i32::try_from)
         179  +
                            .transpose()?,
         180  +
                        );
         181  +
                    }
         182  +
                    "maxLong" => {
         183  +
                        builder = builder.set_max_long(
         184  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         185  +
                                tokens.next(),
         186  +
                            )?
         187  +
                            .map(i64::try_from)
         188  +
                            .transpose()?,
         189  +
                        );
         190  +
                    }
         191  +
                    "maxShort" => {
         192  +
                        builder = builder.set_max_short(
         193  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         194  +
                                tokens.next(),
         195  +
                            )?
         196  +
                            .map(i16::try_from)
         197  +
                            .transpose()?,
         198  +
                        );
         199  +
                    }
         200  +
                    "minByte" => {
         201  +
                        builder = builder.set_min_byte(
         202  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         203  +
                                tokens.next(),
         204  +
                            )?
         205  +
                            .map(i8::try_from)
         206  +
                            .transpose()?,
         207  +
                        );
         208  +
                    }
         209  +
                    "minFloat" => {
         210  +
                        builder = builder.set_min_float(
         211  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         212  +
                                tokens.next(),
         213  +
                            )?
         214  +
                            .map(|v| v.to_f32_lossy()),
         215  +
                        );
         216  +
                    }
         217  +
                    "minInteger" => {
         218  +
                        builder = builder.set_min_integer(
         219  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         220  +
                                tokens.next(),
         221  +
                            )?
         222  +
                            .map(i32::try_from)
         223  +
                            .transpose()?,
         224  +
                        );
         225  +
                    }
         226  +
                    "minLong" => {
         227  +
                        builder = builder.set_min_long(
         228  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         229  +
                                tokens.next(),
         230  +
                            )?
         231  +
                            .map(i64::try_from)
         232  +
                            .transpose()?,
         233  +
                        );
         234  +
                    }
         235  +
                    "minShort" => {
         236  +
                        builder = builder.set_min_short(
         237  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         238  +
                                tokens.next(),
         239  +
                            )?
         240  +
                            .map(i16::try_from)
         241  +
                            .transpose()?,
         242  +
                        );
         243  +
                    }
         244  +
                    "short" => {
         245  +
                        builder = builder.set_short(
         246  +
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
         247  +
                                tokens.next(),
         248  +
                            )?
         249  +
                            .map(i16::try_from)
         250  +
                            .transpose()?,
         251  +
                        );
         252  +
                    }
         253  +
                    _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
         254  +
                }
         255  +
            }
         256  +
            other => {
         257  +
                return Err(
         258  +
                    ::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
         259  +
                        "expected object key or end object, found: {other:?}"
         260  +
                    )),
         261  +
                )
         262  +
            }
         263  +
        }
         264  +
    }
         265  +
    if tokens.next().is_some() {
         266  +
        return Err(
         267  +
            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
         268  +
                "found more JSON tokens after completing parsing",
         269  +
            ),
         270  +
        );
         271  +
    }
         272  +
    Ok(builder)
         273  +
}

tmp-codegen-diff/codegen-server-test/rest_json_validation-http0x/rust-server-codegen/src/protocol_serde/shape_malformed_required.rs

@@ -0,1 +0,169 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
#[allow(clippy::unnecessary_wraps)]
           3  +
pub async fn de_malformed_required_http_request<B>(
           4  +
    #[allow(unused_variables)] request: ::http::Request<B>,
           5  +
) -> std::result::Result<
           6  +
    crate::input::MalformedRequiredInput,
           7  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection,
           8  +
>
           9  +
where
          10  +
    B: ::aws_smithy_legacy_http_server::body::HttpBody + Send,
          11  +
    B::Data: Send,
          12  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection:
          13  +
        From<<B as ::aws_smithy_legacy_http_server::body::HttpBody>::Error>,
          14  +
{
          15  +
    Ok({
          16  +
        #[allow(unused_mut)]
          17  +
        let mut input = crate::input::malformed_required_input::Builder::default();
          18  +
        #[allow(unused_variables)]
          19  +
        let ::aws_smithy_runtime_api::http::RequestParts {
          20  +
            uri, headers, body, ..
          21  +
        } = ::aws_smithy_runtime_api::http::Request::try_from(request)?.into_parts();
          22  +
        let bytes = ::hyper::body::to_bytes(body).await?;
          23  +
        if !bytes.is_empty() {
          24  +
            ::aws_smithy_legacy_http_server::protocol::content_type_header_classifier_smithy(
          25  +
                &headers,
          26  +
                Some("application/json"),
          27  +
            )?;
          28  +
            input = crate::protocol_serde::shape_malformed_required::de_malformed_required(
          29  +
                bytes.as_ref(),
          30  +
                input,
          31  +
            )?;
          32  +
        }
          33  +
        if let Some(value) =
          34  +
            crate::protocol_serde::shape_malformed_required_input::de_string_in_header_header(
          35  +
                &headers,
          36  +
            )?
          37  +
        {
          38  +
            input = input.set_string_in_header(value)
          39  +
        }
          40  +
        let query_string = uri.query().unwrap_or("");
          41  +
        let pairs = ::form_urlencoded::parse(query_string.as_bytes());
          42  +
        let mut string_in_query_seen = false;
          43  +
        for (k, v) in pairs {
          44  +
            if !string_in_query_seen && k == "stringInQuery" {
          45  +
                input = input.set_string_in_query(
          46  +
                    crate::protocol_serde::shape_malformed_required_input::de_string_in_query(&v)?,
          47  +
                );
          48  +
                string_in_query_seen = true;
          49  +
            }
          50  +
        }
          51  +
        input.build()?
          52  +
    })
          53  +
}
          54  +
          55  +
#[allow(clippy::unnecessary_wraps)]
          56  +
pub fn ser_malformed_required_http_response(
          57  +
    #[allow(unused_variables)] output: crate::output::MalformedRequiredOutput,
          58  +
) -> std::result::Result<
          59  +
    ::aws_smithy_legacy_http_server::response::Response,
          60  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          61  +
> {
          62  +
    Ok({
          63  +
        #[allow(unused_mut)]
          64  +
        let mut builder = ::http::Response::builder();
          65  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          66  +
            builder,
          67  +
            ::http::header::CONTENT_TYPE,
          68  +
            "application/json",
          69  +
        );
          70  +
        let http_status: u16 = 200;
          71  +
        builder = builder.status(http_status);
          72  +
        let payload = "";
          73  +
        let content_length = payload.len();
          74  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          75  +
            builder,
          76  +
            ::http::header::CONTENT_LENGTH,
          77  +
            content_length,
          78  +
        );
          79  +
        let body = ::aws_smithy_legacy_http_server::body::to_boxed(payload);
          80  +
        builder.body(body)?
          81  +
    })
          82  +
}
          83  +
          84  +
#[allow(clippy::unnecessary_wraps)]
          85  +
pub fn ser_malformed_required_http_error(
          86  +
    error: &crate::error::MalformedRequiredError,
          87  +
) -> std::result::Result<
          88  +
    ::aws_smithy_legacy_http_server::response::Response,
          89  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          90  +
> {
          91  +
    Ok({
          92  +
        match error {
          93  +
            crate::error::MalformedRequiredError::ValidationException(output) => {
          94  +
                let payload = crate::protocol_serde::shape_validation_exception::ser_validation_exception_error(output)?;
          95  +
                #[allow(unused_mut)]
          96  +
                let mut builder = ::http::Response::builder();
          97  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          98  +
                    builder,
          99  +
                    ::http::header::CONTENT_TYPE,
         100  +
                    "application/json",
         101  +
                );
         102  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
         103  +
                    builder,
         104  +
                    ::http::header::HeaderName::from_static("x-amzn-errortype"),
         105  +
                    "ValidationException",
         106  +
                );
         107  +
                let content_length = payload.len();
         108  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
         109  +
                    builder,
         110  +
                    ::http::header::CONTENT_LENGTH,
         111  +
                    content_length,
         112  +
                );
         113  +
                builder
         114  +
                    .status(400)
         115  +
                    .body(::aws_smithy_legacy_http_server::body::to_boxed(payload))?
         116  +
            }
         117  +
        }
         118  +
    })
         119  +
}
         120  +
         121  +
pub(crate) fn de_malformed_required(
         122  +
    value: &[u8],
         123  +
    mut builder: crate::input::malformed_required_input::Builder,
         124  +
) -> ::std::result::Result<
         125  +
    crate::input::malformed_required_input::Builder,
         126  +
    ::aws_smithy_json::deserialize::error::DeserializeError,
         127  +
> {
         128  +
    let mut tokens_owned =
         129  +
        ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value))
         130  +
            .peekable();
         131  +
    let tokens = &mut tokens_owned;
         132  +
    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
         133  +
    loop {
         134  +
        match tokens.next().transpose()? {
         135  +
            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
         136  +
            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
         137  +
                match key.to_unescaped()?.as_ref() {
         138  +
                    "string" => {
         139  +
                        if let Some(v) =
         140  +
                            ::aws_smithy_json::deserialize::token::expect_string_or_null(
         141  +
                                tokens.next(),
         142  +
                            )?
         143  +
                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
         144  +
                            .transpose()?
         145  +
                        {
         146  +
                            builder = builder.set_string(v);
         147  +
                        }
         148  +
                    }
         149  +
                    _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
         150  +
                }
         151  +
            }
         152  +
            other => {
         153  +
                return Err(
         154  +
                    ::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
         155  +
                        "expected object key or end object, found: {other:?}"
         156  +
                    )),
         157  +
                )
         158  +
            }
         159  +
        }
         160  +
    }
         161  +
    if tokens.next().is_some() {
         162  +
        return Err(
         163  +
            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
         164  +
                "found more JSON tokens after completing parsing",
         165  +
            ),
         166  +
        );
         167  +
    }
         168  +
    Ok(builder)
         169  +
}

tmp-codegen-diff/codegen-server-test/rest_json_validation-http0x/rust-server-codegen/src/protocol_serde/shape_malformed_required_input.rs

@@ -0,1 +0,20 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
pub(crate) fn de_string_in_header_header(
           3  +
    header_map: &::aws_smithy_runtime_api::http::Headers,
           4  +
) -> ::std::result::Result<
           5  +
    ::std::option::Option<::std::string::String>,
           6  +
    ::aws_smithy_legacy_http::header::ParseError,
           7  +
> {
           8  +
    let headers = header_map.get_all("string-in-headers");
           9  +
    ::aws_smithy_legacy_http::header::one_or_none(headers)
          10  +
}
          11  +
          12  +
pub fn de_string_in_query(
          13  +
    value: &str,
          14  +
) -> std::result::Result<
          15  +
    ::std::string::String,
          16  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection,
          17  +
> {
          18  +
    let value = value.to_owned();
          19  +
    Ok(value)
          20  +
}

tmp-codegen-diff/codegen-server-test/rest_json_validation-http0x/rust-server-codegen/src/protocol_serde/shape_malformed_unique_items.rs

@@ -0,1 +0,222 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
#[allow(clippy::unnecessary_wraps)]
           3  +
pub async fn de_malformed_unique_items_http_request<B>(
           4  +
    #[allow(unused_variables)] request: ::http::Request<B>,
           5  +
) -> std::result::Result<
           6  +
    crate::input::MalformedUniqueItemsInput,
           7  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection,
           8  +
>
           9  +
where
          10  +
    B: ::aws_smithy_legacy_http_server::body::HttpBody + Send,
          11  +
    B::Data: Send,
          12  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection:
          13  +
        From<<B as ::aws_smithy_legacy_http_server::body::HttpBody>::Error>,
          14  +
{
          15  +
    Ok({
          16  +
        #[allow(unused_mut)]
          17  +
        let mut input = crate::input::malformed_unique_items_input::Builder::default();
          18  +
        #[allow(unused_variables)]
          19  +
        let ::aws_smithy_runtime_api::http::RequestParts {
          20  +
            uri, headers, body, ..
          21  +
        } = ::aws_smithy_runtime_api::http::Request::try_from(request)?.into_parts();
          22  +
        let bytes = ::hyper::body::to_bytes(body).await?;
          23  +
        if !bytes.is_empty() {
          24  +
            ::aws_smithy_legacy_http_server::protocol::content_type_header_classifier_smithy(
          25  +
                &headers,
          26  +
                Some("application/json"),
          27  +
            )?;
          28  +
            input = crate::protocol_serde::shape_malformed_unique_items::de_malformed_unique_items(
          29  +
                bytes.as_ref(),
          30  +
                input,
          31  +
            )?;
          32  +
        }
          33  +
        input.build()?
          34  +
    })
          35  +
}
          36  +
          37  +
#[allow(clippy::unnecessary_wraps)]
          38  +
pub fn ser_malformed_unique_items_http_response(
          39  +
    #[allow(unused_variables)] output: crate::output::MalformedUniqueItemsOutput,
          40  +
) -> std::result::Result<
          41  +
    ::aws_smithy_legacy_http_server::response::Response,
          42  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          43  +
> {
          44  +
    Ok({
          45  +
        #[allow(unused_mut)]
          46  +
        let mut builder = ::http::Response::builder();
          47  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          48  +
            builder,
          49  +
            ::http::header::CONTENT_TYPE,
          50  +
            "application/json",
          51  +
        );
          52  +
        let http_status: u16 = 200;
          53  +
        builder = builder.status(http_status);
          54  +
        let payload = "";
          55  +
        let content_length = payload.len();
          56  +
        builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          57  +
            builder,
          58  +
            ::http::header::CONTENT_LENGTH,
          59  +
            content_length,
          60  +
        );
          61  +
        let body = ::aws_smithy_legacy_http_server::body::to_boxed(payload);
          62  +
        builder.body(body)?
          63  +
    })
          64  +
}
          65  +
          66  +
#[allow(clippy::unnecessary_wraps)]
          67  +
pub fn ser_malformed_unique_items_http_error(
          68  +
    error: &crate::error::MalformedUniqueItemsError,
          69  +
) -> std::result::Result<
          70  +
    ::aws_smithy_legacy_http_server::response::Response,
          71  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
          72  +
> {
          73  +
    Ok({
          74  +
        match error {
          75  +
            crate::error::MalformedUniqueItemsError::ValidationException(output) => {
          76  +
                let payload = crate::protocol_serde::shape_validation_exception::ser_validation_exception_error(output)?;
          77  +
                #[allow(unused_mut)]
          78  +
                let mut builder = ::http::Response::builder();
          79  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          80  +
                    builder,
          81  +
                    ::http::header::CONTENT_TYPE,
          82  +
                    "application/json",
          83  +
                );
          84  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          85  +
                    builder,
          86  +
                    ::http::header::HeaderName::from_static("x-amzn-errortype"),
          87  +
                    "ValidationException",
          88  +
                );
          89  +
                let content_length = payload.len();
          90  +
                builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
          91  +
                    builder,
          92  +
                    ::http::header::CONTENT_LENGTH,
          93  +
                    content_length,
          94  +
                );
          95  +
                builder
          96  +
                    .status(400)
          97  +
                    .body(::aws_smithy_legacy_http_server::body::to_boxed(payload))?
          98  +
            }
          99  +
        }
         100  +
    })
         101  +
}
         102  +
         103  +
pub(crate) fn de_malformed_unique_items(
         104  +
    value: &[u8],
         105  +
    mut builder: crate::input::malformed_unique_items_input::Builder,
         106  +
) -> ::std::result::Result<
         107  +
    crate::input::malformed_unique_items_input::Builder,
         108  +
    ::aws_smithy_json::deserialize::error::DeserializeError,
         109  +
> {
         110  +
    let mut tokens_owned =
         111  +
        ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value))
         112  +
            .peekable();
         113  +
    let tokens = &mut tokens_owned;
         114  +
    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
         115  +
    loop {
         116  +
        match tokens.next().transpose()? {
         117  +
            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
         118  +
            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
         119  +
                match key.to_unescaped()?.as_ref() {
         120  +
                    "blobList" => {
         121  +
                        builder = builder.set_blob_list(
         122  +
                            crate::protocol_serde::shape_blob_set::de_blob_set(tokens)?,
         123  +
                        );
         124  +
                    }
         125  +
                    "booleanList" => {
         126  +
                        builder = builder.set_boolean_list(
         127  +
                            crate::protocol_serde::shape_boolean_set::de_boolean_set(tokens)?,
         128  +
                        );
         129  +
                    }
         130  +
                    "byteList" => {
         131  +
                        builder = builder.set_byte_list(
         132  +
                            crate::protocol_serde::shape_byte_set::de_byte_set(tokens)?,
         133  +
                        );
         134  +
                    }
         135  +
                    "dateTimeList" => {
         136  +
                        builder = builder.set_date_time_list(
         137  +
                            crate::protocol_serde::shape_date_time_set::de_date_time_set(tokens)?,
         138  +
                        );
         139  +
                    }
         140  +
                    "enumList" => {
         141  +
                        builder = builder.set_enum_list(
         142  +
                            crate::protocol_serde::shape_foo_enum_set::de_foo_enum_set(tokens)?,
         143  +
                        );
         144  +
                    }
         145  +
                    "httpDateList" => {
         146  +
                        builder = builder.set_http_date_list(
         147  +
                            crate::protocol_serde::shape_http_date_set::de_http_date_set(tokens)?,
         148  +
                        );
         149  +
                    }
         150  +
                    "intEnumList" => {
         151  +
                        builder = builder.set_int_enum_list(
         152  +
                            crate::protocol_serde::shape_integer_enum_set::de_integer_enum_set(
         153  +
                                tokens,
         154  +
                            )?,
         155  +
                        );
         156  +
                    }
         157  +
                    "integerList" => {
         158  +
                        builder = builder.set_integer_list(
         159  +
                            crate::protocol_serde::shape_integer_set::de_integer_set(tokens)?,
         160  +
                        );
         161  +
                    }
         162  +
                    "listList" => {
         163  +
                        builder = builder.set_list_list(
         164  +
                            crate::protocol_serde::shape_list_set::de_list_set(tokens)?,
         165  +
                        );
         166  +
                    }
         167  +
                    "longList" => {
         168  +
                        builder = builder.set_long_list(
         169  +
                            crate::protocol_serde::shape_long_set::de_long_set(tokens)?,
         170  +
                        );
         171  +
                    }
         172  +
                    "shortList" => {
         173  +
                        builder = builder.set_short_list(
         174  +
                            crate::protocol_serde::shape_short_set::de_short_set(tokens)?,
         175  +
                        );
         176  +
                    }
         177  +
                    "stringList" => {
         178  +
                        builder = builder.set_string_list(
         179  +
                            crate::protocol_serde::shape_string_set::de_string_set(tokens)?,
         180  +
                        );
         181  +
                    }
         182  +
                    "structureList" => {
         183  +
                        builder = builder.set_structure_list(
         184  +
                            crate::protocol_serde::shape_structure_set::de_structure_set(tokens)?,
         185  +
                        );
         186  +
                    }
         187  +
                    "structureListWithNoKey" => {
         188  +
                        builder = builder.set_structure_list_with_no_key(
         189  +
                            crate::protocol_serde::shape_structure_set_with_no_key::de_structure_set_with_no_key(tokens)?
         190  +
                        );
         191  +
                    }
         192  +
                    "timestampList" => {
         193  +
                        builder = builder.set_timestamp_list(
         194  +
                            crate::protocol_serde::shape_timestamp_set::de_timestamp_set(tokens)?,
         195  +
                        );
         196  +
                    }
         197  +
                    "unionList" => {
         198  +
                        builder = builder.set_union_list(
         199  +
                            crate::protocol_serde::shape_union_set::de_union_set(tokens)?,
         200  +
                        );
         201  +
                    }
         202  +
                    _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
         203  +
                }
         204  +
            }
         205  +
            other => {
         206  +
                return Err(
         207  +
                    ::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
         208  +
                        "expected object key or end object, found: {other:?}"
         209  +
                    )),
         210  +
                )
         211  +
            }
         212  +
        }
         213  +
    }
         214  +
    if tokens.next().is_some() {
         215  +
        return Err(
         216  +
            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
         217  +
                "found more JSON tokens after completing parsing",
         218  +
            ),
         219  +
        );
         220  +
    }
         221  +
    Ok(builder)
         222  +
}

tmp-codegen-diff/codegen-server-test/rest_json_validation-http0x/rust-server-codegen/src/protocol_serde/shape_missing_key_structure.rs

@@ -0,1 +0,57 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
pub(crate) fn de_missing_key_structure<'a, I>(
           3  +
    tokens: &mut ::std::iter::Peekable<I>,
           4  +
) -> ::std::result::Result<
           5  +
    Option<crate::model::missing_key_structure::Builder>,
           6  +
    ::aws_smithy_json::deserialize::error::DeserializeError,
           7  +
>
           8  +
where
           9  +
    I: Iterator<
          10  +
        Item = Result<
          11  +
            ::aws_smithy_json::deserialize::Token<'a>,
          12  +
            ::aws_smithy_json::deserialize::error::DeserializeError,
          13  +
        >,
          14  +
    >,
          15  +
{
          16  +
    match tokens.next().transpose()? {
          17  +
        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
          18  +
        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
          19  +
            #[allow(unused_mut)]
          20  +
            let mut builder = crate::model::missing_key_structure::Builder::default();
          21  +
            loop {
          22  +
                match tokens.next().transpose()? {
          23  +
                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
          24  +
                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
          25  +
                        match key.to_unescaped()?.as_ref() {
          26  +
                            "hi" => {
          27  +
                                if let Some(v) =
          28  +
                                    ::aws_smithy_json::deserialize::token::expect_string_or_null(
          29  +
                                        tokens.next(),
          30  +
                                    )?
          31  +
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
          32  +
                                    .transpose()?
          33  +
                                {
          34  +
                                    builder = builder.set_hi(v);
          35  +
                                }
          36  +
                            }
          37  +
                            _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
          38  +
                        }
          39  +
                    }
          40  +
                    other => {
          41  +
                        return Err(
          42  +
                            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
          43  +
                                format!("expected object key or end object, found: {other:?}"),
          44  +
                            ),
          45  +
                        )
          46  +
                    }
          47  +
                }
          48  +
            }
          49  +
            Ok(Some(builder))
          50  +
        }
          51  +
        _ => Err(
          52  +
            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
          53  +
                "expected start object or null",
          54  +
            ),
          55  +
        ),
          56  +
    }
          57  +
}