Server Test

Server Test

rev. 5857d6aa46858ed386c38a08835dd5eb00fe6788

Files changed:

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/operation.rs

@@ -1,0 +100,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
::pin_project_lite::pin_project! {
    3         -
    /// A [`Future`](std::future::Future) aggregating the body bytes of a [`Request`] and constructing the
    4         -
    /// [`TestOperationInput`](crate::input::TestOperationInput) using modelled bindings.
    5         -
    pub struct TestOperationInputFuture {
    6         -
        inner: std::pin::Pin<Box<dyn std::future::Future<Output = Result<crate::input::TestOperationInput, ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError>> + Send>>
    7         -
    }
    8         -
}
    9         -
   10         -
impl std::future::Future for TestOperationInputFuture {
   11         -
    type Output = Result<
   12         -
        crate::input::TestOperationInput,
   13         -
        ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError,
   14         -
    >;
   15         -
   16         -
    fn poll(
   17         -
        self: std::pin::Pin<&mut Self>,
   18         -
        cx: &mut std::task::Context<'_>,
   19         -
    ) -> std::task::Poll<Self::Output> {
   20         -
        let this = self.project();
   21         -
        this.inner.as_mut().poll(cx)
   22         -
    }
   23         -
}
   24         -
   25         -
impl<B>
   26         -
    ::aws_smithy_http_server::request::FromRequest<
   27         -
        ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
   28         -
        B,
   29         -
    > for crate::input::TestOperationInput
   30         -
where
   31         -
    B: ::aws_smithy_http_server::body::HttpBody + Send,
   32         -
    B: 'static,
   33         -
   34         -
    B::Data: Send,
   35         -
    ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection:
   36         -
        From<<B as ::aws_smithy_http_server::body::HttpBody>::Error>,
   37         -
{
   38         -
    type Rejection = ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError;
   39         -
    type Future = TestOperationInputFuture;
   40         -
   41         -
    fn from_request(request: ::http::Request<B>) -> Self::Future {
   42         -
        let fut = async move {
   43         -
            if !::aws_smithy_http_server::protocol::accept_header_classifier(
   44         -
                request.headers(),
   45         -
                &crate::mimes::CONTENT_TYPE_APPLICATION_JSON,
   46         -
            ) {
   47         -
                return Err(::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection::NotAcceptable);
   48         -
            }
   49         -
            crate::protocol_serde::shape_test_operation::de_test_operation_http_request(request)
   50         -
                .await
   51         -
        };
   52         -
        use ::futures_util::future::TryFutureExt;
   53         -
        let fut = fut.map_err(
   54         -
            |e: ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection| {
   55         -
                ::tracing::debug!(error = %e, "failed to deserialize request");
   56         -
                ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(
   57         -
                    e,
   58         -
                )
   59         -
            },
   60         -
        );
   61         -
        TestOperationInputFuture {
   62         -
            inner: Box::pin(fut),
   63         -
        }
   64         -
    }
   65         -
}
   66         -
impl
   67         -
    ::aws_smithy_http_server::response::IntoResponse<
   68         -
        ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
   69         -
    > for crate::output::TestOperationOutput
   70         -
{
   71         -
    fn into_response(self) -> ::aws_smithy_http_server::response::Response {
   72         -
        match crate::protocol_serde::shape_test_operation::ser_test_operation_http_response(self) {
   73         -
            Ok(response) => response,
   74         -
            Err(e) => {
   75         -
                ::tracing::error!(error = %e, "failed to serialize response");
   76         -
                ::aws_smithy_http_server::response::IntoResponse::<::aws_smithy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
   77         -
            }
   78         -
        }
   79         -
    }
   80         -
}
   81         -
impl
   82         -
    ::aws_smithy_http_server::response::IntoResponse<
   83         -
        ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
   84         -
    > for crate::error::TestOperationError
   85         -
{
   86         -
    fn into_response(self) -> ::aws_smithy_http_server::response::Response {
   87         -
        match crate::protocol_serde::shape_test_operation::ser_test_operation_http_error(&self) {
   88         -
            Ok(mut response) => {
   89         -
                response.extensions_mut().insert(
   90         -
                    ::aws_smithy_http_server::extension::ModeledErrorExtension::new(self.name()),
   91         -
                );
   92         -
                response
   93         -
            }
   94         -
            Err(e) => {
   95         -
                ::tracing::error!(error = %e, "failed to serialize response");
   96         -
                ::aws_smithy_http_server::response::IntoResponse::<::aws_smithy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
   97         -
            }
   98         -
        }
   99         -
    }
  100         -
}

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/operation_shape.rs

@@ -1,0 +38,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
#[allow(missing_docs)] // documentation missing in model
    3         -
pub struct TestOperation;
    4         -
    5         -
impl ::aws_smithy_http_server::operation::OperationShape for TestOperation {
    6         -
    const ID: ::aws_smithy_http_server::shape_id::ShapeId =
    7         -
        ::aws_smithy_http_server::shape_id::ShapeId::new(
    8         -
            "com.aws.example#TestOperation",
    9         -
            "com.aws.example",
   10         -
            "TestOperation",
   11         -
        );
   12         -
   13         -
    type Input = crate::input::TestOperationInput;
   14         -
    type Output = crate::output::TestOperationOutput;
   15         -
    type Error = crate::error::TestOperationError;
   16         -
}
   17         -
   18         -
impl ::aws_smithy_http_server::instrumentation::sensitivity::Sensitivity for TestOperation {
   19         -
    type RequestFmt = ::aws_smithy_http_server::instrumentation::sensitivity::RequestFmt<
   20         -
        ::aws_smithy_http_server::instrumentation::MakeIdentity,
   21         -
        ::aws_smithy_http_server::instrumentation::sensitivity::uri::MakeUri<
   22         -
            ::aws_smithy_http_server::instrumentation::MakeIdentity,
   23         -
            ::aws_smithy_http_server::instrumentation::MakeIdentity,
   24         -
        >,
   25         -
    >;
   26         -
    type ResponseFmt = ::aws_smithy_http_server::instrumentation::sensitivity::ResponseFmt<
   27         -
        ::aws_smithy_http_server::instrumentation::MakeIdentity,
   28         -
        ::aws_smithy_http_server::instrumentation::MakeIdentity,
   29         -
    >;
   30         -
   31         -
    fn request_fmt() -> Self::RequestFmt {
   32         -
        ::aws_smithy_http_server::instrumentation::sensitivity::RequestFmt::new()
   33         -
    }
   34         -
   35         -
    fn response_fmt() -> Self::ResponseFmt {
   36         -
        ::aws_smithy_http_server::instrumentation::sensitivity::ResponseFmt::new()
   37         -
    }
   38         -
}

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/output.rs

@@ -1,0 +33,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
#[allow(missing_docs)] // documentation missing in model
    3         -
