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