Server Test

Server Test

rev. 0a44b51dc4f288c72cfe7e679f226a4d4a1d474a (ignoring whitespace)

Files changed:

tmp-codegen-diff/codegen-server-test/Cargo.toml

@@ -1,1 +5,5 @@
    1      1   
[workspace]
    2      2   
resolver = "2"
    3      3   
members = [
    4         -
    "naming_test_ops/rust-server-codegen","naming_test_casing/rust-server-codegen","naming_test_structs/rust-server-codegen","simple/rust-server-codegen","rpcv2Cbor/rust-server-codegen","rpcv2Cbor_extras/rust-server-codegen","rpcv2Cbor_extras_no_initial_response/rust-server-codegen","constraints_without_public_constrained_types/rust-server-codegen","unique_items/rust-server-codegen","constraints/rust-server-codegen","rest_json/rust-server-codegen","rest_json_extras/rust-server-codegen","rest_json_validation/rust-server-codegen","json_rpc10/rust-server-codegen","json_rpc11/rust-server-codegen","misc/rust-server-codegen","ebs/rust-server-codegen","s3/rust-server-codegen","pokemon-service-server-sdk/rust-server-codegen","pokemon-service-awsjson-server-sdk/rust-server-codegen","custom-validation-exception-example/rust-server-codegen"
           4  +
    "naming_test_ops/rust-server-codegen","naming_test_casing/rust-server-codegen","naming_test_structs/rust-server-codegen","simple/rust-server-codegen","rpcv2Cbor/rust-server-codegen","rpcv2Cbor_extras/rust-server-codegen","rpcv2Cbor_extras_no_initial_response/rust-server-codegen","constraints_without_public_constrained_types/rust-server-codegen","unique_items/rust-server-codegen","constraints/rust-server-codegen","rest_json/rust-server-codegen","rest_json_extras/rust-server-codegen","rest_json_validation/rust-server-codegen","json_rpc10/rust-server-codegen","json_rpc11/rust-server-codegen","misc/rust-server-codegen","ebs/rust-server-codegen","s3/rust-server-codegen","pokemon-service-server-sdk/rust-server-codegen","pokemon-service-awsjson-server-sdk/rust-server-codegen"
    5      5   
]

tmp-codegen-diff/codegen-server-test/custom-validation-exception-example/rust-server-codegen/Cargo.toml

@@ -1,0 +46,0 @@
    1         -
# Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
[package]
    3         -
name = "custom-validation-exception-example"
    4         -
version = "0.0.1"
    5         -
authors = ["protocoltest@example.com"]
    6         -
description = "test"
    7         -
edition = "2021"
    8         -
    9         -
[package.metadata.smithy]
   10         -
codegen-version = "ci"
   11         -
protocol = "aws.protocols#restJson1"
   12         -
[dependencies.aws-smithy-http]
   13         -
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-http"
   14         -
[dependencies.aws-smithy-http-server]
   15         -
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-http-server"
   16         -
[dependencies.aws-smithy-json]
   17         -
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-json"
   18         -
[dependencies.aws-smithy-runtime-api]
   19         -
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-runtime-api"
   20         -
[dependencies.aws-smithy-types]
   21         -
path = "/home/build/workspace/smithy-rs/rust-runtime/aws-smithy-types"
   22         -
[dependencies.futures-util]
   23         -
version = "0.3"
   24         -
[dependencies.http]
   25         -
version = "0.2.9"
   26         -
[dependencies.hyper]
   27         -
version = "0.14.26"
   28         -
[dependencies.mime]
   29         -
version = "0.3"
   30         -
[dependencies.pin-project-lite]
   31         -
version = "0.2"
   32         -
[dependencies.tower]
   33         -
version = "0.4"
   34         -
[dependencies.tracing]
   35         -
version = "0.1"
   36         -
[dev-dependencies.hyper]
   37         -
version = "0.14.12"
   38         -
[dev-dependencies.tokio]
   39         -
version = "1.23.1"
   40         -
[features]
   41         -
rt-tokio = ["aws-smithy-types/rt-tokio"]
   42         -
aws-lambda = ["aws-smithy-http-server/aws-lambda"]
   43         -