#[derive(
    4         -
    ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
    5         -
)]
    6         -
pub struct TestOperationOutput {}
    7         -
impl TestOperationOutput {
    8         -
    /// Creates a new builder-style object to manufacture [`TestOperationOutput`](crate::output::TestOperationOutput).
    9         -
    pub fn builder() -> crate::output::test_operation_output::Builder {
   10         -
        crate::output::test_operation_output::Builder::default()
   11         -
    }
   12         -
}
   13         -
/// See [`TestOperationOutput`](crate::output::TestOperationOutput).
   14         -
pub mod test_operation_output {
   15         -
   16         -
    impl ::std::convert::From<Builder> for crate::output::TestOperationOutput {
   17         -
        fn from(builder: Builder) -> Self {
   18         -
            builder.build()
   19         -
        }
   20         -
    }
   21         -
    /// A builder for [`TestOperationOutput`](crate::output::TestOperationOutput).
   22         -
    #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
   23         -
    pub struct Builder {}
   24         -
    impl Builder {
   25         -
        /// Consumes the builder and constructs a [`TestOperationOutput`](crate::output::TestOperationOutput).
   26         -
        pub fn build(self) -> crate::output::TestOperationOutput {
   27         -
            self.build_enforcing_all_constraints()
   28         -
        }
   29         -
        fn build_enforcing_all_constraints(self) -> crate::output::TestOperationOutput {
   30         -
            crate::output::TestOperationOutput {}
   31         -
        }
   32         -
    }
   33         -
}

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/protocol_serde.rs

@@ -1,0 +14,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
pub(crate) mod shape_test_operation;
    3         -
    4         -
pub(crate) mod shape_my_custom_validation_exception;
    5         -
    6         -
pub(crate) fn or_empty_doc(data: &[u8]) -> &[u8] {
    7         -
    if data.is_empty() {
    8         -
        b"{}"
    9         -
    } else {
   10         -
        data
   11         -
    }
   12         -
}
   13         -
   14         -
pub(crate) mod shape_custom_validation_field;

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/protocol_serde/shape_custom_validation_field.rs

@@ -1,0 +17,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
pub fn ser_custom_validation_field(
    3         -
    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
    4         -
    input: &crate::model::CustomValidationField,
    5         -
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    6         -
    {
    7         -
        object
    8         -
            .key("customFieldName")
    9         -
            .string(input.custom_field_name.as_str());
   10         -
    }
   11         -
    {
   12         -
        object
   13         -
            .key("customFieldMessage")
   14         -
            .string(input.custom_field_message.as_str());
   15         -
    }
   16         -
    Ok(())
   17         -
}

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/protocol_serde/shape_my_custom_validation_exception.rs

@@ -1,0 +40,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
pub fn ser_my_custom_validation_exception_error(
    3         -
    value: &crate::error::MyCustomValidationException,
    4         -
) -> ::std::result::Result<String, ::aws_smithy_types::error::operation::SerializationError> {
    5         -
    let mut out = ::std::string::String::new();
    6         -
    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
    7         -
    crate::protocol_serde::shape_my_custom_validation_exception::ser_my_custom_validation_exception(&mut object, value)?;
    8         -
    object.finish();
    9         -
    Ok(out)
   10         -
}
   11         -
   12         -
pub fn ser_my_custom_validation_exception(
   13         -
    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
   14         -
    input: &crate::error::MyCustomValidationException,
   15         -
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
   16         -
    if let Some(var_1) = &input.custom_field_list {
   17         -
        let mut array_2 = object.key("customFieldList").start_array();
   18         -
        for item_3 in var_1 {
   19         -
            {
   20         -
                #[allow(unused_mut)]
   21         -
                let mut object_4 = array_2.value().start_object();
   22         -
                crate::protocol_serde::shape_custom_validation_field::ser_custom_validation_field(
   23         -
                    &mut object_4,
   24         -
                    item_3,
   25         -
                )?;
   26         -
                object_4.finish();
   27         -
            }
   28         -
        }
   29         -
        array_2.finish();
   30         -
    }
   31         -
    {
   32         -
        object
   33         -
            .key("customMessage")
   34         -
            .string(input.custom_message.as_str());
   35         -
    }
   36         -
    {
   37         -
        object.key("reason").string(input.reason.as_str());
   38         -
    }
   39         -
    Ok(())
   40         -
}

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/protocol_serde/shape_test_operation.rs

@@ -1,0 +161,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
#[allow(clippy::unnecessary_wraps)]
    3         -
pub async fn de_test_operation_http_request<B>(
    4         -
    #[allow(unused_variables)] request: ::http::Request<B>,
    5         -
) -> std::result::Result<
    6         -
    crate::input::TestOperationInput,
    7         -
    ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection,
    8         -
>
    9         -
where
   10         -
    B: ::aws_smithy_http_server::body::HttpBody + Send,
   11         -
    B::Data: Send,
   12         -
    ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection:
   13         -
        From<<B as ::aws_smithy_http_server::body::HttpBody>::Error>,
   14         -
{
   15         -
    Ok({
   16         -
        #[allow(unused_mut)]
   17         -
        let mut input = crate::input::test_operation_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_http_server::protocol::content_type_header_classifier_smithy(
   25         -
                &headers,
   26         -
                Some("application/json"),
   27         -
            )?;
   28         -
            input = crate::protocol_serde::shape_test_operation::de_test_operation(
   29         -
                bytes.as_ref(),
   30         -
                input,
   31         -
            )?;
   32         -
        }
   33         -
        input.build()?
   34         -
    })
   35         -
}
   36         -
   37         -
#[allow(clippy::unnecessary_wraps)]
   38         -
pub fn ser_test_operation_http_response(
   39         -
    #[allow(unused_variables)] output: crate::output::TestOperationOutput,
   40         -
) -> std::result::Result<
   41         -
    ::aws_smithy_http_server::response::Response,
   42         -
    ::aws_smithy_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_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_http::header::set_response_header_if_absent(
   57         -
            builder,
   58         -
            ::http::header::CONTENT_LENGTH,
   59         -
            content_length,
   60         -
        );
   61         -
        let body = ::aws_smithy_http_server::body::to_boxed(payload);
   62         -
        builder.body(body)?
   63         -
    })
   64         -
}
   65         -
   66         -
#[allow(clippy::unnecessary_wraps)]
   67         -
pub fn ser_test_operation_http_error(
   68         -
    error: &crate::error::TestOperationError,
   69         -
) -> std::result::Result<
   70         -
    ::aws_smithy_http_server::response::Response,
   71         -
    ::aws_smithy_http_server::protocol::rest_json_1::rejection::ResponseRejection,
   72         -
