Server Test

Server Test

rev. 3c756f73b1f83a0eed4275d9d1e22df0b10b66fb

Files changed:

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

@@ -0,1 +0,248 @@
           1  +
#![allow(deprecated)]
           2  +
#![allow(unknown_lints)]
           3  +
#![allow(clippy::module_inception)]
           4  +
#![allow(clippy::upper_case_acronyms)]
           5  +
#![allow(clippy::large_enum_variant)]
           6  +
#![allow(clippy::wrong_self_convention)]
           7  +
#![allow(clippy::should_implement_trait)]
           8  +
#![allow(clippy::disallowed_names)]
           9  +
#![allow(clippy::vec_init_then_push)]
          10  +
#![allow(clippy::type_complexity)]
          11  +
#![allow(clippy::needless_return)]
          12  +
#![allow(clippy::derive_partial_eq_without_eq)]
          13  +
#![allow(clippy::result_large_err)]
          14  +
#![allow(clippy::unnecessary_map_on_constructor)]
          15  +
#![allow(clippy::deprecated_semver)]
          16  +
#![allow(clippy::uninlined_format_args)]
          17  +
#![allow(rustdoc::bare_urls)]
          18  +
#![allow(rustdoc::redundant_explicit_links)]
          19  +
#![allow(rustdoc::invalid_html_tags)]
          20  +
#![forbid(unsafe_code)]
          21  +
#![cfg_attr(docsrs, feature(doc_cfg))]
          22  +
//! custom-validation-exception-example-http0x
          23  +
          24  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
          25  +
//! A fast and customizable Rust implementation of the CustomValidationExample Smithy service.
          26  +
//!
          27  +
//! # Using CustomValidationExample
          28  +
//!
          29  +
//! The primary entrypoint is [`CustomValidationExample`]: it satisfies the [`Service<http::Request, Response = http::Response>`](::tower::Service)
          30  +
//! trait and therefore can be handed to a [`hyper` server](https://github.com/hyperium/hyper) via [`CustomValidationExample::into_make_service`]
          31  +
//! or used in AWS Lambda
          32  +
#![cfg_attr(
          33  +
    feature = "aws-lambda",
          34  +
    doc = " via [`LambdaHandler`](crate::server::routing::LambdaHandler)."
          35  +
)]
          36  +
#![cfg_attr(
          37  +
    not(feature = "aws-lambda"),
          38  +
    doc = " by enabling the `aws-lambda` feature flag and utilizing the `LambdaHandler`."
          39  +
)]
          40  +
//! The [`crate::input`], [`crate::output`], and [`crate::error`]
          41  +
//! modules provide the types used in each operation.
          42  +
//!
          43  +
//! ### Running on Hyper
          44  +
//!
          45  +
//! ```rust,no_run
          46  +
//! # use std::net::SocketAddr;
          47  +
//! # async fn dummy() {
          48  +
//! use custom_validation_exception_example_http0x::{CustomValidationExample, CustomValidationExampleConfig};
          49  +
//!
          50  +
//! # let app = CustomValidationExample::builder(
          51  +
//! #     CustomValidationExampleConfig::builder()
          52  +
//! #         .build()
          53  +
//! # ).build_unchecked();
          54  +
//! let server = app.into_make_service();
          55  +
//! let bind: SocketAddr = "127.0.0.1:6969".parse()
          56  +
//!     .expect("unable to parse the server bind address and port");
          57  +
//! ::hyper::Server::bind(&bind).serve(server).await.unwrap();
          58  +
//! # }
          59  +
//!
          60  +
//! ```
          61  +
//!
          62  +
//! ### Running on Lambda
          63  +
//!
          64  +
//! ```rust,ignore
          65  +
//! use custom_validation_exception_example_http0x::server::routing::LambdaHandler;
          66  +
//! use custom_validation_exception_example_http0x::CustomValidationExample;
          67  +
//!
          68  +
//! # async fn dummy() {
          69  +
//! # let app = CustomValidationExample::builder(
          70  +
//! #     CustomValidationExampleConfig::builder()
          71  +
//! #         .build()
          72  +
//! # ).build_unchecked();
          73  +
//! let handler = LambdaHandler::new(app);
          74  +
//! lambda_http::run(handler).await.unwrap();
          75  +
//! # }
          76  +
//! ```
          77  +
//!
          78  +
