Unverified Commit f9c05262 authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Avoid exposing `aws_smithy_http::event_stream::receiver::Receiver` in SDK's public API (#3114)

## Motivation and Context
Implements #3100 

## Description
Currently, we expose `aws_smithy_http::event_stream::Receiver` in
generated SDKs, as shown in the following S3's example (see[ a generated
diff](https://d2luzm2xt3nokh.cloudfront.net/codegen-diff/cc303ab1a07693ab02d5ec4f06101b628d1dbabe/1aa6a8da7d2b7669ba3ab7179a1fd72aadc03162/aws-sdk-ignore-whitespace/index.html)
for
`tmp-codegen-diff/aws-sdk/sdk/s3/src/operation/select_object_content/_select_object_content_output.rs`):
```
pub struct SelectObjectContentOutput {
    <p>The array of results.</p>
    pub payload: ::aws_smithy_http::event_stream::Receiver<
        crate::types::SelectObjectContentEventStream,
        crate::types::error::SelectObjectContentEventStreamError,
    >,
...
```

This PR wraps `Receiver` in a new-type, called `EventReceiver`, which
then supports `pub async fn recv` method whose signature is the same as
`aws_smithy_http::event_stream::Receiver::recv`.

## Testing
Relied on existing tests (e.g. `s3` and `transcribestreaming`
integration tests cover uses cases affected by this change).

## 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._
parent c296e8e9
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -30,3 +30,19 @@ message = """
references = ["smithy-rs#3139"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"}
author = "ysaito1001"

[[smithy-rs]]
message = """
An operation output that supports receiving events from stream now provides a new-type wrapping `aws_smithy_http::event_stream::receiver::Receiver`. The new-type supports the `.recv()` method whose signature is the same as [`aws_smithy_http::event_stream::receiver::Receiver::recv`](https://docs.rs/aws-smithy-http/0.57.0/aws_smithy_http/event_stream/struct.Receiver.html#method.recv).
"""
references = ["smithy-rs#3100", "smithy-rs#3114"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "ysaito1001"

[[aws-sdk-rust]]
message = """
An operation output that supports receiving events from stream now provides a new-type wrapping `aws_smithy_http::event_stream::receiver::Receiver`. The new-type supports the `.recv()` method whose signature is the same as [`aws_smithy_http::event_stream::receiver::Receiver::recv`](https://docs.rs/aws-smithy-http/0.57.0/aws_smithy_http/event_stream/struct.Receiver.html#method.recv).
"""
references = ["smithy-rs#3100", "smithy-rs#3114"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "ysaito1001"
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ class EventStreamSymbolProviderTest {
            listOf(someStream, someStreamError),
        )
        outputType shouldBe RustType.Application(
            RuntimeType.eventStreamReceiver(TestRuntimeConfig).toSymbol().rustType(),
            RuntimeType.eventReceiver(TestRuntimeConfig).toSymbol().rustType(),
            listOf(someStream, someStreamError),
        )
    }
+8 −0
Original line number Diff line number Diff line
@@ -89,6 +89,14 @@ class InlineDependency(
        private fun forInlineableRustFile(name: String, vararg additionalDependencies: RustDependency) =
            forRustFile(RustModule.private(name), "/inlineable/src/$name.rs", *additionalDependencies)

        fun eventReceiver(runtimeConfig: RuntimeConfig) =
            forInlineableRustFile(
                "event_receiver",
                CargoDependency.smithyHttp(runtimeConfig),
                CargoDependency.smithyRuntimeApi(runtimeConfig),
                CargoDependency.smithyTypes(runtimeConfig),
            )

        fun defaultAuthPlugin(runtimeConfig: RuntimeConfig) = forInlineableRustFile("auth_plugin", CargoDependency.smithyRuntimeApi(runtimeConfig))

        fun jsonErrors(runtimeConfig: RuntimeConfig) =
+7 −1
Original line number Diff line number Diff line
@@ -53,7 +53,13 @@ class EventStreamSymbolProvider(
                    (shape.isOutputEventStream(model) && target == CodegenTarget.SERVER)
                val outer = when (isSender) {
                    true -> RuntimeType.eventStreamSender(runtimeConfig).toSymbol().rustType()
                    else -> RuntimeType.eventStreamReceiver(runtimeConfig).toSymbol().rustType()
                    else -> {
                        if (target == CodegenTarget.SERVER) {
                            RuntimeType.eventStreamReceiver(runtimeConfig).toSymbol().rustType()
                        } else {
                            RuntimeType.eventReceiver(runtimeConfig).toSymbol().rustType()
                        }
                    }
                }
                val rustType = RustType.Application(outer, listOf(innerT, errorT))
                return initial.toBuilder()
+3 −0
Original line number Diff line number Diff line
@@ -405,6 +405,9 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
        fun eventStreamReceiver(runtimeConfig: RuntimeConfig): RuntimeType =
            smithyHttp(runtimeConfig).resolve("event_stream::Receiver")

        fun eventReceiver(runtimeConfig: RuntimeConfig) =
            forInlineDependency(InlineDependency.eventReceiver(runtimeConfig)).resolve("EventReceiver")

        fun eventStreamSender(runtimeConfig: RuntimeConfig): RuntimeType =
            smithyHttp(runtimeConfig).resolve("event_stream::EventStreamSender")

Loading