> {
   73         -
    Ok({
   74         -
        match error {
   75         -
            crate::error::TestOperationError::MyCustomValidationException(output) => {
   76         -
                let payload = crate::protocol_serde::shape_my_custom_validation_exception::ser_my_custom_validation_exception_error(output)?;
   77         -
                #[allow(unused_mut)]
   78         -
                let mut builder = ::http::Response::builder();
   79         -
                builder = ::aws_smithy_http::header::set_response_header_if_absent(
   80         -
                    builder,
   81         -
                    ::http::header::CONTENT_TYPE,
   82         -
                    "application/json",
   83         -
                );
   84         -
                builder = ::aws_smithy_http::header::set_response_header_if_absent(
   85         -
                    builder,
   86         -
                    ::http::header::HeaderName::from_static("x-amzn-errortype"),
   87         -
                    "MyCustomValidationException",
   88         -
                );
   89         -
                let content_length = payload.len();
   90         -
                builder = ::aws_smithy_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_http_server::body::to_boxed(payload))?
   98         -
            }
   99         -
        }
  100         -
    })
  101         -
}
  102         -
  103         -
pub(crate) fn de_test_operation(
  104         -
    value: &[u8],
  105         -
    mut builder: crate::input::test_operation_input::Builder,
  106         -
) -> ::std::result::Result<
  107         -
    crate::input::test_operation_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         -
                    "age" => {
  121         -
                        builder = builder.set_age(
  122         -
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(
  123         -
                                tokens.next(),
  124         -
                            )?
  125         -
                            .map(i32::try_from)
  126         -
                            .transpose()?,
  127         -
                        );
  128         -
                    }
  129         -
                    "name" => {
  130         -
                        if let Some(v) =
  131         -
                            ::aws_smithy_json::deserialize::token::expect_string_or_null(
  132         -
                                tokens.next(),
  133         -
                            )?
  134         -
                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
  135         -
                            .transpose()?
  136         -
                        {
  137         -
                            builder = builder.set_name(v);
  138         -
                        }
  139         -
                    }
  140         -
                    _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
  141         -
                }
  142         -
            }
  143         -
            other => {
  144         -
                return Err(
  145         -
                    ::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
  146         -
                        "expected object key or end object, found: {:?}",
  147         -
                        other
  148         -
                    )),
  149         -
                )
  150         -
            }
  151         -
        }
  152         -
    }
  153         -
    if tokens.next().is_some() {
  154         -
        return Err(
  155         -
            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
  156         -
                "found more JSON tokens after completing parsing",
  157         -
            ),
  158         -
        );
  159         -
    }
  160         -
    Ok(builder)
  161         -
}

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/src/service.rs

@@ -1,0 +723,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
/// The service builder for [`CustomValidationExample`].
    3         -
///
    4         -
/// Constructed via [`CustomValidationExample::builder`].
    5         -
pub struct CustomValidationExampleBuilder<Body, L, HttpPl, ModelPl> {
    6         -
    test_operation: Option<::aws_smithy_http_server::routing::Route<Body>>,
    7         -
    layer: L,
    8         -
    http_plugin: HttpPl,
    9         -
    model_plugin: ModelPl,
   10         -
}
   11         -
   12         -