request-id = ["aws-smithy-http-server/request-id"]
   44         -
default = ["rt-tokio", "request-id"]
   45         -
   46         -

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

@@ -1,0 +16,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
/*
    3         -
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
    4         -
 * SPDX-License-Identifier: Apache-2.0
    5         -
 */
    6         -
    7         -
pub(crate) trait Constrained {
    8         -
    type Unconstrained;
    9         -
}
   10         -
   11         -
#[derive(Debug, Clone)]
   12         -
#[allow(dead_code)]
   13         -
pub(crate) enum MaybeConstrained<T: Constrained> {
   14         -
    Constrained(T),
   15         -
    Unconstrained(T::Unconstrained),
   16         -
}

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

@@ -1,0 +173,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
#[allow(missing_docs)] // documentation missing in model
    3         -
#[derive(
    4         -
    ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
    5         -
)]
    6         -
pub struct MyCustomValidationException {
    7         -
    #[allow(missing_docs)] // documentation missing in model
    8         -
    pub custom_message: ::std::string::String,
    9         -
    #[allow(missing_docs)] // documentation missing in model
   10         -
    pub reason: crate::model::ValidationExceptionReason,
   11         -
    #[allow(missing_docs)] // documentation missing in model
   12         -
    pub custom_field_list:
   13         -
        ::std::option::Option<::std::vec::Vec<crate::model::CustomValidationField>>,
   14         -
}
   15         -
impl MyCustomValidationException {
   16         -
    #[allow(missing_docs)] // documentation missing in model
   17         -
    pub fn custom_message(&self) -> &str {
   18         -
        use std::ops::Deref;
   19         -
        self.custom_message.deref()
   20         -
    }
   21         -
    #[allow(missing_docs)] // documentation missing in model
   22         -
    pub fn reason(&self) -> &crate::model::ValidationExceptionReason {
   23         -
        &self.reason
   24         -
    }
   25         -
    #[allow(missing_docs)] // documentation missing in model
   26         -
    pub fn custom_field_list(
   27         -
        &self,
   28         -
    ) -> ::std::option::Option<&[crate::model::CustomValidationField]> {
   29         -
        self.custom_field_list.as_deref()
   30         -
    }
   31         -
}
   32         -
impl MyCustomValidationException {
   33         -
    #[doc(hidden)]
   34         -
    /// Returns the error name.
   35         -
    pub fn name(&self) -> &'static str {
   36         -
        "MyCustomValidationException"
   37         -
    }
   38         -
}
   39         -
impl ::std::fmt::Display for MyCustomValidationException {
   40         -
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
   41         -
        ::std::write!(f, "MyCustomValidationException")?;
   42         -
        Ok(())
   43         -
    }
   44         -
}
   45         -
impl ::std::error::Error for MyCustomValidationException {}
   46         -
impl MyCustomValidationException {
   47         -
    /// Creates a new builder-style object to manufacture [`MyCustomValidationException`](crate::error::MyCustomValidationException).
   48         -
    pub fn builder() -> crate::error::my_custom_validation_exception::Builder {
   49         -
        crate::error::my_custom_validation_exception::Builder::default()
   50         -
    }
   51         -
}
   52         -
   53         -
/// Error type for the `TestOperation` operation.
   54         -
/// Each variant represents an error that can occur for the `TestOperation` operation.
   55         -
#[derive(::std::fmt::Debug)]
   56         -
pub enum TestOperationError {
   57         -
    #[allow(missing_docs)] // documentation missing in model
   58         -
    MyCustomValidationException(crate::error::MyCustomValidationException),
   59         -
}
   60         -
impl ::std::fmt::Display for TestOperationError {
   61         -
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
   62         -
        match &self {
   63         -
            TestOperationError::MyCustomValidationException(_inner) => _inner.fmt(f),
   64         -
        }
   65         -
    }
   66         -
}
   67         -