//! # Building the CustomValidationExample
          79  +
//!
          80  +
//! To construct [`CustomValidationExample`] we use [`CustomValidationExampleBuilder`] returned by [`CustomValidationExample::builder`].
          81  +
//!
          82  +
//! ## Plugins
          83  +
//!
          84  +
//! The [`CustomValidationExample::builder`] method, returning [`CustomValidationExampleBuilder`],
          85  +
//! accepts a config object on which plugins can be registered.
          86  +
//! Plugins allow you to build middleware which is aware of the operation it is being applied to.
          87  +
//!
          88  +
//! ```rust,no_run
          89  +
//! # use custom_validation_exception_example_http0x::server::plugin::IdentityPlugin as LoggingPlugin;
          90  +
//! # use custom_validation_exception_example_http0x::server::plugin::IdentityPlugin as MetricsPlugin;
          91  +
//! # use ::hyper::Body;
          92  +
//! use custom_validation_exception_example_http0x::server::plugin::HttpPlugins;
          93  +
//! use custom_validation_exception_example_http0x::{CustomValidationExample, CustomValidationExampleConfig, CustomValidationExampleBuilder};
          94  +
//!
          95  +
//! let http_plugins = HttpPlugins::new()
          96  +
//!         .push(LoggingPlugin)
          97  +
//!         .push(MetricsPlugin);
          98  +
//! let config = CustomValidationExampleConfig::builder().build();
          99  +
//! let builder: CustomValidationExampleBuilder<::hyper::Body, _, _, _> = CustomValidationExample::builder(config);
         100  +
//! ```
         101  +
//!
         102  +
//! Check out [`crate::server::plugin`] to learn more about plugins.
         103  +
//!
         104  +
//! ## Handlers
         105  +
//!
         106  +
//! [`CustomValidationExampleBuilder`] provides a setter method for each operation in your Smithy model. The setter methods expect an async function as input, matching the signature for the corresponding operation in your Smithy model.
         107  +
//! We call these async functions **handlers**. This is where your application business logic lives.
         108  +
//!
         109  +
//! Every handler must take an `Input`, and optional [`extractor arguments`](crate::server::request), while returning:
         110  +
//!
         111  +
//! * A `Result<Output, Error>` if your operation has modeled errors, or
         112  +
//! * An `Output` otherwise.
         113  +
//!
         114  +
//! ```rust,no_run
         115  +
//! # struct Input;
         116  +
//! # struct Output;
         117  +
//! # struct Error;
         118  +
//! async fn infallible_handler(input: Input) -> Output { todo!() }
         119  +
//!
         120  +
//! async fn fallible_handler(input: Input) -> Result<Output, Error> { todo!() }
         121  +
//! ```
         122  +
//!
         123  +
//! Handlers can accept up to 8 extractors:
         124  +
//!
         125  +
//! ```rust,no_run
         126  +
//! # struct Input;
         127  +
//! # struct Output;
         128  +
//! # struct Error;
         129  +
//! # struct State;
         130  +
//! # use std::net::SocketAddr;
         131  +
//! use custom_validation_exception_example_http0x::server::request::{extension::Extension, connect_info::ConnectInfo};
         132  +
//!
         133  +
//! async fn handler_with_no_extensions(input: Input) -> Output {
         134  +
//!     todo!()
         135  +
//! }
         136  +
//!
         137  +
//! async fn handler_with_one_extractor(input: Input, ext: Extension<State>) -> Output {
         138  +
//!     todo!()
         139  +
//! }
         140  +
//!
         141  +
//! async fn handler_with_two_extractors(
         142  +
//!     input: Input,
         143  +
//!     ext0: Extension<State>,
         144  +
//!     ext1: ConnectInfo<SocketAddr>,
         145  +
//! ) -> Output {
         146  +
//!     todo!()
         147  +
//! }
         148  +
//! ```
         149  +
//!
         150  +
//! See the [`operation module`](crate::operation) for information on precisely what constitutes a handler.
         151  +
//!
         152  +
//! ## Build
         153  +
//!
         154  +
//! You can convert [`CustomValidationExampleBuilder`] into [`CustomValidationExample`] using either [`CustomValidationExampleBuilder::build`] or [`CustomValidationExampleBuilder::build_unchecked`].
         155  +
//!
         156  +