impl<Body, L, HttpPl, ModelPl> CustomValidationExampleBuilder<Body, L, HttpPl, ModelPl> {
   13         -
    /// Sets the [`TestOperation`](crate::operation_shape::TestOperation) operation.
   14         -
    ///
   15         -
    /// This should be an async function satisfying the [`Handler`](::aws_smithy_http_server::operation::Handler) trait.
   16         -
    /// See the [operation module documentation](::aws_smithy_http_server::operation) for more information.
   17         -
    ///
   18         -
    /// # Example
   19         -
    ///
   20         -
    /// ```no_run
   21         -
    /// use custom_validation_exception_example::{CustomValidationExample, CustomValidationExampleConfig};
   22         -
    ///
   23         -
    /// use custom_validation_exception_example::{input, output, error};
   24         -
    ///
   25         -
    /// async fn handler(input: input::TestOperationInput) -> Result<output::TestOperationOutput, error::TestOperationError> {
   26         -
    ///     todo!()
   27         -
    /// }
   28         -
    ///
   29         -
    /// let config = CustomValidationExampleConfig::builder().build();
   30         -
    /// let app = CustomValidationExample::builder(config)
   31         -
    ///     .test_operation(handler)
   32         -
    ///     /* Set other handlers */
   33         -
    ///     .build()
   34         -
    ///     .unwrap();
   35         -
    /// # let app: CustomValidationExample<::aws_smithy_http_server::routing::RoutingService<::aws_smithy_http_server::protocol::rest::router::RestRouter<::aws_smithy_http_server::routing::Route>, ::aws_smithy_http_server::protocol::rest_json_1::RestJson1>> = app;
   36         -
    /// ```
   37         -
    ///
   38         -
                    pub fn test_operation<HandlerType, HandlerExtractors, UpgradeExtractors>(self, handler: HandlerType) -> Self
   39         -
                    where
   40         -
                        HandlerType: ::aws_smithy_http_server::operation::Handler<crate::operation_shape::TestOperation, HandlerExtractors>,
   41         -
   42         -
                        ModelPl: ::aws_smithy_http_server::plugin::Plugin<
   43         -
                            CustomValidationExample<L>,
   44         -
                            crate::operation_shape::TestOperation,
   45         -
                            ::aws_smithy_http_server::operation::IntoService<crate::operation_shape::TestOperation, HandlerType>
   46         -
                        >,
   47         -
                        ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>: ::aws_smithy_http_server::plugin::Plugin<
   48         -
                            CustomValidationExample<L>,
   49         -
                            crate::operation_shape::TestOperation,
   50         -
                            ModelPl::Output
   51         -
                        >,
   52         -
                        HttpPl: ::aws_smithy_http_server::plugin::Plugin<
   53         -
                            CustomValidationExample<L>,
   54         -
                            crate::operation_shape::TestOperation,
   55         -
                            <
   56         -
                                ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>
   57         -
                                as ::aws_smithy_http_server::plugin::Plugin<
   58         -
                                    CustomValidationExample<L>,
   59         -
                                    crate::operation_shape::TestOperation,
   60         -
                                    ModelPl::Output
   61         -
                                >
   62         -
                            >::Output
   63         -
                        >,
   64         -
   65         -
                        HttpPl::Output: ::tower::Service<::http::Request<Body>, Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>, Error = ::std::convert::Infallible> + Clone + Send + 'static,
   66         -
                        <HttpPl::Output as ::tower::Service<::http::Request<Body>>>::Future: Send + 'static,
   67         -
   68         -
                    {
   69         -
        use ::aws_smithy_http_server::operation::OperationShapeExt;
   70         -
        use ::aws_smithy_http_server::plugin::Plugin;
   71         -
        let svc = crate::operation_shape::TestOperation::from_handler(handler);
   72         -
        let svc = self.model_plugin.apply(svc);
   73         -
        let svc = ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>::new()
   74         -
            .apply(svc);
   75         -
        let svc = self.http_plugin.apply(svc);
   76         -
        self.test_operation_custom(svc)
   77         -
    }
   78         -
   79         -
    /// Sets the [`TestOperation`](crate::operation_shape::TestOperation) operation.
   80         -
    ///
   81         -
    /// This should be an async function satisfying the [`Handler`](::aws_smithy_http_server::operation::Handler) trait.
   82         -
    /// See the [operation module documentation](::aws_smithy_http_server::operation) for more information.
   83         -
    ///
   84         -
    /// # Example
   85         -
    ///
   86         -
    /// ```no_run
   87         -
    /// use custom_validation_exception_example::{CustomValidationExample, CustomValidationExampleConfig};
   88         -
    ///
   89         -
    /// use custom_validation_exception_example::{input, output, error};
   90         -
    ///
   91         -
    /// async fn handler(input: input::TestOperationInput) -> Result<output::TestOperationOutput, error::TestOperationError> {
   92         -
    ///     todo!()
   93         -
    /// }
   94         -
    ///
   95         -
    /// let config = CustomValidationExampleConfig::builder().build();
   96         -
    /// let svc = ::tower::util::service_fn(handler);
   97         -
    /// let app = CustomValidationExample::builder(config)
   98         -
    ///     .test_operation_service(svc)
   99         -
    ///     /* Set other handlers */
  100         -
    ///     .build()
  101         -
    ///     .unwrap();
  102         -
    /// # let app: CustomValidationExample<::aws_smithy_http_server::routing::RoutingService<::aws_smithy_http_server::protocol::rest::router::RestRouter<::aws_smithy_http_server::routing::Route>, ::aws_smithy_http_server::protocol::rest_json_1::RestJson1>> = app;
  103         -
    /// ```
  104         -
    ///
  105         -
                    pub fn test_operation_service<S, ServiceExtractors, UpgradeExtractors>(self, service: S) -> Self
  106         -
                    where
  107         -
                        S: ::aws_smithy_http_server::operation::OperationService<crate::operation_shape::TestOperation, ServiceExtractors>,
  108         -
  109         -
                        ModelPl: ::aws_smithy_http_server::plugin::Plugin<
  110         -
                            CustomValidationExample<L>,
  111         -
                            crate::operation_shape::TestOperation,
  112         -
                            ::aws_smithy_http_server::operation::Normalize<crate::operation_shape::TestOperation, S>
  113         -
                        >,
  114         -
                        ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>: ::aws_smithy_http_server::plugin::Plugin<
  115         -
                            CustomValidationExample<L>,
  116         -
                            crate::operation_shape::TestOperation,
  117         -
                            ModelPl::Output
  118         -
                        >,
  119         -
                        HttpPl: ::aws_smithy_http_server::plugin::Plugin<
  120         -
                            CustomValidationExample<L>,
  121         -
                            crate::operation_shape::TestOperation,
  122         -
                            <
  123         -
                                ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>
  124         -
                                as ::aws_smithy_http_server::plugin::Plugin<
  125         -
                                    CustomValidationExample<L>,
  126         -
                                    crate::operation_shape::TestOperation,
  127         -
                                    ModelPl::Output
  128         -
                                >
  129         -
                            >::Output
  130         -
                        >,
  131         -
  132         -
                        HttpPl::Output: ::tower::Service<::http::Request<Body>, Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>, Error = ::std::convert::Infallible> + Clone + Send + 'static,
  133         -
                        <HttpPl::Output as ::tower::Service<::http::Request<Body>>>::Future: Send + 'static,
  134         -
  135         -
                    {
  136         -
        use ::aws_smithy_http_server::operation::OperationShapeExt;
  137         -
        use ::aws_smithy_http_server::plugin::Plugin;
  138         -
        let svc = crate::operation_shape::TestOperation::from_service(service);
  139         -
        let svc = self.model_plugin.apply(svc);
  140         -
        let svc = ::aws_smithy_http_server::operation::UpgradePlugin::<UpgradeExtractors>::new()
  141         -
            .apply(svc);
  142         -
        let svc = self.http_plugin.apply(svc);
  143         -
        self.test_operation_custom(svc)
  144         -
    }
  145         -
  146         -
    /// Sets the [`TestOperation`](crate::operation_shape::TestOperation) to a custom [`Service`](tower::Service).
  147         -
    /// not constrained by the Smithy contract.
  148         -
    fn test_operation_custom<S>(mut self, svc: S) -> Self
  149         -
    where
  150         -
        S: ::tower::Service<
  151         -
                ::http::Request<Body>,
  152         -
                Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>,
  153         -
                Error = ::std::convert::Infallible,
  154         -
            > + Clone
  155         -
            + Send
  156         -
            + 'static,
  157         -
        S::Future: Send + 'static,
  158         -
    {
  159         -
        self.test_operation = Some(::aws_smithy_http_server::routing::Route::new(svc));
  160         -
        self
  161         -
    }
  162         -
}
  163         -
  164         -