impl TestOperationError {
   68         -
    /// Returns `true` if the error kind is `TestOperationError::MyCustomValidationException`.
   69         -
    pub fn is_my_custom_validation_exception(&self) -> bool {
   70         -
        matches!(&self, TestOperationError::MyCustomValidationException(_))
   71         -
    }
   72         -
    /// Returns the error name string by matching the correct variant.
   73         -
    pub fn name(&self) -> &'static str {
   74         -
        match &self {
   75         -
            TestOperationError::MyCustomValidationException(_inner) => _inner.name(),
   76         -
        }
   77         -
    }
   78         -
}
   79         -
impl ::std::error::Error for TestOperationError {
   80         -
    fn source(&self) -> std::option::Option<&(dyn ::std::error::Error + 'static)> {
   81         -
        match &self {
   82         -
            TestOperationError::MyCustomValidationException(_inner) => Some(_inner),
   83         -
        }
   84         -
    }
   85         -
}
   86         -
impl ::std::convert::From<crate::error::MyCustomValidationException>
   87         -
    for crate::error::TestOperationError
   88         -
{
   89         -
    fn from(
   90         -
        variant: crate::error::MyCustomValidationException,
   91         -
    ) -> crate::error::TestOperationError {
   92         -
        Self::MyCustomValidationException(variant)
   93         -
    }
   94         -
}
   95         -
/// See [`MyCustomValidationException`](crate::error::MyCustomValidationException).
   96         -
pub mod my_custom_validation_exception {
   97         -
   98         -
    #[derive(::std::cmp::PartialEq, ::std::fmt::Debug)]
   99         -
    /// Holds one variant for each of the ways the builder can fail.
  100         -
    #[non_exhaustive]
  101         -
    #[allow(clippy::enum_variant_names)]
  102         -
    pub enum ConstraintViolation {
  103         -
        /// `custom_message` was not provided but it is required when building `MyCustomValidationException`.
  104         -
        MissingCustomMessage,
  105         -
    }
  106         -
    impl ::std::fmt::Display for ConstraintViolation {
  107         -
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  108         -
            match self {
  109         -
                ConstraintViolation::MissingCustomMessage => write!(f, "`custom_message` was not provided but it is required when building `MyCustomValidationException`"),
  110         -
            }
  111         -
        }
  112         -
    }
  113         -
    impl ::std::error::Error for ConstraintViolation {}
  114         -
    impl ::std::convert::TryFrom<Builder> for crate::error::MyCustomValidationException {
  115         -
        type Error = ConstraintViolation;
  116         -
  117         -
        fn try_from(builder: Builder) -> ::std::result::Result<Self, Self::Error> {
  118         -
            builder.build()
  119         -
        }
  120         -
    }
  121         -
    /// A builder for [`MyCustomValidationException`](crate::error::MyCustomValidationException).
  122         -
    #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
  123         -
    pub struct Builder {
  124         -
        pub(crate) custom_message: ::std::option::Option<::std::string::String>,
  125         -
        pub(crate) reason: ::std::option::Option<crate::model::ValidationExceptionReason>,
  126         -
        pub(crate) custom_field_list:
  127         -
            ::std::option::Option<::std::vec::Vec<crate::model::CustomValidationField>>,
  128         -
    }
  129         -
    impl Builder {
  130         -
        #[allow(missing_docs)] // documentation missing in model
  131         -
        pub fn custom_message(mut self, input: ::std::string::String) -> Self {
  132         -
            self.custom_message = Some(input);
  133         -
            self
  134         -
        }
  135         -
        #[allow(missing_docs)] // documentation missing in model
  136         -
        pub fn reason(mut self, input: crate::model::ValidationExceptionReason) -> Self {
  137         -
            self.reason = Some(input);
  138         -
            self
  139         -
        }
  140         -
        #[allow(missing_docs)] // documentation missing in model
  141         -
        pub fn custom_field_list(
  142         -
            mut self,
  143         -
            input: ::std::option::Option<::std::vec::Vec<crate::model::CustomValidationField>>,
  144         -
        ) -> Self {
  145         -
            self.custom_field_list = input;
  146         -
            self
  147         -
        }
  148         -
        /// Consumes the builder and constructs a [`MyCustomValidationException`](crate::error::MyCustomValidationException).
  149         -
        ///
  150         -
        /// The builder fails to construct a [`MyCustomValidationException`](crate::error::MyCustomValidationException) if a [`ConstraintViolation`] occurs.
  151         -
        ///
  152         -
        pub fn build(
  153         -
            self,
  154         -
        ) -> Result<crate::error::MyCustomValidationException, ConstraintViolation> {
  155         -
            self.build_enforcing_all_constraints()
  156         -
        }
  157         -
        fn build_enforcing_all_constraints(
  158         -
            self,
  159         -
        ) -> Result<crate::error::MyCustomValidationException, ConstraintViolation> {
  160         -
            Ok(crate::error::MyCustomValidationException {
  161         -
                custom_message: self
  162         -
                    .custom_message
  163         -
                    .ok_or(ConstraintViolation::MissingCustomMessage)?,
  164         -
                reason: self.reason.unwrap_or(
  165         -
                    "testReason1"
  166         -
                        .parse::<crate::model::ValidationExceptionReason>()
  167         -
                        .expect("static value validated to member"),
  168         -
                ),
  169         -
                custom_field_list: self.custom_field_list,
  170         -
            })
  171         -
        }
  172         -
    }
  173         -
}

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