//! [`CustomValidationExampleBuilder::build`] requires you to provide a handler for every single operation in your Smithy model. It will return an error if that is not the case.
         157  +
//!
         158  +
//! [`CustomValidationExampleBuilder::build_unchecked`], instead, does not require exhaustiveness. The server will automatically return 500 Internal Server Error to all requests for operations that do not have a registered handler.
         159  +
//! [`CustomValidationExampleBuilder::build_unchecked`] is particularly useful if you are deploying your Smithy service as a collection of Lambda functions, where each Lambda is only responsible for a subset of the operations in the Smithy service (or even a single one!).
         160  +
//!
         161  +
//! # Example
         162  +
//!
         163  +
//! ```rust,no_run
         164  +
//! # use std::net::SocketAddr;
         165  +
//! use custom_validation_exception_example_http0x::{CustomValidationExample, CustomValidationExampleConfig};
         166  +
//!
         167  +
//! #[::tokio::main]
         168  +
//! pub async fn main() {
         169  +
//!    let config = CustomValidationExampleConfig::builder().build();
         170  +
//!    let app = CustomValidationExample::builder(config)
         171  +
//!        .test_operation(test_operation)
         172  +
//!        .build()
         173  +
//!        .expect("failed to build an instance of CustomValidationExample");
         174  +
//!
         175  +
//!    let bind: SocketAddr = "127.0.0.1:6969".parse()
         176  +
//!        .expect("unable to parse the server bind address and port");
         177  +
//!    let server = ::hyper::Server::bind(&bind).serve(app.into_make_service());
         178  +
//!    # let server = async { Ok::<_, ()>(()) };
         179  +
//!
         180  +
//!    // Run your service!
         181  +
//!    if let Err(err) = server.await {
         182  +
//!        eprintln!("server error: {:?}", err);
         183  +
//!    }
         184  +
//! }
         185  +
//!
         186  +
//! use custom_validation_exception_example_http0x::{input, output, error};
         187  +
//!
         188  +
//! async fn test_operation(input: input::TestOperationInput) -> Result<output::TestOperationOutput, error::TestOperationError> {
         189  +
//!     todo!()
         190  +
//! }
         191  +
//!
         192  +
//! ```
         193  +
//!
         194  +
//! [`serve`]: https://docs.rs/hyper/0.14.16/hyper/server/struct.Builder.html#method.serve
         195  +
//! [hyper server]: https://docs.rs/hyper/0.14.26/hyper/server/index.html
         196  +
//! [`tower::make::MakeService`]: https://docs.rs/tower/latest/tower/make/trait.MakeService.html
         197  +
//! [HTTP binding traits]: https://smithy.io/2.0/spec/http-bindings.html
         198  +
//! [operations]: https://smithy.io/2.0/spec/service-types.html#operation
         199  +
//! [Service]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html
         200  +
pub use crate::service::{
         201  +
    CustomValidationExample, CustomValidationExampleBuilder, CustomValidationExampleConfig,
         202  +
    CustomValidationExampleConfigBuilder, MissingOperationsError,
         203  +
};
         204  +
         205  +
/// Contains the types that are re-exported from the `aws-smithy-http-server` crate.
         206  +
pub mod server {
         207  +
    // Re-export all types from the `aws-smithy-http-server` crate.
         208  +
    pub use ::aws_smithy_legacy_http_server::*;
         209  +
}
         210  +
         211  +
/// Crate version number.
         212  +
pub static PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
         213  +
         214  +
/// All error types that operations can return. Documentation on these types is copied from the model.
         215  +
pub mod error;
         216  +
         217  +
/// Input structures for operations. Documentation on these types is copied from the model.
         218  +
pub mod input;
         219  +
         220  +
/// Data structures used by operation inputs/outputs. Documentation on these types is copied from the model.
         221  +
pub mod model;
         222  +
         223  +
/// All operations that this crate can perform.
         224  +
pub mod operation;
         225  +
         226  +
/// A collection of types representing each operation defined in the service closure.
         227  +
///
         228  +
/// The [plugin system](::aws_smithy_legacy_http_server::plugin) makes use of these
         229  +
/// [zero-sized types](https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts) (ZSTs) to
         230  +
/// parameterize [`Plugin`](::aws_smithy_legacy_http_server::plugin::Plugin) implementations. Their traits, such as
         231  +
/// [`OperationShape`](::aws_smithy_legacy_http_server::operation::OperationShape), can be used to provide
         232  +