impl<Body, L, HttpPl, ModelPl> CustomValidationExampleBuilder<Body, L, HttpPl, ModelPl> {
  165         -
    /// Constructs a [`CustomValidationExample`] from the arguments provided to the builder.
  166         -
    ///
  167         -
    /// Forgetting to register a handler for one or more operations will result in an error.
  168         -
    ///
  169         -
    /// Check out [`CustomValidationExampleBuilder::build_unchecked`] if you'd prefer the service to return status code 500 when an
  170         -
    /// unspecified route is requested.
  171         -
    pub fn build(
  172         -
        self,
  173         -
    ) -> ::std::result::Result<
  174         -
        CustomValidationExample<
  175         -
            ::aws_smithy_http_server::routing::RoutingService<
  176         -
                ::aws_smithy_http_server::protocol::rest::router::RestRouter<L::Service>,
  177         -
                ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
  178         -
            >,
  179         -
        >,
  180         -
        MissingOperationsError,
  181         -
    >
  182         -
    where
  183         -
        L: ::tower::Layer<::aws_smithy_http_server::routing::Route<Body>>,
  184         -
    {
  185         -
        let router = {
  186         -
            use ::aws_smithy_http_server::operation::OperationShape;
  187         -
            let mut missing_operation_names = std::collections::HashMap::new();
  188         -
            if self.test_operation.is_none() {
  189         -
                missing_operation_names.insert(
  190         -
                    crate::operation_shape::TestOperation::ID,
  191         -
                    ".test_operation()",
  192         -
                );
  193         -
            }
  194         -
            if !missing_operation_names.is_empty() {
  195         -
                return Err(MissingOperationsError {
  196         -
                    operation_names2setter_methods: missing_operation_names,
  197         -
                });
  198         -
            }
  199         -
            let unexpected_error_msg = "this should never panic since we are supposed to check beforehand that a handler has been registered for this operation; please file a bug report under https://github.com/smithy-lang/smithy-rs/issues";
  200         -
  201         -
            ::aws_smithy_http_server::protocol::rest::router::RestRouter::from_iter([(
  202         -
                request_specs::test_operation(),
  203         -
                self.test_operation.expect(unexpected_error_msg),
  204         -
            )])
  205         -
        };
  206         -
        let svc = ::aws_smithy_http_server::routing::RoutingService::new(router);
  207         -
        let svc = svc.map(|s| s.layer(self.layer));
  208         -
        Ok(CustomValidationExample { svc })
  209         -
    }
  210         -
  211         -
    /// Constructs a [`CustomValidationExample`] from the arguments provided to the builder.
  212         -
    /// Operations without a handler default to returning 500 Internal Server Error to the caller.
  213         -
    ///
  214         -
    /// Check out [`CustomValidationExampleBuilder::build`] if you'd prefer the builder to fail if one or more operations do
  215         -
    /// not have a registered handler.
  216         -
    pub fn build_unchecked(self) -> CustomValidationExample<L::Service>
  217         -
    where
  218         -
        Body: Send + 'static,
  219         -
        L: ::tower::Layer<
  220         -
            ::aws_smithy_http_server::routing::RoutingService<
  221         -
                ::aws_smithy_http_server::protocol::rest::router::RestRouter<
  222         -
                    ::aws_smithy_http_server::routing::Route<Body>,
  223         -
                >,
  224         -
                ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
  225         -
            >,
  226         -
        >,
  227         -
    {
  228         -
        let router = ::aws_smithy_http_server::protocol::rest::router::RestRouter::from_iter([(
  229         -
            request_specs::test_operation(),
  230         -
            self.test_operation.unwrap_or_else(|| {
  231         -
                let svc = ::aws_smithy_http_server::operation::MissingFailure::<
  232         -
                    ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
  233         -
                >::default();
  234         -
                ::aws_smithy_http_server::routing::Route::new(svc)
  235         -
            }),
  236         -
        )]);
  237         -
        let svc = self
  238         -
            .layer
  239         -
            .layer(::aws_smithy_http_server::routing::RoutingService::new(
  240         -
                router,
  241         -
            ));
  242         -
        CustomValidationExample { svc }
  243         -
    }
  244         -
}
  245         -
  246         -
/// The error encountered when calling the [`CustomValidationExampleBuilder::build`] method if one or more operation handlers are not
  247         -
/// specified.
  248         -
#[derive(Debug)]
  249         -
pub struct MissingOperationsError {
  250         -
    operation_names2setter_methods:
  251         -
        std::collections::HashMap<::aws_smithy_http_server::shape_id::ShapeId, &'static str>,
  252         -
}
  253         -
  254         -
impl std::fmt::Display for MissingOperationsError {
  255         -
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  256         -
        write!(
  257         -
                            f,
  258         -
                            "You must specify a handler for all operations attached to `CustomValidationExample`.\n\
  259         -
                            We are missing handlers for the following operations:\n",
  260         -
                        )?;
  261         -
        for operation_name in self.operation_names2setter_methods.keys() {
  262         -
            writeln!(f, "- {}", operation_name.absolute())?;
  263         -
        }
  264         -
  265         -
        writeln!(f, "\nUse the dedicated methods on `CustomValidationExampleBuilder` to register the missing handlers:")?;
  266         -
        for setter_name in self.operation_names2setter_methods.values() {
  267         -
            writeln!(f, "- {}", setter_name)?;
  268         -
        }
  269         -
        Ok(())
  270         -
    }
  271         -
}
  272         -
  273         -
impl std::error::Error for MissingOperationsError {}
  274         -
  275         -
mod request_specs {
  276         -
    pub(super) fn test_operation() -> ::aws_smithy_http_server::routing::request_spec::RequestSpec {
  277         -
        ::aws_smithy_http_server::routing::request_spec::RequestSpec::new(
  278         -
                    ::http::Method::POST,
  279         -
                    ::aws_smithy_http_server::routing::request_spec::UriSpec::new(
  280         -
                        ::aws_smithy_http_server::routing::request_spec::PathAndQuerySpec::new(
  281         -
                            ::aws_smithy_http_server::routing::request_spec::PathSpec::from_vector_unchecked(vec![
  282         -
    ::aws_smithy_http_server::routing::request_spec::PathSegment::Literal(String::from("test")),
  283         -
]),
  284         -
                            ::aws_smithy_http_server::routing::request_spec::QuerySpec::from_vector_unchecked(vec![
  285         -
])
  286         -
                        )
  287         -
                    ),
  288         -
                )
  289         -
    }
  290         -
}
  291         -
  292         -
#[allow(missing_docs)] // documentation missing in model
  293         -
///
  294         -
/// See the [root](crate) documentation for more information.
  295         -
#[derive(Clone)]
  296         -
pub struct CustomValidationExample<
  297         -
    S = ::aws_smithy_http_server::routing::RoutingService<
  298         -
        ::aws_smithy_http_server::protocol::rest::router::RestRouter<
  299         -
            ::aws_smithy_http_server::routing::Route<::aws_smithy_http_server::body::BoxBody>,
  300         -
        >,
  301         -
        ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
  302         -
    >,
  303         -
> {
  304         -
    // This is the router wrapped by layers.
  305         -
    svc: S,
  306         -
}
  307         -
  308         -
