You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
impl<P, Op, S, L> Plugin<P, Op, S, L> for PrintPlugin
272
+
where
273
+
Op: OperationShape,
274
+
{
275
+
type Service = PrintService<S>;
276
+
277
+
fn apply(&self, svc: S) -> Self::Service {
278
+
PrintService { inner, name: Op::ID.name() }
279
+
}
280
+
}
281
+
```
282
+
283
+
A single `Plugin` can no longer apply a `tower::Layer` on HTTP requests/responses _and_ modelled structures at the same time (see middleware positions [C](https://awslabs.github.io/smithy-rs/design/server/middleware.html#c-operation-specific-http-middleware) and [D](https://awslabs.github.io/smithy-rs/design/server/middleware.html#d-operation-specific-model-middleware). Instead one `Plugin` must be specified for each and passed to the service builder constructor separately:
284
+
285
+
```rust
286
+
let app = PokemonService::builder_with_plugins(/* HTTP plugins */, /* model plugins */)
287
+
/* setters */
288
+
.build()
289
+
.unwrap();
290
+
```
291
+
292
+
The motivation behind this change is to simplify the job of middleware authors, separate concerns, accomodate common cases better, and to improve composition internally.
293
+
294
+
Because `Plugin` is now closer to `tower::Layer` we have two canonical converters:
295
+
296
+
```rust
297
+
use aws_smithy_http_server::plugin::{PluginLayer, LayerPlugin};
298
+
299
+
// Convert from `Layer` to `Plugin` which applies uniformly across all operations
300
+
let layer = /* some layer */;
301
+
let plugin = PluginLayer(layer);
302
+
303
+
// Convert from `Plugin` to `Layer` for some fixed protocol and operation
304
+
let plugin = /* some plugin */;
305
+
let layer = LayerPlugin::new::<SomeProtocol, SomeOperation>(plugin);
306
+
```
307
+
308
+
## Remove `Operation`
309
+
310
+
The `aws_smithy_http_server::operation::Operation` structure has now been removed. Previously, there existed a `{operation_name}_operation` setter on the service builder, which accepted an `Operation`. This allowed users to
let app = PokemonService::builder_without_plugins()
329
+
.get_pokemon_species_operation(operation)
330
+
/* other setters */
331
+
.build()
332
+
.unwrap();
333
+
```
334
+
335
+
to add a `tower::Layer` (acting on HTTP requests/responses post-routing) to a single operation.
336
+
337
+
We have seen little adoption of this API and for this reason we have opted instead to introduce a new setter, accepting a `tower::Service`, on the service builder:
338
+
339
+
```rust
340
+
let app = PokemonService::builder_without_plugins()
Copy file name to clipboardExpand all lines: codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/DocHandlerGenerator.kt
Copy file name to clipboardExpand all lines: codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ class ServerOperationGenerator(
56
56
pub struct $operationName;
57
57
58
58
impl #{SmithyHttpServer}::operation::OperationShape for $operationName {
Copy file name to clipboardExpand all lines: codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRootGenerator.kt
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ open class ServerRootGenerator(
53
53
val hasErrors = operations.any { it.errors.isNotEmpty() }
Copy file name to clipboardExpand all lines: codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRuntimeTypesReExportsGenerator.kt
-1Lines changed: 0 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,6 @@ class ServerRuntimeTypesReExportsGenerator(
28
28
}
29
29
pub mod operation {
30
30
pub use #{SmithyHttpServer}::operation::OperationShape;
31
-
pub use #{SmithyHttpServer}::operation::Operation;
0 commit comments