/// operation specific information to the [`Layer`](::tower::Layer) being applied.
         233  +
pub mod operation_shape;
         234  +
         235  +
/// Output structures for operations. Documentation on these types is copied from the model.
         236  +
pub mod output;
         237  +
         238  +
mod service;
         239  +
         240  +
/// Data primitives referenced by other data types.
         241  +
pub mod types;
         242  +
         243  +
/// Constrained types for constrained shapes.
         244  +
mod constrained;
         245  +
         246  +
mod mimes;
         247  +
         248  +
pub(crate) mod protocol_serde;

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

@@ -0,1 +0,7 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
pub(crate) static CONTENT_TYPE_APPLICATION_JSON: std::sync::LazyLock<::mime::Mime> =
           3  +
    std::sync::LazyLock::new(|| {
           4  +
        "application/json"
           5  +
            .parse::<::mime::Mime>()
           6  +
            .expect("BUG: MIME parsing failed, content_type is not valid")
           7  +
    });

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

@@ -0,1 +0,186 @@
           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 CustomValidationField {
           7  +
    #[allow(missing_docs)] // documentation missing in model
           8  +
    pub custom_field_name: ::std::string::String,
           9  +
    #[allow(missing_docs)] // documentation missing in model
          10  +
    pub custom_field_message: ::std::string::String,
          11  +
}
          12  +
impl CustomValidationField {
          13  +
    #[allow(missing_docs)] // documentation missing in model
          14  +
    pub fn custom_field_name(&self) -> &str {
          15  +
        use std::ops::Deref;
          16  +
        self.custom_field_name.deref()
          17  +
    }
          18  +
    #[allow(missing_docs)] // documentation missing in model
          19  +
    pub fn custom_field_message(&self) -> &str {
          20  +
        use std::ops::Deref;
          21  +
        self.custom_field_message.deref()
          22  +
    }
          23  +
}
          24  +
impl CustomValidationField {
          25  +
    /// Creates a new builder-style object to manufacture [`CustomValidationField`](crate::model::CustomValidationField).
          26  +
    pub fn builder() -> crate::model::custom_validation_field::Builder {
          27  +
        crate::model::custom_validation_field::Builder::default()
          28  +
    }
          29  +
}
          30  +
          31  +
#[allow(missing_docs)] // documentation missing in model
          32  +
#[derive(
          33  +
    ::std::clone::Clone,
          34  +
    ::std::cmp::Eq,
          35  +
    ::std::cmp::Ord,
          36  +
    ::std::cmp::PartialEq,
          37  +
    ::std::cmp::PartialOrd,
          38  +
    ::std::fmt::Debug,
          39  +
    ::std::hash::Hash,
          40  +
)]
          41  +
pub enum ValidationExceptionReason {
          42  +
    #[allow(missing_docs)] // documentation missing in model
          43  +
    TestReason0,
          44  +
    #[allow(missing_docs)] // documentation missing in model
          45  +
    TestReason1,
          46  +
}
          47  +
/// See [`ValidationExceptionReason`](crate::model::ValidationExceptionReason).
          48  +
pub mod validation_exception_reason {
          49  +
    #[derive(Debug, PartialEq)]
          50  +
    pub struct ConstraintViolation(pub(crate) ::std::string::String);
          51  +
          52  +
    impl ::std::fmt::Display for ConstraintViolation {
          53  +
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          54  +
            write!(
          55  +
                f,
          56  +
                r#"Value provided for 'com.aws.example#ValidationExceptionReason' failed to satisfy constraint: Member must satisfy enum value set: [testReason0, testReason1]"#
          57  +
            )
          58  +
        }
          59  +
    }
          60  +
          61  +
    impl ::std::error::Error for ConstraintViolation {}
          62  +
}
          63  +
impl ::std::convert::TryFrom<&str> for ValidationExceptionReason {
          64  +
    type Error = crate::model::validation_exception_reason::ConstraintViolation;
          65  +
    fn try_from(
          66  +
        s: &str,
          67  +
    ) -> ::std::result::Result<Self, <Self as ::std::convert::TryFrom<&str>>::Error> {
          68  +
        match s {
          69  +
            "testReason0" => Ok(ValidationExceptionReason::TestReason0),
          70  +
            "testReason1" => Ok(ValidationExceptionReason::TestReason1),
          71  +
            _ => Err(crate::model::validation_exception_reason::ConstraintViolation(s.to_owned())),
          72  +
        }
          73  +
    }
          74  +
}
          75  +