impl CustomValidationExample<()> {
  309         -
    /// Constructs a builder for [`CustomValidationExample`].
  310         -
    /// You must specify a configuration object holding any plugins and layers that should be applied
  311         -
    /// to the operations in this service.
  312         -
    pub fn builder<
  313         -
        Body,
  314         -
        L,
  315         -
        HttpPl: ::aws_smithy_http_server::plugin::HttpMarker,
  316         -
        ModelPl: ::aws_smithy_http_server::plugin::ModelMarker,
  317         -
    >(
  318         -
        config: CustomValidationExampleConfig<L, HttpPl, ModelPl>,
  319         -
    ) -> CustomValidationExampleBuilder<Body, L, HttpPl, ModelPl> {
  320         -
        CustomValidationExampleBuilder {
  321         -
            test_operation: None,
  322         -
            layer: config.layers,
  323         -
            http_plugin: config.http_plugins,
  324         -
            model_plugin: config.model_plugins,
  325         -
        }
  326         -
    }
  327         -
  328         -
    /// Constructs a builder for [`CustomValidationExample`].
  329         -
    /// You must specify what plugins should be applied to the operations in this service.
  330         -
    ///
  331         -
    /// Use [`CustomValidationExample::builder_without_plugins`] if you don't need to apply plugins.
  332         -
    ///
  333         -
    /// Check out [`HttpPlugins`](::aws_smithy_http_server::plugin::HttpPlugins) and
  334         -
    /// [`ModelPlugins`](::aws_smithy_http_server::plugin::ModelPlugins) if you need to apply
  335         -
    /// multiple plugins.
  336         -
    #[deprecated(
  337         -
        since = "0.57.0",
  338         -
        note = "please use the `builder` constructor and register plugins on the `CustomValidationExampleConfig` object instead; see https://github.com/smithy-lang/smithy-rs/discussions/3096"
  339         -
    )]
  340         -
    pub fn builder_with_plugins<
  341         -
        Body,
  342         -
        HttpPl: ::aws_smithy_http_server::plugin::HttpMarker,
  343         -
        ModelPl: ::aws_smithy_http_server::plugin::ModelMarker,
  344         -
    >(
  345         -
        http_plugin: HttpPl,
  346         -
        model_plugin: ModelPl,
  347         -
    ) -> CustomValidationExampleBuilder<Body, ::tower::layer::util::Identity, HttpPl, ModelPl> {
  348         -
        CustomValidationExampleBuilder {
  349         -
            test_operation: None,
  350         -
            layer: ::tower::layer::util::Identity::new(),
  351         -
            http_plugin,
  352         -
            model_plugin,
  353         -
        }
  354         -
    }
  355         -
  356         -
    /// Constructs a builder for [`CustomValidationExample`].
  357         -
    ///
  358         -
    /// Use [`CustomValidationExample::builder_with_plugins`] if you need to specify plugins.
  359         -
    #[deprecated(
  360         -
        since = "0.57.0",
  361         -
        note = "please use the `builder` constructor instead; see https://github.com/smithy-lang/smithy-rs/discussions/3096"
  362         -
    )]
  363         -
    pub fn builder_without_plugins<Body>() -> CustomValidationExampleBuilder<
  364         -
        Body,
  365         -
        ::tower::layer::util::Identity,
  366         -
        ::aws_smithy_http_server::plugin::IdentityPlugin,
  367         -
        ::aws_smithy_http_server::plugin::IdentityPlugin,
  368         -
    > {
  369         -
        Self::builder_with_plugins(
  370         -
            ::aws_smithy_http_server::plugin::IdentityPlugin,
  371         -
            ::aws_smithy_http_server::plugin::IdentityPlugin,
  372         -
        )
  373         -
    }
  374         -
}
  375         -
  376         -
impl<S> CustomValidationExample<S> {
  377         -
    /// Converts [`CustomValidationExample`] into a [`MakeService`](tower::make::MakeService).
  378         -
    pub fn into_make_service(self) -> ::aws_smithy_http_server::routing::IntoMakeService<Self> {
  379         -
        ::aws_smithy_http_server::routing::IntoMakeService::new(self)
  380         -
    }
  381         -
  382         -
    /// Converts [`CustomValidationExample`] into a [`MakeService`](tower::make::MakeService) with [`ConnectInfo`](::aws_smithy_http_server::request::connect_info::ConnectInfo).
  383         -
    pub fn into_make_service_with_connect_info<C>(
  384         -
        self,
  385         -
    ) -> ::aws_smithy_http_server::routing::IntoMakeServiceWithConnectInfo<Self, C> {
  386         -
        ::aws_smithy_http_server::routing::IntoMakeServiceWithConnectInfo::new(self)
  387         -
    }
  388         -
}
  389         -
  390         -
impl<S>
  391         -
    CustomValidationExample<
  392         -
        ::aws_smithy_http_server::routing::RoutingService<
  393         -
            ::aws_smithy_http_server::protocol::rest::router::RestRouter<S>,
  394         -
            ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
  395         -
        >,
  396         -
    >
  397         -
{
  398         -
    /// Applies a [`Layer`](::tower::Layer) uniformly to all routes.
  399         -
    #[deprecated(
  400         -
        since = "0.57.0",
  401         -
        note = "please add layers to the `CustomValidationExampleConfig` object instead; see https://github.com/smithy-lang/smithy-rs/discussions/3096"
  402         -
    )]
  403         -
    pub fn layer<L>(
  404         -
        self,
  405         -
        layer: &L,
  406         -
    ) -> CustomValidationExample<
  407         -
        ::aws_smithy_http_server::routing::RoutingService<
  408         -
            ::aws_smithy_http_server::protocol::rest::router::RestRouter<L::Service>,
  409         -
            ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
  410         -
        >,
  411         -
    >
  412         -
    where
  413         -
        L: ::tower::Layer<S>,
  414         -
    {
  415         -
        CustomValidationExample {
  416         -
            svc: self.svc.map(|s| s.layer(layer)),
  417         -
        }
  418         -
    }
  419         -
  420         -
    /// Applies [`Route::new`](::aws_smithy_http_server::routing::Route::new) to all routes.
  421         -
    ///
  422         -
    /// This has the effect of erasing all types accumulated via layers.
  423         -
    pub fn boxed<B>(
  424         -
        self,
  425         -
    ) -> CustomValidationExample<
  426         -
        ::aws_smithy_http_server::routing::RoutingService<
  427         -
            ::aws_smithy_http_server::protocol::rest::router::RestRouter<
  428         -
                ::aws_smithy_http_server::routing::Route<B>,
  429         -
            >,
  430         -
            ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
  431         -
        >,
  432         -
    >
  433         -
    where
  434         -
        S: ::tower::Service<
  435         -
            ::http::Request<B>,
  436         -
            Response = ::http::Response<::aws_smithy_http_server::body::BoxBody>,
  437         -
            Error = std::convert::Infallible,
  438         -
        >,
  439         -
        S: Clone + Send + 'static,
  440         -
        S::Future: Send + 'static,
  441         -
    {
  442         -
        self.layer(&::tower::layer::layer_fn(
  443         -
            ::aws_smithy_http_server::routing::Route::new,
  444         -
        ))
  445         -
    }
  446         -
}
  447         -
  448         -
impl<S, R> ::tower::Service<R> for CustomValidationExample<S>
  449         -
where
  450         -
    S: ::tower::Service<R>,
  451         -
{
  452         -
    type Response = S::Response;
  453         -
    type Error = S::Error;
  454         -
    type Future = S::Future;
  455         -
  456         -
    fn poll_ready(
  457         -
        &mut self,
  458         -
        cx: &mut std::task::Context,
  459         -
    ) -> std::task::Poll<::std::result::Result<(), Self::Error>> {
  460         -
        self.svc.poll_ready(cx)
  461         -
    }
  462         -
  463         -
    fn call(&mut self, request: R) -> Self::Future {
  464         -
        self.svc.call(request)
  465         -
    }
  466         -
}
  467         -
  468         -