@@ -1,0 +409,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
#[allow(missing_docs)] // documentation missing in model
    3         -
#[derive(
    4         -
    ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
    5         -
)]
    6         -
pub struct TestOperationInput {
    7         -
    #[allow(missing_docs)] // documentation missing in model
    8         -
    pub name: crate::input::test_operation_input::Name,
    9         -
    #[allow(missing_docs)] // documentation missing in model
   10         -
    pub age: ::std::option::Option<crate::input::test_operation_input::Age>,
   11         -
}
   12         -
impl TestOperationInput {
   13         -
    #[allow(missing_docs)] // documentation missing in model
   14         -
    pub fn name(&self) -> &crate::input::test_operation_input::Name {
   15         -
        &self.name
   16         -
    }
   17         -
    #[allow(missing_docs)] // documentation missing in model
   18         -
    pub fn age(&self) -> ::std::option::Option<&crate::input::test_operation_input::Age> {
   19         -
        self.age.as_ref()
   20         -
    }
   21         -
}
   22         -
impl TestOperationInput {
   23         -
    /// Creates a new builder-style object to manufacture [`TestOperationInput`](crate::input::TestOperationInput).
   24         -
    pub fn builder() -> crate::input::test_operation_input::Builder {
   25         -
        crate::input::test_operation_input::Builder::default()
   26         -
    }
   27         -
}
   28         -
impl crate::constrained::Constrained for crate::input::TestOperationInput {
   29         -
    type Unconstrained = crate::input::test_operation_input::Builder;
   30         -
}
   31         -
   32         -
/// See [`TestOperationInput`](crate::input::TestOperationInput).
   33         -
