From d8fbf47d21463a3ac22e7fb7844a308134f615c9 Mon Sep 17 00:00:00 2001 From: Fahad Zubair Date: Mon, 30 Sep 2024 10:04:12 -0400 Subject: [PATCH] `aws_smithy_http_server::*` should be re-exported from generated crates (#3839) Many customers have reported the need to explicitly depend on the `aws-smithy-http-server` crate in their service handler code. When they re-generate the crate, they often encounter version mismatches between the `aws-smithy-http-server` crate used in the generated code and the one they use in their service handler. This version discrepancy leads to compilation errors, requiring them to manually adjust the crate versions, which adds friction to their development workflow. To resolve this issue, we now re-export all relevant types from `aws-smithy-http-server` within the generated crates. By doing so, customers can use these re-exported types directly, eliminating the need to depend on `aws-smithy-http-server` in their handler code. Additionally, the generated crates no longer have the `aws-lambda` feature flag enabled by default. This prevents the `aws-lambda` feature from being automatically enabled in `aws-smithy-http-server` when the SDK is not intended for AWS Lambda. --------- Co-authored-by: Fahad Zubair --- .changelog/4106176.md | 9 ++ .changelog/9278363.md | 10 ++ .../rust/codegen/core/rustlang/RustModule.kt | 3 +- .../codegen/server/smithy/ServerRustModule.kt | 2 +- .../ServerRequiredCustomizations.kt | 10 +- .../smithy/generators/ScopeMacroGenerator.kt | 28 ++---- .../smithy/generators/ServerRootGenerator.kt | 28 +++--- .../ServerRuntimeTypesReExportsGenerator.kt | 40 +------- .../server/smithy/ServerTypesReExportTest.kt | 96 +++++++++++++++++++ examples/pokemon-service-common/Cargo.toml | 5 +- examples/pokemon-service-common/src/lib.rs | 2 +- .../tests/plugins_execution_order.rs | 6 +- examples/pokemon-service-lambda/Cargo.toml | 1 - examples/pokemon-service-lambda/src/lib.rs | 4 +- examples/pokemon-service-lambda/src/main.rs | 5 +- examples/pokemon-service-tls/Cargo.toml | 6 +- examples/pokemon-service-tls/src/main.rs | 9 +- examples/pokemon-service/Cargo.toml | 7 +- examples/pokemon-service/src/authz.rs | 6 +- examples/pokemon-service/src/lib.rs | 2 +- examples/pokemon-service/src/main.rs | 5 +- examples/pokemon-service/src/plugin.rs | 2 +- 22 files changed, 187 insertions(+), 99 deletions(-) create mode 100644 .changelog/4106176.md create mode 100644 .changelog/9278363.md create mode 100644 codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerTypesReExportTest.kt diff --git a/.changelog/4106176.md b/.changelog/4106176.md new file mode 100644 index 0000000000..90581291df --- /dev/null +++ b/.changelog/4106176.md @@ -0,0 +1,9 @@ +--- +applies_to: ["server"] +authors: ["drganjoo"] +references: [] +breaking: true +new_feature: false +bug_fix: false +--- +The generated crates no longer have the `aws-lambda` feature flag enabled by default. This prevents the [aws-lambda](https://docs.rs/crate/aws-smithy-http-server/0.63.3/features#aws-lambda) feature from being automatically enabled in [aws-smithy-http-server](https://docs.rs/aws-smithy-http-server/0.63.3/aws_smithy_http_server/) when the SDK is not intended for AWS Lambda. diff --git a/.changelog/9278363.md b/.changelog/9278363.md new file mode 100644 index 0000000000..7b159087da --- /dev/null +++ b/.changelog/9278363.md @@ -0,0 +1,10 @@ +--- +applies_to: ["server"] +authors: ["drganjoo"] +references: [] +breaking: false +new_feature: true +bug_fix: false +--- +All relevant types from [aws-smithy-http-server](https://docs.rs/aws-smithy-http-server/0.63.3/aws_smithy_http_server/) are now re-exported within the generated crates. This removes the need to explicitly depend on [aws-smithy-http-server](https://docs.rs/aws-smithy-http-server/0.63.3/aws_smithy_http_server/) in service handler code and prevents compilation errors caused by version mismatches. + diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt index 6b0a725925..f6b20de6a9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt @@ -82,11 +82,12 @@ sealed class RustModule { parent: RustModule = LibRs, documentationOverride: String? = null, additionalAttributes: List = emptyList(), + inline: Boolean = false, ): LeafModule = new( name, visibility = Visibility.PUBLIC, - inline = false, + inline = inline, parent = parent, documentationOverride = documentationOverride, additionalAttributes = additionalAttributes, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustModule.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustModule.kt index b7e349ddc0..d364905372 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustModule.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustModule.kt @@ -41,8 +41,8 @@ object ServerRustModule { val Input = RustModule.public("input") val Output = RustModule.public("output") val Types = RustModule.public("types") - val Server = RustModule.public("server") val Service = RustModule.private("service") + val Server = RustModule.public("server", inline = true) val UnconstrainedModule = software.amazon.smithy.rust.codegen.core.smithy.UnconstrainedModule diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt index 4dc4332822..a366b39c2e 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt @@ -51,11 +51,19 @@ class ServerRequiredCustomizations : ServerCodegenDecorator { rustCrate.mergeFeature( Feature( "aws-lambda", - true, + false, listOf("aws-smithy-http-server/aws-lambda"), ), ) + rustCrate.mergeFeature( + Feature( + "request-id", + true, + listOf("aws-smithy-http-server/request-id"), + ), + ) + rustCrate.withModule(ServerRustModule.Types) { pubUseSmithyPrimitives(codegenContext, codegenContext.model, rustCrate)(this) rustTemplate( diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ScopeMacroGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ScopeMacroGenerator.kt index 1329c2b7cd..5e7a18dcb9 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ScopeMacroGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ScopeMacroGenerator.kt @@ -11,18 +11,11 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.util.toPascalCase -import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext class ScopeMacroGenerator( private val codegenContext: ServerCodegenContext, ) { - private val runtimeConfig = codegenContext.runtimeConfig - private val codegenScope = - arrayOf( - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), - ) - /** Calculate all `operationShape`s contained within the `ServiceShape`. */ private val index = TopDownIndex.of(codegenContext.model) private val operations = index.getContainedOperations(codegenContext.serviceShape).toSortedSet(compareBy { it.id }) @@ -37,7 +30,7 @@ class ScopeMacroGenerator( // When writing `macro_rules!` we add whitespace between `$` and the arguments to avoid Kotlin templating. - // To acheive the desired API we need to calculate the set theoretic complement `B \ A`. + // To achieve the desired API we need to calculate the set theoretic complement `B \ A`. // The macro below, for rules prefixed with `@`, encodes a state machine which performs this. // The initial state is `(A) () (B)`, where `A` and `B` are lists of elements of `A` and `B`. // The rules, in order: @@ -87,9 +80,9 @@ class ScopeMacroGenerator( rustTemplate( """ - /// A macro to help with scoping [plugins](#{SmithyHttpServer}::plugin) to a subset of all operations. + /// A macro to help with scoping [plugins](crate::server::plugin) to a subset of all operations. /// - /// In contrast to [`aws_smithy_http_server::scope`](#{SmithyHttpServer}::scope), this macro has knowledge + /// In contrast to [`crate::server::scope`](crate::server::scope), this macro has knowledge /// of the service and any operations _not_ specified will be placed in the opposing group. /// /// ## Example @@ -109,7 +102,7 @@ class ScopeMacroGenerator( /// } /// } /// - /// ## use #{SmithyHttpServer}::plugin::{Plugin, Scoped}; + /// ## use $crateName::server::plugin::{Plugin, Scoped}; /// ## use $crateName::scope; /// ## struct MockPlugin; /// ## impl Plugin for MockPlugin { type Output = u32; fn apply(&self, input: T) -> u32 { 3 } } @@ -125,13 +118,13 @@ class ScopeMacroGenerator( // Completed, render impls (@ $ name: ident, $ contains: ident () ($($ temp: ident)*) ($($ not_member: ident)*)) => { $( - impl #{SmithyHttpServer}::plugin::scoped::Membership<$ temp> for $ name { - type Contains = #{SmithyHttpServer}::plugin::scoped::$ contains; + impl $ crate::server::plugin::scoped::Membership<$ temp> for $ name { + type Contains = $ crate::server::plugin::scoped::$ contains; } )* $( - impl #{SmithyHttpServer}::plugin::scoped::Membership<$ not_member> for $ name { - type Contains = #{SmithyHttpServer}::plugin::scoped::$ contains; + impl $ crate::server::plugin::scoped::Membership<$ not_member> for $ name { + type Contains = $ crate::server::plugin::scoped::$ contains; } )* }; @@ -147,7 +140,7 @@ class ScopeMacroGenerator( } ) => { use $ crate::operation_shape::*; - #{SmithyHttpServer}::scope! { + $ crate::server::scope! { $(##[$ attrs])* $ vis struct $ name { includes: [$($ include),*], @@ -164,7 +157,7 @@ class ScopeMacroGenerator( ) => { use $ crate::operation_shape::*; - #{SmithyHttpServer}::scope! { + $ crate::server::scope! { $(##[$ attrs])* $ vis struct $ name { includes: [], @@ -175,7 +168,6 @@ class ScopeMacroGenerator( }; } """, - *codegenScope, "FurtherTests" to furtherTests, ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRootGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRootGenerator.kt index 177c6fa845..d23801549e 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRootGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRootGenerator.kt @@ -69,7 +69,14 @@ open class ServerRootGenerator( //! ## Using $serviceName //! //! The primary entrypoint is [`$serviceName`]: it satisfies the [`Service`](#{Tower}::Service) - //! trait and therefore can be handed to a [`hyper` server](https://github.com/hyperium/hyper) via [`$serviceName::into_make_service`] or used in Lambda via [`LambdaHandler`](#{SmithyHttpServer}::routing::LambdaHandler). + //! trait and therefore can be handed to a [`hyper` server](https://github.com/hyperium/hyper) via [`$serviceName::into_make_service`] + //! or used in AWS Lambda + ##![cfg_attr( + feature = "aws-lambda", + doc = " via [`LambdaHandler`](crate::server::routing::LambdaHandler).")] + ##![cfg_attr( + not(feature = "aws-lambda"), + doc = " by enabling the `aws-lambda` feature flag and utilizing the `LambdaHandler`.")] //! The [`crate::${InputModule.name}`], ${if (!hasErrors) "and " else ""}[`crate::${OutputModule.name}`], ${if (hasErrors) "and [`crate::${ErrorModule.name}`]" else "" } //! modules provide the types used in each operation. //! @@ -93,10 +100,8 @@ open class ServerRootGenerator( //! //! ###### Running on Lambda //! - //! This requires the `aws-lambda` feature flag to be passed to the [`#{SmithyHttpServer}`] crate. - //! //! ```rust,ignore - //! use #{SmithyHttpServer}::routing::LambdaHandler; + //! use $crateName::server::routing::LambdaHandler; //! use $crateName::$serviceName; //! //! ## async fn dummy() { @@ -120,10 +125,10 @@ open class ServerRootGenerator( //! Plugins allow you to build middleware which is aware of the operation it is being applied to. //! //! ```rust,no_run - //! ## use #{SmithyHttpServer}::plugin::IdentityPlugin as LoggingPlugin; - //! ## use #{SmithyHttpServer}::plugin::IdentityPlugin as MetricsPlugin; + //! ## use $crateName::server::plugin::IdentityPlugin as LoggingPlugin; + //! ## use $crateName::server::plugin::IdentityPlugin as MetricsPlugin; //! ## use #{Hyper}::Body; - //! use #{SmithyHttpServer}::plugin::HttpPlugins; + //! use $crateName::server::plugin::HttpPlugins; //! use $crateName::{$serviceName, ${serviceName}Config, $builderName}; //! //! let http_plugins = HttpPlugins::new() @@ -133,14 +138,14 @@ open class ServerRootGenerator( //! let builder: $builderName = $serviceName::builder(config); //! ``` //! - //! Check out [`#{SmithyHttpServer}::plugin`] to learn more about plugins. + //! Check out [`crate::server::plugin`] to learn more about plugins. //! //! #### Handlers //! //! [`$builderName`] provides a setter method for each operation in your Smithy model. The setter methods expect an async function as input, matching the signature for the corresponding operation in your Smithy model. //! We call these async functions **handlers**. This is where your application business logic lives. //! - //! Every handler must take an `Input`, and optional [`extractor arguments`](#{SmithyHttpServer}::request), while returning: + //! Every handler must take an `Input`, and optional [`extractor arguments`](crate::server::request), while returning: //! //! * A `Result` if your operation has modeled errors, or //! * An `Output` otherwise. @@ -162,7 +167,7 @@ open class ServerRootGenerator( //! ## struct Error; //! ## struct State; //! ## use std::net::SocketAddr; - //! use #{SmithyHttpServer}::request::{extension::Extension, connect_info::ConnectInfo}; + //! use $crateName::server::request::{extension::Extension, connect_info::ConnectInfo}; //! //! async fn handler_with_no_extensions(input: Input) -> Output { //! todo!() @@ -181,7 +186,7 @@ open class ServerRootGenerator( //! } //! ``` //! - //! See the [`operation module`](#{SmithyHttpServer}::operation) for information on precisely what constitutes a handler. + //! See the [`operation module`](crate::operation) for information on precisely what constitutes a handler. //! //! #### Build //! @@ -233,7 +238,6 @@ open class ServerRootGenerator( "HandlerImports" to handlerImports(crateName, operations, commentToken = "//!"), "Handlers" to handlers, "ExampleHandler" to operations.take(1).map { operation -> DocHandlerGenerator(codegenContext, operation, builderFieldNames[operation]!!, "//!").docSignature() }, - "SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(codegenContext.runtimeConfig).toType(), "Hyper" to ServerCargoDependency.HyperDev.toType(), "Tokio" to ServerCargoDependency.TokioDev.toType(), "Tower" to ServerCargoDependency.Tower.toType(), diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRuntimeTypesReExportsGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRuntimeTypesReExportsGenerator.kt index 82bf6c14f5..f15a3939b9 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRuntimeTypesReExportsGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRuntimeTypesReExportsGenerator.kt @@ -22,44 +22,8 @@ class ServerRuntimeTypesReExportsGenerator( fun render(writer: RustWriter) { writer.rustTemplate( """ - pub mod body { - pub use #{SmithyHttpServer}::body::BoxBody; - } - pub mod operation { - pub use #{SmithyHttpServer}::operation::OperationShape; - } - pub mod plugin { - pub use #{SmithyHttpServer}::plugin::HttpPlugins; - pub use #{SmithyHttpServer}::plugin::ModelPlugins; - pub use #{SmithyHttpServer}::plugin::HttpMarker; - pub use #{SmithyHttpServer}::plugin::ModelMarker; - pub use #{SmithyHttpServer}::plugin::Plugin; - pub use #{SmithyHttpServer}::plugin::PluginStack; - } - pub mod request { - pub use #{SmithyHttpServer}::request::FromParts; - - ##[cfg(feature = "aws-lambda")] - pub mod lambda { - pub use #{SmithyHttpServer}::request::lambda::Context; - } - } - pub mod response { - pub use #{SmithyHttpServer}::response::IntoResponse; - } - pub mod routing { - pub use #{SmithyHttpServer}::routing::IntoMakeService; - pub use #{SmithyHttpServer}::routing::IntoMakeServiceWithConnectInfo; - pub use #{SmithyHttpServer}::routing::Router; - - ##[cfg(feature = "aws-lambda")] - pub use #{SmithyHttpServer}::routing::LambdaHandler; - } - - pub use #{SmithyHttpServer}::instrumentation; - pub use #{SmithyHttpServer}::protocol; - - pub use #{SmithyHttpServer}::Extension; + // Re-export all types from the `aws-smithy-http-server` crate. + pub use #{SmithyHttpServer}::*; """, *codegenScope, ) diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerTypesReExportTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerTypesReExportTest.kt new file mode 100644 index 0000000000..5f8be1a9e1 --- /dev/null +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerTypesReExportTest.kt @@ -0,0 +1,96 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package software.amazon.smithy.rust.codegen.server.smithy + +import org.junit.jupiter.api.Test +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.testutil.IntegrationTestParams +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.testModule +import software.amazon.smithy.rust.codegen.core.testutil.unitTest +import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrationTest + +class ServerTypesReExportTest { + private val sampleModel = + """ + namespace amazon + use aws.protocols#restJson1 + + @restJson1 + service SampleService { + operations: [SampleOperation] + } + @http(uri: "/sample", method: "GET") + operation SampleOperation { + output := {} + } + """.asSmithyModel(smithyVersion = "2") + + @Test + fun `ensure types are exported from aws-smithy-http-server`() { + serverIntegrationTest(sampleModel, IntegrationTestParams(service = "amazon#SampleService")) { _, rustCrate -> + rustCrate.testModule { + fun Set.generateUseStatements(prefix: String) = + this.joinToString(separator = "\n") { + "#[allow(unused_imports)] use $prefix::$it;" + } + + // Ensure all types that were exported before version 0.64 and used + // under the `{generated_sdk_crate_name}::server` namespace remain available. + // Additionally, include all types requested by customers. + unitTest( + "types_exists_in_server_module", + setOf( + "extension::{OperationExtensionExt, OperationExtension}", + "plugin::Scoped", + "routing::{Route, RoutingService}", + "body::boxed", + "shape_id::ShapeId", + "body::BoxBody", + "operation::OperationShape", + "plugin::HttpPlugins", + "plugin::ModelPlugins", + "plugin::HttpMarker", + "plugin::ModelMarker", + "plugin::Plugin", + "plugin::PluginStack", + "request::{self, FromParts}", + "response::IntoResponse", + "routing::IntoMakeService", + "routing::IntoMakeServiceWithConnectInfo", + "routing::Router", + "instrumentation", + "protocol", + "Extension", + "scope", + ).generateUseStatements("crate::server"), + ) + + unitTest( + "request_id_reexports", + additionalAttributes = listOf(Attribute.featureGate("request-id")), + ) { + rustTemplate( + """ + ##[allow(unused_imports)] use crate::server::request::request_id::ServerRequestId; + """, + ) + } + + unitTest( + "aws_lambda_reexports", + additionalAttributes = listOf(Attribute.featureGate("aws-lambda")), + ) { + rustTemplate( + """ + ##[allow(unused_imports)] use crate::server::{request::lambda::Context, routing::LambdaHandler}; + """, + ) + } + } + } + } +} diff --git a/examples/pokemon-service-common/Cargo.toml b/examples/pokemon-service-common/Cargo.toml index 3121fcb11a..d7b3f5015e 100644 --- a/examples/pokemon-service-common/Cargo.toml +++ b/examples/pokemon-service-common/Cargo.toml @@ -18,8 +18,9 @@ tower = "0.4" # Local paths aws-smithy-runtime = { path = "../../rust-runtime/aws-smithy-runtime", features = ["client", "connector-hyper-0-14-x"] } aws-smithy-runtime-api = { path = "../../rust-runtime/aws-smithy-runtime-api", features = ["client"] } -aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server" } -pokemon-service-client = { path = "../pokemon-service-client" } +pokemon-service-client = { path = "../pokemon-service-client/", features = [ + "behavior-version-latest", +] } pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk" } [dev-dependencies] diff --git a/examples/pokemon-service-common/src/lib.rs b/examples/pokemon-service-common/src/lib.rs index 72f1860549..16c25e02f5 100644 --- a/examples/pokemon-service-common/src/lib.rs +++ b/examples/pokemon-service-common/src/lib.rs @@ -15,7 +15,6 @@ use std::{ }; use async_stream::stream; -use aws_smithy_http_server::Extension; use aws_smithy_runtime::client::http::hyper_014::HyperConnector; use aws_smithy_runtime_api::client::http::HttpConnector; use http::Uri; @@ -23,6 +22,7 @@ use pokemon_service_server_sdk::{ error, input, model, model::CapturingPayload, output, + server::Extension, types::{Blob, ByteStream, SdkBody}, }; use rand::{seq::SliceRandom, Rng}; diff --git a/examples/pokemon-service-common/tests/plugins_execution_order.rs b/examples/pokemon-service-common/tests/plugins_execution_order.rs index be50b50a04..62fb47ed03 100644 --- a/examples/pokemon-service-common/tests/plugins_execution_order.rs +++ b/examples/pokemon-service-common/tests/plugins_execution_order.rs @@ -10,8 +10,10 @@ use std::{ task::{Context, Poll}, }; -use aws_smithy_http_server::plugin::{HttpMarker, HttpPlugins, Plugin}; -use pokemon_service_server_sdk::{PokemonService, PokemonServiceConfig}; +use pokemon_service_server_sdk::{ + server::plugin::{HttpMarker, HttpPlugins, Plugin}, + PokemonService, PokemonServiceConfig, +}; use tower::{Layer, Service}; use aws_smithy_runtime::client::http::test_util::capture_request; diff --git a/examples/pokemon-service-lambda/Cargo.toml b/examples/pokemon-service-lambda/Cargo.toml index 39b2a48045..21318a4752 100644 --- a/examples/pokemon-service-lambda/Cargo.toml +++ b/examples/pokemon-service-lambda/Cargo.toml @@ -19,6 +19,5 @@ tracing = "0.1" lambda_http = "0.8.0" # Local paths -aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server" } pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/", features = ["aws-lambda"] } pokemon-service-common = { path = "../pokemon-service-common/" } diff --git a/examples/pokemon-service-lambda/src/lib.rs b/examples/pokemon-service-lambda/src/lib.rs index 75bf9a09f7..81f7c97cb2 100644 --- a/examples/pokemon-service-lambda/src/lib.rs +++ b/examples/pokemon-service-lambda/src/lib.rs @@ -5,14 +5,12 @@ use std::sync::Arc; -use aws_smithy_http_server::Extension; - use pokemon_service_common::State; use pokemon_service_server_sdk::{ error::{GetStorageError, StorageAccessNotAuthorized}, input::GetStorageInput, output::GetStorageOutput, - server::request::lambda::Context, + server::{request::lambda::Context, Extension}, }; /// Retrieves the user's storage and logs the lambda request ID. diff --git a/examples/pokemon-service-lambda/src/main.rs b/examples/pokemon-service-lambda/src/main.rs index 68042ec97d..a5c914534b 100644 --- a/examples/pokemon-service-lambda/src/main.rs +++ b/examples/pokemon-service-lambda/src/main.rs @@ -5,15 +5,14 @@ use std::sync::Arc; -use aws_smithy_http_server::AddExtensionLayer; - use pokemon_service_common::{ capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics, setup_tracing, stream_pokemon_radio, State, }; use pokemon_service_lambda::get_storage_lambda; use pokemon_service_server_sdk::{ - server::routing::LambdaHandler, PokemonService, PokemonServiceConfig, + server::{routing::LambdaHandler, AddExtensionLayer}, + PokemonService, PokemonServiceConfig, }; #[tokio::main] diff --git a/examples/pokemon-service-tls/Cargo.toml b/examples/pokemon-service-tls/Cargo.toml index e704b3ad0f..a14850c6f5 100644 --- a/examples/pokemon-service-tls/Cargo.toml +++ b/examples/pokemon-service-tls/Cargo.toml @@ -19,7 +19,6 @@ rustls-pemfile = "1.0.2" futures-util = { version = "0.3.29", default-features = false } # Local paths -aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server" } pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/" } pokemon-service-common = { path = "../pokemon-service-common/" } @@ -35,4 +34,7 @@ hyper-tls = { version = "0.5" } aws-smithy-http = { path = "../../rust-runtime/aws-smithy-http/" } aws-smithy-runtime = { path = "../../rust-runtime/aws-smithy-runtime", features = ["client", "connector-hyper-0-14-x"] } aws-smithy-types = { path = "../../rust-runtime/aws-smithy-types/" } -pokemon-service-client = { path = "../pokemon-service-client/" } +pokemon-service-client = { path = "../pokemon-service-client/", features = [ + "behavior-version-latest", +] } + diff --git a/examples/pokemon-service-tls/src/main.rs b/examples/pokemon-service-tls/src/main.rs index b536b9f436..fb3a16081f 100644 --- a/examples/pokemon-service-tls/src/main.rs +++ b/examples/pokemon-service-tls/src/main.rs @@ -24,9 +24,6 @@ use std::{fs::File, future, io::BufReader, net::SocketAddr, sync::Arc}; -use aws_smithy_http_server::{ - request::connect_info::ConnectInfo, routing::Connected, AddExtensionLayer, -}; use clap::Parser; use futures_util::stream::StreamExt; use tokio_rustls::{ @@ -38,7 +35,11 @@ use pokemon_service_common::{ capture_pokemon, check_health, get_pokemon_species, get_server_statistics, get_storage, setup_tracing, stream_pokemon_radio, State, }; -use pokemon_service_server_sdk::{input, output, PokemonService, PokemonServiceConfig}; +use pokemon_service_server_sdk::{ + input, output, + server::{request::connect_info::ConnectInfo, routing::Connected, AddExtensionLayer}, + PokemonService, PokemonServiceConfig, +}; use pokemon_service_tls::{DEFAULT_ADDRESS, DEFAULT_PORT, DEFAULT_TEST_CERT, DEFAULT_TEST_KEY}; #[derive(Parser, Debug)] diff --git a/examples/pokemon-service/Cargo.toml b/examples/pokemon-service/Cargo.toml index 6e5b27caa2..5afe717c6b 100644 --- a/examples/pokemon-service/Cargo.toml +++ b/examples/pokemon-service/Cargo.toml @@ -15,8 +15,7 @@ tower = "0.4" tracing = "0.1" # Local paths -aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server", features = ["request-id"] } -pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/" } +pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/", features = ["request-id"]} pokemon-service-common = { path = "../pokemon-service-common/" } [dev-dependencies] @@ -33,4 +32,6 @@ hyper-rustls = { version = "0.24", features = ["http2"] } # Local paths aws-smithy-http = { path = "../../rust-runtime/aws-smithy-http/" } -pokemon-service-client = { path = "../pokemon-service-client/" } +pokemon-service-client = { path = "../pokemon-service-client/", features = [ + "behavior-version-latest", +] } diff --git a/examples/pokemon-service/src/authz.rs b/examples/pokemon-service/src/authz.rs index 348a22f47e..51a1c82e52 100644 --- a/examples/pokemon-service/src/authz.rs +++ b/examples/pokemon-service/src/authz.rs @@ -12,12 +12,12 @@ use std::{marker::PhantomData, pin::Pin}; -use aws_smithy_http_server::{ +use pokemon_service_server_sdk::server::{ body::BoxBody, operation::OperationShape, plugin::{ModelMarker, Plugin}, + response::IntoResponse, }; -use pokemon_service_server_sdk::server::response::IntoResponse; use tower::Service; pub struct AuthorizationPlugin { @@ -109,7 +109,7 @@ where AuthorizeServiceError::InnerServiceError(e) => e.into_response(), AuthorizeServiceError::AuthorizeError { message } => http::Response::builder() .status(http::StatusCode::UNAUTHORIZED) - .body(aws_smithy_http_server::body::to_boxed(message)) + .body(pokemon_service_server_sdk::server::body::to_boxed(message)) .expect("attempted to build an invalid HTTP response; please file a bug report"), } } diff --git a/examples/pokemon-service/src/lib.rs b/examples/pokemon-service/src/lib.rs index b6521213a1..95341abd9f 100644 --- a/examples/pokemon-service/src/lib.rs +++ b/examples/pokemon-service/src/lib.rs @@ -5,11 +5,11 @@ use std::net::{IpAddr, SocketAddr}; -use aws_smithy_http_server::request::{connect_info::ConnectInfo, request_id::ServerRequestId}; use pokemon_service_server_sdk::{ error::{GetStorageError, StorageAccessNotAuthorized}, input::{DoNothingInput, GetStorageInput}, output::{DoNothingOutput, GetStorageOutput}, + server::request::{connect_info::ConnectInfo, request_id::ServerRequestId}, }; // Defaults shared between `main.rs` and `/tests`. diff --git a/examples/pokemon-service/src/main.rs b/examples/pokemon-service/src/main.rs index 97d93378ff..4420553a4d 100644 --- a/examples/pokemon-service/src/main.rs +++ b/examples/pokemon-service/src/main.rs @@ -8,7 +8,8 @@ mod plugin; use std::{net::SocketAddr, sync::Arc}; -use aws_smithy_http_server::{ +use clap::Parser; +use pokemon_service_server_sdk::server::{ extension::OperationExtensionExt, instrumentation::InstrumentExt, layer::alb_health_check::AlbHealthCheckLayer, @@ -16,7 +17,6 @@ use aws_smithy_http_server::{ request::request_id::ServerRequestIdProviderLayer, AddExtensionLayer, }; -use clap::Parser; use hyper::StatusCode; use plugin::PrintExt; @@ -54,6 +54,7 @@ pub async fn main() { includes: [GetPokemonSpecies, GetStorage] } } + // Scope the `PrintPlugin`, defined in `plugin.rs`, to `PrintScope`. let print_plugin = Scoped::new::(HttpPlugins::new().print()); diff --git a/examples/pokemon-service/src/plugin.rs b/examples/pokemon-service/src/plugin.rs index 971aebb015..a1eec0d6a6 100644 --- a/examples/pokemon-service/src/plugin.rs +++ b/examples/pokemon-service/src/plugin.rs @@ -5,7 +5,7 @@ //! Provides an example [`Plugin`] implementation - [`PrintPlugin`]. -use aws_smithy_http_server::{ +use pokemon_service_server_sdk::server::{ operation::OperationShape, plugin::{HttpMarker, HttpPlugins, Plugin, PluginStack}, service::ServiceShape,