/// An enumeration of all [operations](https://smithy.io/2.0/spec/service-types.html#operation) in CustomValidationExample.
  469         -
#[allow(clippy::enum_variant_names)]
  470         -
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
  471         -
pub enum Operation {
  472         -
    TestOperation,
  473         -
}
  474         -
  475         -
impl Operation {
  476         -
    /// Returns the [operations](https://smithy.io/2.0/spec/service-types.html#operation) [`ShapeId`](::aws_smithy_http_server::shape_id::ShapeId).
  477         -
    pub fn shape_id(&self) -> ::aws_smithy_http_server::shape_id::ShapeId {
  478         -
        match self {
  479         -
            Operation::TestOperation => ::aws_smithy_http_server::shape_id::ShapeId::new(
  480         -
                "com.aws.example#TestOperation",
  481         -
                "com.aws.example",
  482         -
                "TestOperation",
  483         -
            ),
  484         -
        }
  485         -
    }
  486         -
}
  487         -
impl<L> ::aws_smithy_http_server::service::ContainsOperation<crate::operation_shape::TestOperation>
  488         -
    for CustomValidationExample<L>
  489         -
{
  490         -
    const VALUE: Operation = Operation::TestOperation;
  491         -
}
  492         -
  493         -
impl<S> ::aws_smithy_http_server::service::ServiceShape for CustomValidationExample<S> {
  494         -
    const ID: ::aws_smithy_http_server::shape_id::ShapeId =
  495         -
        ::aws_smithy_http_server::shape_id::ShapeId::new(
  496         -
            "com.aws.example#CustomValidationExample",
  497         -
            "com.aws.example",
  498         -
            "CustomValidationExample",
  499         -
        );
  500         -
  501         -
    const VERSION: Option<&'static str> = Some("1.0.0");
  502         -
  503         -
    type Protocol = ::aws_smithy_http_server::protocol::rest_json_1::RestJson1;
  504         -
  505         -
    type Operations = Operation;
  506         -
}
  507         -
/// Configuration for the [`CustomValidationExample`]. This is the central place where to register and
  508         -
/// configure [`::tower::Layer`]s, HTTP plugins, and model plugins.
  509         -
///
  510         -
/// ```rust,no_run
  511         -
/// # use custom_validation_exception_example::CustomValidationExampleConfig;
  512         -
/// # use ::aws_smithy_http_server::plugin::IdentityPlugin;
  513         -
/// # use ::tower::layer::util::Identity;
  514         -
/// # let authentication_plugin = IdentityPlugin;
  515         -
/// # let authorization_plugin = IdentityPlugin;
  516         -
/// # let server_request_id_provider_layer = Identity::new();
  517         -
/// let config = CustomValidationExampleConfig::builder()
  518         -
///     // Layers get executed first...
  519         -
///     .layer(server_request_id_provider_layer)
  520         -
///     // ...then HTTP plugins...
  521         -
///     .http_plugin(authentication_plugin)
  522         -
///     // ...and right after deserialization, model plugins.
  523         -
///     .model_plugin(authorization_plugin)
  524         -
///     .build();
  525         -
/// ```
  526         -
///
  527         -
/// See the [`plugin`] system for details.
  528         -
///
  529         -
/// [`plugin`]: ::aws_smithy_http_server::plugin
  530         -
#[derive(::std::fmt::Debug)]
  531         -
pub struct CustomValidationExampleConfig<L, H, M> {
  532         -
    layers: L,
  533         -
    http_plugins: H,
  534         -
    model_plugins: M,
  535         -
}
  536         -
  537         -
impl CustomValidationExampleConfig<(), (), ()> {
  538         -
    /// Returns a builder to construct the configuration.
  539         -
    pub fn builder() -> CustomValidationExampleConfigBuilder<
  540         -
        ::tower::layer::util::Identity,
  541         -
        ::aws_smithy_http_server::plugin::IdentityPlugin,
  542         -
        ::aws_smithy_http_server::plugin::IdentityPlugin,
  543         -
    > {
  544         -
        CustomValidationExampleConfigBuilder {
  545         -
            layers: ::tower::layer::util::Identity::new(),
  546         -
            http_plugins: ::aws_smithy_http_server::plugin::IdentityPlugin,
  547         -
            model_plugins: ::aws_smithy_http_server::plugin::IdentityPlugin,
  548         -
        }
  549         -
    }
  550         -
}
  551         -
  552         -
/// Builder returned by [`CustomValidationExampleConfig::builder()`].
  553         -
#[derive(::std::fmt::Debug)]
  554         -
pub struct CustomValidationExampleConfigBuilder<L, H, M> {
  555         -
    pub(crate) layers: L,
  556         -
    pub(crate) http_plugins: H,
  557         -
    pub(crate) model_plugins: M,
  558         -
}
  559         -
  560         -
impl<L, H, M> CustomValidationExampleConfigBuilder<L, H, M> {
  561         -
    /// Add a [`::tower::Layer`] to the service.
  562         -
    pub fn layer<NewLayer>(
  563         -
        self,
  564         -
        layer: NewLayer,
  565         -
    ) -> CustomValidationExampleConfigBuilder<::tower::layer::util::Stack<NewLayer, L>, H, M> {
  566         -
        CustomValidationExampleConfigBuilder {
  567         -
            layers: ::tower::layer::util::Stack::new(layer, self.layers),
  568         -
            http_plugins: self.http_plugins,
  569         -
            model_plugins: self.model_plugins,
  570         -
        }
  571         -
    }
  572         -
  573         -
    /// Add a HTTP [plugin] to the service.
  574         -
    ///
  575         -
    /// [plugin]: ::aws_smithy_http_server::plugin
  576         -
    // We eagerly require `NewPlugin: HttpMarker`, despite not really needing it, because compiler
  577         -
    // errors get _substantially_ better if the user makes a mistake.
  578         -
    pub fn http_plugin<NewPlugin: ::aws_smithy_http_server::plugin::HttpMarker>(
  579         -
        self,
  580         -
        http_plugin: NewPlugin,
  581         -
    ) -> CustomValidationExampleConfigBuilder<
  582         -
        L,
  583         -
        ::aws_smithy_http_server::plugin::PluginStack<NewPlugin, H>,
  584         -
        M,
  585         -
    > {
  586         -
        CustomValidationExampleConfigBuilder {
  587         -
            layers: self.layers,
  588         -
            http_plugins: ::aws_smithy_http_server::plugin::PluginStack::new(
  589         -
                http_plugin,
  590         -
                self.http_plugins,
  591         -
            ),
  592         -
            model_plugins: self.model_plugins,
  593         -
        }
  594         -
    }
  595         -
  596         -
    /// Add a model [plugin] to the service.
  597         -
    ///
  598         -
    /// [plugin]: ::aws_smithy_http_server::plugin
  599         -
    // We eagerly require `NewPlugin: ModelMarker`, despite not really needing it, because compiler
  600         -
    // errors get _substantially_ better if the user makes a mistake.
  601         -
    pub fn model_plugin<NewPlugin: ::aws_smithy_http_server::plugin::ModelMarker>(
  602         -
        self,
  603         -
        model_plugin: NewPlugin,
  604         -
    ) -> CustomValidationExampleConfigBuilder<
  605         -
        L,
  606         -
        H,
  607         -
        ::aws_smithy_http_server::plugin::PluginStack<NewPlugin, M>,
  608         -
    > {
  609         -
        CustomValidationExampleConfigBuilder {
  610         -
            layers: self.layers,
  611         -
            http_plugins: self.http_plugins,
  612         -
            model_plugins: ::aws_smithy_http_server::plugin::PluginStack::new(
  613         -
                model_plugin,
  614         -
                self.model_plugins,
  615         -
            ),
  616         -
        }
  617         -
    }
  618         -
  619         -
    /// Build the configuration.
  620         -
    pub fn build(self) -> super::CustomValidationExampleConfig<L, H, M> {
  621         -
        super::CustomValidationExampleConfig {
  622         -
            layers: self.layers,
  623         -
            http_plugins: self.http_plugins,
  624         -
            model_plugins: self.model_plugins,
  625         -
        }
  626         -
    }
  627         -
}
  628         -