impl ::std::convert::TryFrom<::std::string::String> for ValidationExceptionReason {
          76  +
    type Error = crate::model::validation_exception_reason::ConstraintViolation;
          77  +
    fn try_from(
          78  +
        s: ::std::string::String,
          79  +
    ) -> ::std::result::Result<Self, <Self as ::std::convert::TryFrom<::std::string::String>>::Error>
          80  +
    {
          81  +
        s.as_str().try_into()
          82  +
    }
          83  +
}
          84  +
impl std::str::FromStr for ValidationExceptionReason {
          85  +
    type Err = crate::model::validation_exception_reason::ConstraintViolation;
          86  +
    fn from_str(s: &str) -> std::result::Result<Self, <Self as std::str::FromStr>::Err> {
          87  +
        Self::try_from(s)
          88  +
    }
          89  +
}
          90  +
impl ValidationExceptionReason {
          91  +
    /// Returns the `&str` value of the enum member.
          92  +
    pub fn as_str(&self) -> &str {
          93  +
        match self {
          94  +
            ValidationExceptionReason::TestReason0 => "testReason0",
          95  +
            ValidationExceptionReason::TestReason1 => "testReason1",
          96  +
        }
          97  +
    }
          98  +
    /// Returns all the `&str` representations of the enum members.
          99  +
    pub const fn values() -> &'static [&'static str] {
         100  +
        &["testReason0", "testReason1"]
         101  +
    }
         102  +
}
         103  +
impl ::std::convert::AsRef<str> for ValidationExceptionReason {
         104  +
    fn as_ref(&self) -> &str {
         105  +
        self.as_str()
         106  +
    }
         107  +
}
         108  +
impl crate::constrained::Constrained for ValidationExceptionReason {
         109  +
    type Unconstrained = ::std::string::String;
         110  +
}
         111  +
         112  +
impl ::std::convert::From<::std::string::String>
         113  +
    for crate::constrained::MaybeConstrained<crate::model::ValidationExceptionReason>
         114  +
{
         115  +
    fn from(value: ::std::string::String) -> Self {
         116  +
        Self::Unconstrained(value)
         117  +
    }
         118  +
}
         119  +
/// See [`CustomValidationField`](crate::model::CustomValidationField).
         120  +
pub mod custom_validation_field {
         121  +
         122  +
    #[derive(::std::cmp::PartialEq, ::std::fmt::Debug)]
         123  +
    /// Holds one variant for each of the ways the builder can fail.
         124  +
    #[non_exhaustive]
         125  +
    #[allow(clippy::enum_variant_names)]
         126  +
    pub enum ConstraintViolation {
         127  +
        /// `custom_field_name` was not provided but it is required when building `CustomValidationField`.
         128  +
        MissingCustomFieldName,
         129  +
        /// `custom_field_message` was not provided but it is required when building `CustomValidationField`.
         130  +
        MissingCustomFieldMessage,
         131  +
    }
         132  +
    impl ::std::fmt::Display for ConstraintViolation {
         133  +
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         134  +
            match self {
         135  +
                ConstraintViolation::MissingCustomFieldName => write!(f, "`custom_field_name` was not provided but it is required when building `CustomValidationField`"),
         136  +
                ConstraintViolation::MissingCustomFieldMessage => write!(f, "`custom_field_message` was not provided but it is required when building `CustomValidationField`"),
         137  +
            }
         138  +
        }
         139  +
    }
         140  +
    impl ::std::error::Error for ConstraintViolation {}
         141  +
    impl ::std::convert::TryFrom<Builder> for crate::model::CustomValidationField {
         142  +
        type Error = ConstraintViolation;
         143  +
         144  +
        fn try_from(builder: Builder) -> ::std::result::Result<Self, Self::Error> {
         145  +
            builder.build()
         146  +
        }
         147  +
    }
         148  +
    /// A builder for [`CustomValidationField`](crate::model::CustomValidationField).
         149  +
    #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
         150  +
    pub struct Builder {
         151  +
        pub(crate) custom_field_name: ::std::option::Option<::std::string::String>,
         152  +
        pub(crate) custom_field_message: ::std::option::Option<::std::string::String>,
         153  +
    }
         154  +
    impl Builder {
         155  +
        #[allow(missing_docs)] // documentation missing in model
         156  +
        pub fn custom_field_name(mut self, input: ::std::string::String) -> Self {
         157  +
            self.custom_field_name = Some(input);
         158  +
            self
         159  +
        }
         160  +
        #[allow(missing_docs)] // documentation missing in model
         161  +
        pub fn custom_field_message(mut self, input: ::std::string::String) -> Self {
         162  +
            self.custom_field_message = Some(input);
         163  +
            self
         164  +
        }
         165  +
        /// Consumes the builder and constructs a [`CustomValidationField`](crate::model::CustomValidationField).
         166  +
        ///
         167  +
        /// The builder fails to construct a [`CustomValidationField`](crate::model::CustomValidationField) if a [`ConstraintViolation`] occurs.
         168  +
        ///
         169  +
        /// If the builder fails, it will return the _first_ encountered [`ConstraintViolation`].
         170  +
        pub fn build(self) -> Result<crate::model::CustomValidationField, ConstraintViolation> {
         171  +
            self.build_enforcing_all_constraints()
         172  +
        }
         173  +
        fn build_enforcing_all_constraints(
         174  +
            self,
         175  +
        ) -> Result<crate::model::CustomValidationField, ConstraintViolation> {
         176  +
            Ok(crate::model::CustomValidationField {
         177  +
                custom_field_name: self
         178  +
                    .custom_field_name
         179  +
                    .ok_or(ConstraintViolation::MissingCustomFieldName)?,
         180  +
                custom_field_message: self
         181  +
                    .custom_field_message
         182  +
                    .ok_or(ConstraintViolation::MissingCustomFieldMessage)?,
         183  +
            })
         184  +
        }
         185  +
    }
         186  +
}

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

