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 - | }
|