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_legacy_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(crate::constrained::MaybeConstrained::Constrained);
|
147 + | self
|
148 + | }
|
149 + | #[allow(missing_docs)] // documentation missing in model
|
150 + | pub(crate) fn set_age(
|
151 + | mut self,
|
152 + | input: Option<
|
153 + | impl ::std::convert::Into<
|
154 + | crate::constrained::MaybeConstrained<crate::input::test_operation_input::Age>,
|
155 + | >,
|
156 + | >,
|
157 + | ) -> Self {
|
158 + | self.age = input.map(|v| v.into());
|
159 + | self
|
160 + | }
|
161 + | /// Consumes the builder and constructs a [`TestOperationInput`](crate::input::TestOperationInput).
|
162 + | ///
|
163 + | /// The builder fails to construct a [`TestOperationInput`](crate::input::TestOperationInput) if a [`ConstraintViolation`] occurs.
|
164 + | ///
|
165 + | /// If the builder fails, it will return the _first_ encountered [`ConstraintViolation`].
|
166 + | pub fn build(self) -> Result<crate::input::TestOperationInput, ConstraintViolation> {
|
167 + | self.build_enforcing_all_constraints()
|
168 + | }
|
169 + | fn build_enforcing_all_constraints(
|
170 + | self,
|
171 + | ) -> Result<crate::input::TestOperationInput, ConstraintViolation> {
|
172 + | Ok(crate::input::TestOperationInput {
|
173 + | name: self
|
174 + | .name
|
175 + | .map(|v| match v {
|
176 + | crate::constrained::MaybeConstrained::Constrained(x) => Ok(x),
|
177 + | crate::constrained::MaybeConstrained::Unconstrained(x) => x.try_into(),
|
178 + | })
|
179 + | .map(|res| res.map_err(ConstraintViolation::Name))
|
180 + | .transpose()?
|
181 + | .ok_or(ConstraintViolation::MissingName)?,
|
182 + | age: self
|
183 + | .age
|
184 + | .map(|v| match v {
|
185 + | crate::constrained::MaybeConstrained::Constrained(x) => Ok(x),
|
186 + | crate::constrained::MaybeConstrained::Unconstrained(x) => x.try_into(),
|
187 + | })
|
188 + | .map(|res| res.map_err(ConstraintViolation::Age))
|
189 + | .transpose()?,
|
190 + | })
|
191 + | }
|
192 + | }
|
193 + | #[allow(missing_docs)] // documentation missing in model
|
194 + | ///
|
195 + | /// This is a constrained type because its corresponding modeled Smithy shape has one or more
|
196 + | /// [constraint traits]. Use [`Age::try_from`] to construct values of this type.
|
197 + | ///
|
198 + | /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
|
199 + | ///
|
200 + | #[derive(
|
201 + | ::std::clone::Clone,
|
202 + | ::std::cmp::Eq,
|
203 + | ::std::cmp::PartialEq,
|
204 + | ::std::fmt::Debug,
|
205 + | ::std::hash::Hash,
|
206 + | )]
|
207 + | pub struct Age(pub(crate) i32);
|
208 + | impl Age {
|
209 + | /// Returns an immutable reference to the underlying [`i32`].
|
210 + | pub fn inner(&self) -> &i32 {
|
211 + | &self.0
|
212 + | }
|
213 + |
|
214 + | /// Consumes the value, returning the underlying [`i32`].
|
215 + | pub fn into_inner(self) -> i32 {
|
216 + | self.0
|
217 + | }
|
218 + | }
|
219 + |
|
220 + | impl crate::constrained::Constrained for Age {
|
221 + | type Unconstrained = i32;
|
222 + | }
|
223 + |
|
224 + | impl ::std::convert::From<i32>
|
225 + | for crate::constrained::MaybeConstrained<crate::input::test_operation_input::Age>
|
226 + | {
|
227 + | fn from(value: i32) -> Self {
|
228 + | Self::Unconstrained(value)
|
229 + | }
|
230 + | }
|
231 + |
|
232 + | impl ::std::fmt::Display for Age {
|
233 + | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
234 + | self.0.fmt(f)
|
235 + | }
|
236 + | }
|
237 + |
|
238 + | impl ::std::convert::From<Age> for i32 {
|
239 + | fn from(value: Age) -> Self {
|
240 + | value.into_inner()
|
241 + | }
|
242 + | }
|
243 + | impl Age {
|
244 + | fn check_range(
|
245 + | value: i32,
|
246 + | ) -> ::std::result::Result<(), crate::input::test_operation_input::age::ConstraintViolation>
|
247 + | {
|
248 + | if (1..=100).contains(&value) {
|
249 + | Ok(())
|
250 + | } else {
|
251 + | Err(crate::input::test_operation_input::age::ConstraintViolation::Range(value))
|
252 + | }
|
253 + | }
|
254 + | }
|
255 + | impl ::std::convert::TryFrom<i32> for Age {
|
256 + | type Error = crate::input::test_operation_input::age::ConstraintViolation;
|
257 + |
|
258 + | /// Constructs a `Age` from an [`i32`], failing when the provided value does not satisfy the modeled constraints.
|
259 + | fn try_from(value: i32) -> ::std::result::Result<Self, Self::Error> {
|
260 + | Self::check_range(value)?;
|
261 + |
|
262 + | Ok(Self(value))
|
263 + | }
|
264 + | }
|
265 + | #[allow(missing_docs)] // documentation missing in model
|
266 + | ///
|
267 + | /// This is a constrained type because its corresponding modeled Smithy shape has one or more
|
268 + | /// [constraint traits]. Use [`Name::try_from`] to construct values of this type.
|
269 + | ///
|
270 + | /// [constraint traits]: https://smithy.io/2.0/spec/constraint-traits.html
|
271 + | ///
|
272 + | #[derive(
|
273 + | ::std::clone::Clone,
|
274 + | ::std::cmp::Eq,
|
275 + | ::std::cmp::PartialEq,
|
276 + | ::std::fmt::Debug,
|
277 + | ::std::hash::Hash,
|
278 + | )]
|
279 + | pub struct Name(pub(crate) ::std::string::String);
|
280 + | impl Name {
|
281 + | /// Extracts a string slice containing the entire underlying `String`.
|
282 + | pub fn as_str(&self) -> &str {
|
283 + | &self.0
|
284 + | }
|
285 + |
|
286 + | /// Returns an immutable reference to the underlying [`::std::string::String`].
|
287 + | pub fn inner(&self) -> &::std::string::String {
|
288 + | &self.0
|
289 + | }
|
290 + |
|
291 + | /// Consumes the value, returning the underlying [`::std::string::String`].
|
292 + | pub fn into_inner(self) -> ::std::string::String {
|
293 + | self.0
|
294 + | }
|
295 + | }
|
296 + | impl Name {
|
297 + | fn check_length(
|
298 + | string: &str,
|
299 + | ) -> ::std::result::Result<(), crate::input::test_operation_input::name::ConstraintViolation>
|
300 + | {
|
301 + | let length = string.chars().count();
|
302 + |
|
303 + | if (1..=10).contains(&length) {
|
304 + | Ok(())
|
305 + | } else {
|
306 + | Err(crate::input::test_operation_input::name::ConstraintViolation::Length(length))
|
307 + | }
|
308 + | }
|
309 + | }
|
310 + | impl ::std::convert::TryFrom<::std::string::String> for Name {
|
311 + | type Error = crate::input::test_operation_input::name::ConstraintViolation;
|
312 + |
|
313 + | /// Constructs a `Name` from an [`::std::string::String`], failing when the provided value does not satisfy the modeled constraints.
|
314 + | fn try_from(value: ::std::string::String) -> ::std::result::Result<Self, Self::Error> {
|
315 + | Self::check_length(&value)?;
|
316 + |
|
317 + | Ok(Self(value))
|
318 + | }
|
319 + | }
|
320 + | impl crate::constrained::Constrained for Name {
|
321 + | type Unconstrained = ::std::string::String;
|
322 + | }
|
323 + |
|
324 + | impl ::std::convert::From<::std::string::String>
|
325 + | for crate::constrained::MaybeConstrained<crate::input::test_operation_input::Name>
|
326 + | {
|
327 + | fn from(value: ::std::string::String) -> Self {
|
328 + | Self::Unconstrained(value)
|
329 + | }
|
330 + | }
|
331 + |
|
332 + | impl ::std::fmt::Display for Name {
|
333 + | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
334 + | self.0.fmt(f)
|
335 + | }
|
336 + | }
|
337 + |
|
338 + | impl ::std::convert::From<Name> for ::std::string::String {
|
339 + | fn from(value: Name) -> Self {
|
340 + | value.into_inner()
|
341 + | }
|
342 + | }
|
343 + |
|
344 + | /// See [`TestOperationInputAge`](crate::input::test_operation_input::Age).
|
345 + | pub mod age {
|
346 + |
|
347 + | #[derive(Debug, PartialEq)]
|
348 + | pub enum ConstraintViolation {
|
349 + | Range(i32),
|
350 + | }
|
351 + |
|
352 + | impl ::std::fmt::Display for ConstraintViolation {
|
353 + | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
354 + | write!(f, "Value for `com.aws.example.synthetic#TestOperationInputAge`failed to satisfy constraint: Member must be between 1 and 100, inclusive")
|
355 + | }
|
356 + | }
|
357 + |
|
358 + | impl ::std::error::Error for ConstraintViolation {}
|
359 + | impl ConstraintViolation {
|
360 + | pub(crate) fn as_validation_exception_field(
|
361 + | self,
|
362 + | path: ::std::string::String,
|
363 + | ) -> crate::model::CustomValidationField {
|
364 + | match self {
|
365 + | Self::Range(_) => crate::model::CustomValidationField {
|
366 + | custom_field_name: path.clone(),custom_field_message: format!("Value at '{}' failed to satisfy constraint: Member must be between 1 and 100, inclusive", &path)
|
367 + | },
|
368 + | }
|
369 + | }
|
370 + | }
|
371 + | }
|
372 + | /// See [`TestOperationInputName`](crate::input::test_operation_input::Name).
|
373 + | pub mod name {
|
374 + |
|
375 + | #[derive(Debug, PartialEq)]
|
376 + | pub enum ConstraintViolation {
|
377 + | /// Error when a string doesn't satisfy its `@length` requirements.
|
378 + | Length(usize),
|
379 + | }
|
380 + |
|
381 + | impl ::std::fmt::Display for ConstraintViolation {
|
382 + | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
383 + | let message = match self {
|
384 + | Self::Length(length) => {
|
385 + | 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)
|
386 + | }
|
387 + | };
|
388 + | write!(f, "{message}")
|
389 + | }
|
390 + | }
|
391 + |
|
392 + | impl ::std::error::Error for ConstraintViolation {}
|
393 + | impl ConstraintViolation {
|
394 + | pub(crate) fn as_validation_exception_field(
|
395 + | self,
|
396 + | path: ::std::string::String,
|
397 + | ) -> crate::model::CustomValidationField {
|
398 + | match self {
|
399 + | #[allow(unused_variables)]
|
400 + | Self::Length(length) => crate::model::CustomValidationField {
|
401 + | 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)
|
402 + | },
|
403 + | }
|
404 + | }
|
405 + | }
|
406 + | }
|
407 + | }
|