-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of Unit type in server event stream creates non-compiling code #2546
Comments
Note that this also applies to any union, streaming or not |
github-merge-queue bot
pushed a commit
that referenced
this issue
Apr 9, 2024
## Motivation and Context Unions that have a [unit target member shape](https://smithy.io/2.0/spec/model.html#unit-type) do not have an associated data in the generated Rust enum. Closes Issue: [2546](#2546) ## Description On the **server** side, when the union has constrained members, the code generated for the conversion from the `Unconstrained` type to the `Constrained` type incorrectly assumed that each Rust enum would have associated data. ``` rust-server-codegen/src/unconstrained.rs:31:129 | | crate::unconstrained::some_union_with_unit_unconstrained::SomeUnionWithUnitUnconstrained::Option1(unconstrained) => Self::Option1( | -^^^^^^^^^^^^- help: consider using a semicolon here to finish the statement: `;` | _________________________________________________________________________________________________________________________________| | | | | unconstrained | | ), | |_____________- call expression requires function | ::: rust-server-codegen/src/model.rs:152:5 | | Option1, | ------- `SomeUnionWithUnit::Option1` defined here ``` The marshaling code for event streams with unit target types incorrectly assumed that the variant would have associated data. ``` rust-server-codegen/src/event_stream_serde.rs impl ::aws_smithy_eventstream::frame::MarshallMessage for TestEventMarshaller { fn marshal() { let payload = match input { Self::Input::KeepAlive(inner) => { ``` On the **client** side, the `event_stream_serde` code incorrectly assumes that a union member, which has the `@streaming` trait applied to it, takes a `model::Unit` type. ``` rust-client-codegen/src/event_stream_serde.rs: | | crate::types::TestEvent::KeepAlive(crate::types::Unit::builder().build()), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------- | | | call expression requires function | ::: rust-client-codegen/src/types/_test_event.rs | | KeepAlive, | --------- `TestEvent::KeepAlive` defined here ``` ## Testing A unit test has been added that tests the following model: ``` $version: "2" namespace com.example use aws.protocols#restJson1 use smithy.framework#ValidationException @restJson1 @title("Test Service") service TestService { version: "0.1", operations: [ TestOperation TestSimpleUnionWithUnit ] } @http(uri: "/testunit", method: "POST") operation TestSimpleUnionWithUnit { input := { @required request: SomeUnionWithUnit } output := { result : SomeUnionWithUnit } errors: [ ValidationException ] } @Length(min: 13) string StringRestricted union SomeUnionWithUnit { Option1: Unit Option2: StringRestricted } @http(uri: "/test", method: "POST") operation TestOperation { input := { payload: String } output := { @httpPayload events: TestEvent }, errors: [ValidationException] } @streaming union TestEvent { KeepAlive: Unit, Response: TestResponseEvent, } structure TestResponseEvent { data: String } ``` --------- Co-authored-by: Fahad Zubair <fahadzub@amazon.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When attempting to generate server code that returns an event stream, an event type referencing
smithy.api#Unit
generates code that fails to compile, instead producing an error.smithy-rs version appears to be 0.54.4
A reproducible example is:
The error produced is:
The text was updated successfully, but these errors were encountered: