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