Skip to content

Commit dc970b3

Browse files
authored
Re-export HttpRequest and HttpResponse in client crates (#3762)
## Motivation and Context #3591 ## Description In early days of smithy-rs, we used to re-export [Request](https://docs.rs/aws-sdk-s3/0.25.0/aws_sdk_s3/client/customize/struct.Request.html) and [Response](https://docs.rs/aws-sdk-s3/0.25.0/aws_sdk_s3/client/customize/struct.Request.html) types. When we overhauled the underlying smithy runtime from middleware to orchestrator, we did not re-export the corresponding types [HttpRequest](https://docs.rs/aws-smithy-runtime-api/latest/aws_smithy_runtime_api/client/orchestrator/type.HttpRequest.html) and [HttpResponse](https://docs.rs/aws-smithy-runtime-api/latest/aws_smithy_runtime_api/client/orchestrator/type.HttpResponse.html) to client crates. This PR will re-export them in `crate::config::http`. ## Testing Added a new test file for `ClientRuntimeTypesReExportGenerator.kt` that verifies re-exports. ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent e4a58c3 commit dc970b3

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

CHANGELOG.next.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ message = "Add support for `operationContextParams` Endpoints trait"
2222
references = ["smithy-rs#3755"]
2323
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
2424
author = "landonxjames"
25+
26+
[[aws-sdk-rust]]
27+
message = "`aws_smithy_runtime_api::client::orchestrator::HttpRequest` and `aws_smithy_runtime_api::client::orchestrator::HttpResponse` are now re-exported in AWS SDK clients so that using these types does not require directly depending on `aws-smithy-runtime-api`."
28+
references = ["smithy-rs#3591"]
29+
meta = { "breaking" = false, "tada" = false, "bug" = false }
30+
author = "ysaito1001"
31+
32+
[[smithy-rs]]
33+
message = "`aws_smithy_runtime_api::client::orchestrator::HttpRequest` and `aws_smithy_runtime_api::client::orchestrator::HttpResponse` are now re-exported in generated clients so that using these types does not require directly depending on `aws-smithy-runtime-api`."
34+
references = ["smithy-rs#3591"]
35+
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
36+
author = "ysaito1001"

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustModule.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,17 @@ object ClientRustModule {
6868
/** crate::config::endpoint */
6969
val endpoint = RustModule.public("endpoint", parent = self)
7070

71+
/** crate::config::http */
72+
val http = RustModule.public("http", parent = self)
73+
74+
/** crate::config::interceptors */
75+
val interceptors = RustModule.public("interceptors", parent = self)
76+
7177
/** crate::config::retry */
7278
val retry = RustModule.public("retry", parent = self)
7379

7480
/** crate::config::timeout */
7581
val timeout = RustModule.public("timeout", parent = self)
76-
77-
/** crate::config::interceptors */
78-
val interceptors = RustModule.public("interceptors", parent = self)
7982
}
8083

8184
val Error = RustModule.public("error")
@@ -122,6 +125,7 @@ class ClientModuleDocProvider(
122125
ClientRustModule.Config.endpoint -> strDoc("Types needed to configure endpoint resolution.")
123126
ClientRustModule.Config.retry -> strDoc("Retry configuration.")
124127
ClientRustModule.Config.timeout -> strDoc("Timeout configuration.")
128+
ClientRustModule.Config.http -> strDoc("HTTP request and response types.")
125129
ClientRustModule.Config.interceptors -> strDoc("Types needed to implement [`Intercept`](crate::config::Intercept).")
126130
ClientRustModule.Error -> strDoc("Common errors and error handling utilities.")
127131
ClientRustModule.Operation -> strDoc("All operations that this crate can perform.")

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientRuntimeTypesReExportGenerator.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ class ClientRuntimeTypesReExportGenerator(
5656
"ShouldAttempt" to smithyRuntimeApi.resolve("client::retries::ShouldAttempt"),
5757
)
5858
}
59+
rustCrate.withModule(ClientRustModule.Config.http) {
60+
rustTemplate(
61+
"""
62+
pub use #{HttpRequest};
63+
pub use #{HttpResponse};
64+
""",
65+
"HttpRequest" to smithyRuntimeApi.resolve("client::orchestrator::HttpRequest"),
66+
"HttpResponse" to smithyRuntimeApi.resolve("client::orchestrator::HttpResponse"),
67+
)
68+
}
5969
rustCrate.withModule(ClientRustModule.Config.interceptors) {
6070
rustTemplate(
6171
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.client.smithy.generators
7+
8+
import org.junit.jupiter.api.Test
9+
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
10+
import software.amazon.smithy.rust.codegen.core.rustlang.rust
11+
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
12+
import software.amazon.smithy.rust.codegen.core.testutil.unitTest
13+
14+
class ClientRuntimeTypesReExportGeneratorTest {
15+
private val model =
16+
"""
17+
namespace test
18+
use aws.protocols#awsJson1_0
19+
20+
@awsJson1_0
21+
service HelloService {
22+
operations: [],
23+
version: "1"
24+
}
25+
""".asSmithyModel()
26+
27+
@Test
28+
fun `it should reexport client runtime types`() {
29+
clientIntegrationTest(model) { _, crate ->
30+
crate.unitTest {
31+
rust(
32+
"""
33+
##[allow(unused_imports)]
34+
{
35+
use crate::config::ConfigBag;
36+
use crate::config::RuntimeComponents;
37+
use crate::config::IdentityCache;
38+
39+
use crate::config::endpoint::SharedEndpointResolver;
40+
use crate::config::endpoint::EndpointFuture;
41+
use crate::config::endpoint::Endpoint;
42+
43+
use crate::config::retry::ClassifyRetry;
44+
use crate::config::retry::RetryAction;
45+
use crate::config::retry::ShouldAttempt;
46+
47+
use crate::config::http::HttpRequest;
48+
use crate::config::http::HttpResponse;
49+
50+
use crate::config::interceptors::AfterDeserializationInterceptorContextRef;
51+
use crate::config::interceptors::BeforeDeserializationInterceptorContextMut;
52+
use crate::config::interceptors::BeforeDeserializationInterceptorContextRef;
53+
use crate::config::interceptors::BeforeSerializationInterceptorContextMut;
54+
use crate::config::interceptors::BeforeSerializationInterceptorContextRef;
55+
use crate::config::interceptors::BeforeTransmitInterceptorContextMut;
56+
use crate::config::interceptors::BeforeTransmitInterceptorContextRef;
57+
use crate::config::interceptors::FinalizerInterceptorContextMut;
58+
use crate::config::interceptors::FinalizerInterceptorContextRef;
59+
use crate::config::interceptors::InterceptorContext;
60+
61+
use crate::error::BoxError;
62+
}
63+
""",
64+
)
65+
}
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)