/// A macro to help with scoping [plugins](crate::server::plugin) to a subset of all operations.
  629         -
///
  630         -
/// In contrast to [`crate::server::scope`](crate::server::scope), this macro has knowledge
  631         -
/// of the service and any operations _not_ specified will be placed in the opposing group.
  632         -
///
  633         -
/// # Example
  634         -
///
  635         -
/// ```rust
  636         -
/// scope! {
  637         -
///     /// Includes [`TestOperation`], excluding all other operations.
  638         -
///     struct ScopeA {
  639         -
///         includes: [TestOperation]
  640         -
///     }
  641         -
/// }
  642         -
///
  643         -
/// scope! {
  644         -
///     /// Excludes [`TestOperation`], excluding all other operations.
  645         -
///     struct ScopeB {
  646         -
///         excludes: [TestOperation]
  647         -
///     }
  648         -
/// }
  649         -
///
  650         -
/// # use custom_validation_exception_example::server::plugin::{Plugin, Scoped};
  651         -
/// # use custom_validation_exception_example::scope;
  652         -
/// # struct MockPlugin;
  653         -
/// # impl<S, Op, T> Plugin<S, Op, T> for MockPlugin { type Output = u32; fn apply(&self, input: T) -> u32 { 3 } }
  654         -
/// # let scoped_a = Scoped::new::<ScopeA>(MockPlugin);
  655         -
/// # let scoped_b = Scoped::new::<ScopeB>(MockPlugin);
  656         -
/// # let a = Plugin::<(), custom_validation_exception_example::operation_shape::TestOperation, u64>::apply(&scoped_a, 6);
  657         -
/// # let b = Plugin::<(), custom_validation_exception_example::operation_shape::TestOperation, u64>::apply(&scoped_b, 6);
  658         -
/// # assert_eq!(a, 3_u32);
  659         -
/// # assert_eq!(b, 6_u64);
  660         -
/// ```
  661         -
#[macro_export]
  662         -
macro_rules! scope {
  663         -
                    // Completed, render impls
  664         -
                    (@ $ name: ident, $ contains: ident () ($($ temp: ident)*) ($($ not_member: ident)*)) => {
  665         -
                        $(
  666         -
                            impl $ crate::server::plugin::scoped::Membership<$ temp> for $ name {
  667         -
                                type Contains = $ crate::server::plugin::scoped::$ contains;
  668         -
                            }
  669         -
                        )*
  670         -
                        $(
  671         -
                            impl $ crate::server::plugin::scoped::Membership<$ not_member> for $ name {
  672         -
                                type Contains = $ crate::server::plugin::scoped::$ contains;
  673         -
                            }
  674         -
                        )*
  675         -
                    };
  676         -
                    // All `not_member`s exhausted, move `temp` into `not_member`
  677         -
                    (@ $ name: ident, $ contains: ident ($($ member: ident)*) ($($ temp: ident)*) ()) => {
  678         -
                        scope! { @ $ name, $ contains ($($ member)*) () ($($ temp)*) }
  679         -
                    };
  680         -
  681         -
                        // TestOperation match found, pop from both `member` and `not_member`
  682         -
                        (@ $ name: ident, $ contains: ident (TestOperation $($ member: ident)*) ($($ temp: ident)*) (TestOperation $($ not_member: ident)*)) => {
  683         -
                            scope! { @ $ name, $ contains ($($ member)*) ($($ temp)*) ($($ not_member)*) }
  684         -
                        };
  685         -
                        // TestOperation match not found, pop from `not_member` into `temp` stack
  686         -
                        (@ $ name: ident, $ contains: ident (TestOperation $($ member: ident)*) ($($ temp: ident)*) ($ other: ident $($ not_member: ident)*)) => {
  687         -
                            scope! { @ $ name, $ contains (TestOperation $($ member)*) ($ other $($ temp)*) ($($ not_member)*) }
  688         -
                        };
  689         -
  690         -
                    (
  691         -
                        $(#[$ attrs:meta])*
  692         -
                        $ vis:vis struct $ name:ident {
  693         -
                            includes: [$($ include:ident),*]
  694         -
                        }
  695         -
                    ) => {
  696         -
                        use $ crate::operation_shape::*;
  697         -
                        $ crate::server::scope! {
  698         -
                            $(#[$ attrs])*
  699         -
                            $ vis struct $ name {
  700         -
                                includes: [$($ include),*],
  701         -
                                excludes: []
  702         -
                            }
  703         -
                        }
  704         -
                        scope! { @ $ name, False ($($ include)*) () (TestOperation) }
  705         -
                    };
  706         -
                    (
  707         -
                        $(#[$ attrs:meta])*
  708         -
                        $ vis:vis struct $ name:ident {
  709         -
                            excludes: [$($ exclude:ident),*]
  710         -
                        }
  711         -
                    ) => {
  712         -
                        use $ crate::operation_shape::*;
  713         -
  714         -
                        $ crate::server::scope! {
  715         -
                            $(#[$ attrs])*
  716         -
                            $ vis struct $ name {
  717         -
                                includes: [],
  718         -
                                excludes: [$($ exclude),*]
  719         -
                            }
  720         -
                        }
  721         -
                        scope! { @ $ name, True ($($ exclude)*) () (TestOperation) }
  722         -
                    };
  723         -
                }