pub mod test_operation_input {
   34         -
   35         -
    #[derive(::std::cmp::PartialEq, ::std::fmt::Debug)]
   36         -
    /// Holds one variant for each of the ways the builder can fail.
   37         -
    #[non_exhaustive]
   38         -
    #[allow(clippy::enum_variant_names)]
   39         -
    pub enum ConstraintViolation {
   40         -
        /// `name` was not provided but it is required when building `TestOperationInput`.
   41         -
        MissingName,
   42         -
        /// Constraint violation occurred building member `name` when building `TestOperationInput`.
   43         -
        #[doc(hidden)]
   44         -
        Name(crate::input::test_operation_input::name::ConstraintViolation),
   45         -
        /// Constraint violation occurred building member `age` when building `TestOperationInput`.
   46         -
        #[doc(hidden)]
   47         -
        Age(crate::input::test_operation_input::age::ConstraintViolation),
   48         -
    }
   49         -
    impl ::std::fmt::Display for ConstraintViolation {
   50         -
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
   51         -
            match self {
   52         -
                ConstraintViolation::MissingName => write!(f, "`name` was not provided but it is required when building `TestOperationInput`"),
   53         -
                ConstraintViolation::Name(_) => write!(f, "constraint violation occurred building member `name` when building `TestOperationInput`"),
   54         -
                ConstraintViolation::Age(_) => write!(f, "constraint violation occurred building member `age` when building `TestOperationInput`"),
   55         -
            }
   56         -
        }
   57         -
    }
   58         -
    impl ::std::error::Error for ConstraintViolation {}
   59         -
    impl ConstraintViolation {
   60         -
        pub(crate) fn as_validation_exception_field(
   61         -
            self,
   62         -
            path: ::std::string::String,
   63         -
        ) -> crate::model::CustomValidationField {
   64         -
            match self {
   65         -
                ConstraintViolation::MissingName => crate::model::CustomValidationField {
   66         -
                    custom_field_name: path.clone() + "/name",
   67         -
                    custom_field_message: format!(
   68         -
                        "Value at '{}/name' failed to satisfy constraint: Member must not be null",
   69         -
                        path
   70         -
                    ),
   71         -
                },
   72         -
                ConstraintViolation::Name(inner) => {
   73         -
                    inner.as_validation_exception_field(path + "/name")
   74         -
                }
   75         -
                ConstraintViolation::Age(inner) => {
   76         -
                    inner.as_validation_exception_field(path + "/age")
   77         -
                }
   78         -
            }
   79         -
        }
   80         -
    }
   81         -
    impl ::std::convert::From<ConstraintViolation>
   82         -
        for ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection
   83         -
    {
   84         -
        fn from(constraint_violation: ConstraintViolation) -> Self {
   85         -
            let first_validation_exception_field =
   86         -
                constraint_violation.as_validation_exception_field("".to_owned());
   87         -
            let validation_exception = crate::error::MyCustomValidationException {
   88         -
                custom_message: format!(
   89         -
                    "validation error detected. {}",
   90         -
                    &first_validation_exception_field.custom_field_message
   91         -
                ),
   92         -
                custom_field_list: Some(vec![first_validation_exception_field]),
   93         -
                reason: crate::model::ValidationExceptionReason::TestReason1,
   94         -
            };
   95         -
            Self::ConstraintViolation(
   96         -
                                crate::protocol_serde::shape_my_custom_validation_exception::ser_my_custom_validation_exception_error(&validation_exception)
   97         -
                                    .expect("validation exceptions should never fail to serialize; please file a bug report under https://github.com/smithy-lang/smithy-rs/issues")
   98         -
                            )
   99         -
        }
  100         -
    }
  101         -
    impl ::std::convert::From<Builder>
  102         -
        for crate::constrained::MaybeConstrained<crate::input::TestOperationInput>
  103         -
    {
  104         -
        fn from(builder: Builder) -> Self {
  105         -
            Self::Unconstrained(builder)
  106         -
        }
  107         -
    }
  108         -
    impl ::std::convert::TryFrom<Builder> for crate::input::TestOperationInput {
  109         -
        type Error = ConstraintViolation;
  110         -
  111         -
        fn try_from(builder: Builder) -> ::std::result::Result<Self, Self::Error> {
  112         -
            builder.build()
  113         -
        }
  114         -
    }
  115         -
    /// A builder for [`TestOperationInput`](crate::input::TestOperationInput).
  116         -
    #[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
  117         -
    pub struct Builder {
  118         -
        pub(crate) name: ::std::option::Option<
  119         -
            crate::constrained::MaybeConstrained<crate::input::test_operation_input::Name>,
  120         -
        >,
  121         -
        pub(crate) age: ::std::option::Option<
  122         -
            crate::constrained::MaybeConstrained<crate::input::test_operation_input::Age>,
  123         -
        >,
  124         -
    }
  125         -
    impl Builder {
  126         -
        #[allow(missing_docs)] // documentation missing in model
  127         -
        pub fn name(mut self, input: crate::input::test_operation_input::Name) -> Self {
  128         -
            self.name = Some(crate::constrained::MaybeConstrained::Constrained(input));
  129         -
            self
  130         -
        }
  131         -
        #[allow(missing_docs)] // documentation missing in model
  132         -
        pub(crate) fn set_name(
  133         -
            mut self,
  134         -
            input: impl ::std::convert::Into<
  135         -
                crate::constrained::MaybeConstrained<crate::input::test_operation_input::Name>,
  136         -
            >,
  137         -
        ) -> Self {
  138         -
            self.name = Some(input.into());
  139         -
            self
  140         -
        }
  141         -
        #[allow(missing_docs)] // documentation missing in model
  142         -
        pub fn age(
  143         -
            mut self,
  144         -
            input: ::std::option::Option<crate::input::test_operation_input::Age>,
  145         -
        ) -> Self {
  146         -
            self.age = input.map(
  147         -
                #[allow(clippy::redundant_closure)]
  148         -
                |v| crate::constrained::MaybeConstrained::Constrained(v),
  149         -
            );
  150         -
            self
  151         -
        }
  152         -
        #[allow(missing_docs)] // documentation missing in model
  153         -
        pub(crate) fn set_age(
  154         -
            mut self,
  155         -
            input: Option<
  156         -
                impl ::std::convert::Into<
  157         -
                    crate::constrained::MaybeConstrained<crate::input::test_operation_input::Age>,
  158         -
                >,
  159         -
            >,
  160         -
        ) -> Self {
  161         -
            self.age = input.map(|v| v.into());
  162         -
            self
  163         -
        }
  164         -
        /// Consumes the builder and constructs a [`TestOperationInput`](crate::input::TestOperationInput).
  165         -
        ///
  166         -
        /// The builder fails to construct a [`TestOperationInput`](crate::input::TestOperationInput) if a [`ConstraintViolation`] occurs.
  167         -
        ///
  168         -
        /// If the builder fails, it will return the _first_ encountered [`ConstraintViolation`].
  169         -
        pub fn build(self) -> Result<crate::input::TestOperationInput, ConstraintViolation> {
  170         -
            self.build_enforcing_all_constraints()
  171         -
        }
  172         -
        fn build_enforcing_all_constraints(
  173         -
            self,
  174         -
        ) -> Result<crate::input::TestOperationInput, ConstraintViolation> {
  175         -
            Ok(crate::input::TestOperationInput {
  176         -
                name: self
  177         -
                    .name
  178         -
                    .map(|v| match v {
  179         -
                        crate::constrained::MaybeConstrained::Constrained(x) => Ok(x),
  180         -
                        crate::constrained::MaybeConstrained::Unconstrained(x) => x.try_into(),
  181         -
                    })
  182         -
                    .map(|res| res.map_err(ConstraintViolation::Name))
  183         -
                    .transpose()?
  184         -
                    .ok_or(ConstraintViolation::MissingName)?,
  185         -
                age: self
  186         -
                    .age
  187         -
                    .map(|v| match v {
  188         -
                        crate::constrained::MaybeConstrained::Constrained(x) => Ok(x),
  189         -
                        crate::constrained::MaybeConstrained::Unconstrained(x) => x.try_into(),
  190         -
                    })
  191         -
                    .map(|res| res.map_err(ConstraintViolation::Age))
  192         -
                    .transpose()?,
  193         -
            })
  194         -
        }
  195         -
    }
  196         -
    #[allow(missing_docs)] // documentation missing in model
  197         -
    ///
  198         -
    /// This is a constrained type because its corresponding modeled Smithy shape has one or more
  199         -
    /// [constraint traits]. Use [`Age::try_from`] to construct values of this type.
  200         -
    ///
  201         -
    /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
  202         -
    ///
  203         -
    #[derive(
  204         -
        ::std::clone::Clone,
  205         -
        ::std::cmp::Eq,
  206         -
        ::std::cmp::PartialEq,
  207         -
        ::std::fmt::Debug,
  208         -
        ::std::hash::Hash,
  209         -
    )]
  210         -
    pub struct Age(pub(crate) i32);
  211         -
    impl Age {
  212         -
        /// Returns an immutable reference to the underlying [`i32`].
  213         -
        pub fn inner(&self) -> &i32 {
  214         -
            &self.0
  215         -
        }
  216         -
  217         -
        /// Consumes the value, returning the underlying [`i32`].
  218         -
        pub fn into_inner(self) -> i32 {
  219         -
            self.0
  220         -
        }
  221         -
    }
  222         -
  223         -
    impl crate::constrained::Constrained for Age {
  224         -
        type Unconstrained = i32;
  225         -
    }
  226         -
  227         -
    impl ::std::convert::From<i32>
  228         -
        for crate::constrained::MaybeConstrained<crate::input::test_operation_input::Age>
  229         -
    {
  230         -
        fn from(value: i32) -> Self {
  231         -
            Self::Unconstrained(value)
  232         -
        }
  233         -
    }
  234         -
  235         -
    impl ::std::fmt::Display for Age {
  236         -
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  237         -
            self.0.fmt(f)
  238         -
        }
  239         -
    }
  240         -
  241         -
    impl ::std::convert::From<Age> for i32 {
  242         -
        fn from(value: Age) -> Self {
  243         -
            value.into_inner()
  244         -
        }
  245         -
    }
  246         -
    impl Age {
  247         -
        fn check_range(
  248         -
            value: i32,
  249         -
        ) -> ::std::result::Result<(), crate::input::test_operation_input::age::ConstraintViolation>
  250         -
        {
  251         -
            if (1..=100).contains(&value) {
  252         -
                Ok(())
  253         -
            } else {
  254         -
                Err(crate::input::test_operation_input::age::ConstraintViolation::Range(value))
  255         -
            }
  256         -
        }
  257         -
    }
  258         -
    impl ::std::convert::TryFrom<i32> for Age {
  259         -
        type Error = crate::input::test_operation_input::age::ConstraintViolation;
  260         -
  261         -
        /// Constructs a `Age` from an [`i32`], failing when the provided value does not satisfy the modeled constraints.
  262         -
        fn try_from(value: i32) -> ::std::result::Result<Self, Self::Error> {
  263         -
            Self::check_range(value)?;
  264         -
  265         -
            Ok(Self(value))
  266         -
        }
  267         -
    }
  268         -
    #[allow(missing_docs)] // documentation missing in model
  269         -
    ///
  270         -
    /// This is a constrained type because its corresponding modeled Smithy shape has one or more
  271         -
    /// [constraint traits]. Use [`Name::try_from`] to construct values of this type.
  272         -
    ///
  273         -
    /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
  274         -
    ///
  275         -
    #[derive(
  276         -
        ::std::clone::Clone,
  277         -
        ::std::cmp::Eq,
  278         -
        ::std::cmp::PartialEq,
  279         -
        ::std::fmt::Debug,
  280         -
        ::std::hash::Hash,
  281         -
    )]
  282         -
    pub struct Name(pub(crate) ::std::string::String);
  283         -
    impl Name {
  284         -
        /// Extracts a string slice containing the entire underlying `String`.
  285         -
        pub fn as_str(&self) -> &str {
  286         -
            &self.0
  287         -
        }
  288         -
  289         -
        /// Returns an immutable reference to the underlying [`::std::string::String`].
  290         -
        pub fn inner(&self) -> &::std::string::String {
  291         -
            &self.0
  292         -
        }
  293         -
  294         -
        /// Consumes the value, returning the underlying [`::std::string::String`].
  295         -
        pub fn into_inner(self) -> ::std::string::String {
  296         -
            self.0
  297         -
        }
  298         -
    }
  299         -
    impl Name {
  300         -
        fn check_length(
  301         -
            string: &str,
  302         -
        ) -> ::std::result::Result<(), crate::input::test_operation_input::name::ConstraintViolation>
  303         -
        {
  304         -
            let length = string.chars().count();
  305         -
  306         -
            if (1..=10).contains(&length) {
  307         -
                Ok(())
  308         -
            } else {
  309         -
                Err(crate::input::test_operation_input::name::ConstraintViolation::Length(length))
  310         -
            }
  311         -
        }
  312         -
    }
  313         -
    impl ::std::convert::TryFrom<::std::string::String> for Name {
  314         -
        type Error = crate::input::test_operation_input::name::ConstraintViolation;
  315         -
  316         -
        /// Constructs a `Name` from an [`::std::string::String`], failing when the provided value does not satisfy the modeled constraints.
  317         -
        fn try_from(value: ::std::string::String) -> ::std::result::Result<Self, Self::Error> {
  318         -
            Self::check_length(&value)?;
  319         -
  320         -
            Ok(Self(value))
  321         -
        }
  322         -
    }
  323         -
    impl crate::constrained::Constrained for Name {
  324         -
        type Unconstrained = ::std::string::String;
  325         -
    }
  326         -
  327         -
    impl ::std::convert::From<::std::string::String>
  328         -
        for crate::constrained::MaybeConstrained<crate::input::test_operation_input::Name>
  329         -
    {
  330         -
        fn from(value: ::std::string::String) -> Self {
  331         -
            Self::Unconstrained(value)
  332         -
        }
  333         -
    }
  334         -
  335         -
    impl ::std::fmt::Display for Name {
  336         -
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  337         -
            self.0.fmt(f)
  338         -
        }
  339         -
    }
  340         -
  341         -
    impl ::std::convert::From<Name> for ::std::string::String {
  342         -
        fn from(value: Name) -> Self {
  343         -
            value.into_inner()
  344         -
        }
  345         -
    }
  346         -
  347         -
    /// See [`TestOperationInputAge`](crate::input::test_operation_input::Age).
  348         -
    pub mod age {
  349         -
  350         -
        #[derive(Debug, PartialEq)]
  351         -
        pub enum ConstraintViolation {
  352         -
            Range(i32),
  353         -
        }
  354         -
  355         -
        impl ::std::fmt::Display for ConstraintViolation {
  356         -
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  357         -
                write!(f, "Value for `com.aws.example.synthetic#TestOperationInputAge`failed to satisfy constraint: Member must be between 1 and 100, inclusive")
  358         -
            }
  359         -
        }
  360         -
  361         -
        impl ::std::error::Error for ConstraintViolation {}
  362         -
        impl ConstraintViolation {
  363         -
            pub(crate) fn as_validation_exception_field(
  364         -
                self,
  365         -
                path: ::std::string::String,
  366         -
            ) -> crate::model::CustomValidationField {
  367         -
                match self {
  368         -
                                Self::Range(_) => crate::model::CustomValidationField {
  369         -
                                    custom_field_name: path.clone(),custom_field_message: format!("Value at '{}' failed to satisfy constraint: Member must be between 1 and 100, inclusive", &path)
  370         -
                                },
  371         -
                            }
  372         -
            }
  373         -
        }
  374         -
    }
  375         -
    /// See [`TestOperationInputName`](crate::input::test_operation_input::Name).
  376         -
    pub mod name {
  377         -
  378         -
        #[derive(Debug, PartialEq)]
  379         -
        pub enum ConstraintViolation {
  380         -
            /// Error when a string doesn't satisfy its `@length` requirements.
  381         -
            Length(usize),
  382         -
        }
  383         -
  384         -
        impl ::std::fmt::Display for ConstraintViolation {
  385         -
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  386         -
                let message = match self {
  387         -
                    Self::Length(length) => {
  388         -
                        format!("Value with length {} provided for 'com.aws.example.synthetic#TestOperationInputName' failed to satisfy constraint: Member must have length between 1 and 10, inclusive", length)
  389         -
                    }
  390         -
                };
  391         -
                write!(f, "{message}")
  392         -
            }
  393         -
        }
  394         -
  395         -
        impl ::std::error::Error for ConstraintViolation {}
  396         -
        impl ConstraintViolation {
  397         -
            pub(crate) fn as_validation_exception_field(
  398         -
                self,
  399         -
                path: ::std::string::String,
  400         -
            ) -> crate::model::CustomValidationField {
  401         -
                match self {
  402         -
                                Self::Length(length) => crate::model::CustomValidationField {
  403         -
                                                    custom_field_name: path.clone(),custom_field_message: format!("Value with length {} at '{}' failed to satisfy constraint: Member must have length between 1 and 10, inclusive", length, &path)
  404         -
                                                },
  405         -
                            }
  406         -
            }
  407         -
        }
  408         -
    }
  409         -
}

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

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

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

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

@@ -1,0 +186,0 @@
    1         -
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2         -
#[allow(missing_docs)] // documentation missing in model
    3         -
#[derive(
    4         -
    ::std::clone::Clone, ::std::cmp::Eq, ::std::cmp::PartialEq, ::std::fmt::Debug, ::std::hash::Hash,
    5         -
)]
    6         -
pub struct 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         -
}