@@ -0,1 +0,99 @@
           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_legacy_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_legacy_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_legacy_http_server::request::FromRequest<
          27  +
        ::aws_smithy_legacy_http_server::protocol::rest_json_1::RestJson1,
          28  +
        B,
          29  +
    > for crate::input::TestOperationInput
          30  +
where
          31  +
    B: ::aws_smithy_legacy_http_server::body::HttpBody + Send,
          32  +
    B: 'static,
          33  +
          34  +
    B::Data: Send,
          35  +
    ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection:
          36  +
        From<<B as ::aws_smithy_legacy_http_server::body::HttpBody>::Error>,
          37  +
{
          38  +
    type Rejection =
          39  +
        ::aws_smithy_legacy_http_server::protocol::rest_json_1::runtime_error::RuntimeError;
          40  +
    type Future = TestOperationInputFuture;
          41  +
          42  +
    fn from_request(request: ::http::Request<B>) -> Self::Future {
          43  +
        let fut = async move {
          44  +
            if !::aws_smithy_legacy_http_server::protocol::accept_header_classifier(
          45  +
                request.headers(),
          46  +
                &crate::mimes::CONTENT_TYPE_APPLICATION_JSON,
          47  +
            ) {
          48  +
                return Err(::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection::NotAcceptable);
          49  +
            }
          50  +
            crate::protocol_serde::shape_test_operation::de_test_operation_http_request(request)
          51  +
                .await
          52  +
        };
          53  +
        use ::futures_util::future::TryFutureExt;
          54  +
        let fut = fut.map_err(|e: ::aws_smithy_legacy_http_server::protocol::rest_json_1::rejection::RequestRejection| {
          55  +
                        ::tracing::debug!(error = %e, "failed to deserialize request");
          56  +
                        ::aws_smithy_legacy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e)
          57  +
                    });
          58  +
        TestOperationInputFuture {
          59  +
            inner: Box::pin(fut),
          60  +
        }
          61  +
    }
          62  +
}
          63  +
impl
          64  +
    ::aws_smithy_legacy_http_server::response::IntoResponse<
          65  +
        ::aws_smithy_legacy_http_server::protocol::rest_json_1::RestJson1,
          66  +
    > for crate::output::TestOperationOutput
          67  +
{
          68  +
    fn into_response(self) -> ::aws_smithy_legacy_http_server::response::Response {
          69  +
        match crate::protocol_serde::shape_test_operation::ser_test_operation_http_response(self) {
          70  +
            Ok(response) => response,
          71  +
            Err(e) => {
          72  +
                ::tracing::error!(error = %e, "failed to serialize response");
          73  +
                ::aws_smithy_legacy_http_server::response::IntoResponse::<::aws_smithy_legacy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_legacy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
          74  +
            }
          75  +
        }
          76  +
    }
          77  +
}
          78  +
impl
          79  +
    ::aws_smithy_legacy_http_server::response::IntoResponse<
          80  +
        ::aws_smithy_legacy_http_server::protocol::rest_json_1::RestJson1,
          81  +
    > for crate::error::TestOperationError
          82  +
{
          83  +
    fn into_response(self) -> ::aws_smithy_legacy_http_server::response::Response {
          84  +
        match crate::protocol_serde::shape_test_operation::ser_test_operation_http_error(&self) {
          85  +
            Ok(mut response) => {
          86  +
                response.extensions_mut().insert(
          87  +
                    ::aws_smithy_legacy_http_server::extension::ModeledErrorExtension::new(
          88  +
                        self.name(),
          89  +
                    ),
          90  +
                );
          91  +
                response
          92  +
            }
          93  +
            Err(e) => {
          94  +
                ::tracing::error!(error = %e, "failed to serialize response");
          95  +
                ::aws_smithy_legacy_http_server::response::IntoResponse::<::aws_smithy_legacy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_legacy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
          96  +
            }
          97  +
        }
          98  +
    }
          99  +
}

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

@@ -0,1 +0,38 @@
           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_legacy_http_server::operation::OperationShape for TestOperation {
           6  +
    const ID: ::aws_smithy_legacy_http_server::shape_id::ShapeId =
           7  +
        ::aws_smithy_legacy_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_legacy_http_server::instrumentation::sensitivity::Sensitivity for TestOperation {
          19  +
    type RequestFmt = ::aws_smithy_legacy_http_server::instrumentation::sensitivity::RequestFmt<
          20  +
        ::aws_smithy_legacy_http_server::instrumentation::MakeIdentity,
          21  +
        ::aws_smithy_legacy_http_server::instrumentation::sensitivity::uri::MakeUri<
          22  +
            ::aws_smithy_legacy_http_server::instrumentation::MakeIdentity,
          23  +
            ::aws_smithy_legacy_http_server::instrumentation::MakeIdentity,
          24  +
        >,
          25  +
    >;
          26  +
    type ResponseFmt = ::aws_smithy_legacy_http_server::instrumentation::sensitivity::ResponseFmt<
          27  +
        ::aws_smithy_legacy_http_server::instrumentation::MakeIdentity,
          28  +
        ::aws_smithy_legacy_http_server::instrumentation::MakeIdentity,
          29  +
    >;
          30  +
          31  +
    fn request_fmt() -> Self::RequestFmt {
          32  +
        ::aws_smithy_legacy_http_server::instrumentation::sensitivity::RequestFmt::new()
          33  +
    }
          34  +
          35  +
    fn response_fmt() -> Self::ResponseFmt {
          36  +
        ::aws_smithy_legacy_http_server::instrumentation::sensitivity::ResponseFmt::new()
          37  +
    }
          38  +
}

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

@@ -0,1 +0,33 @@
           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-http0x/rust-server-codegen/src/protocol_serde.rs

@@ -0,1 +0,14 @@
           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-http0x/rust-server-codegen/src/protocol_serde/shape_custom_validation_field.rs

@@ -0,1 +0,17 @@
           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-http0x/rust-server-codegen/src/protocol_serde/shape_my_custom_validation_exception.rs

@@ -0,1 +0,40 @@
           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-http0x/rust-server-codegen/src/protocol_serde/shape_test_operation.rs

@@ -0,1 +0,160 @@
           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_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::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_legacy_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_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_test_operation_http_error(
          68  +
    error: &crate::error::TestOperationError,
          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::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_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  +
                    "MyCustomValidationException",
          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_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: {other:?}"
         147  +
                    )),
         148  +
                )
         149  +
            }
         150  +
        }
         151  +
    }
         152  +
    if tokens.next().is_some() {
         153  +
        return Err(
         154  +
            ::aws_smithy_json::deserialize::error::DeserializeError::custom(
         155  +
                "found more JSON tokens after completing parsing",
         156  +
            ),
         157  +
        );
         158  +
    }
         159  +
    Ok(builder)
         160  +
}

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

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