Skip to content
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

httpPayload does not work on union shapes #1896

Closed
david-perez opened this issue Oct 24, 2022 · 1 comment · Fixed by #2969
Closed

httpPayload does not work on union shapes #1896

david-perez opened this issue Oct 24, 2022 · 1 comment · Fixed by #2969
Assignees
Labels
bug Something isn't working

Comments

@david-perez
Copy link
Contributor

$version: "1.0"

namespace com.amazonaws.simple

use aws.protocols#restJson1

@restJson1
service SimpleService {
    operations: [
        HttpPayloadUnion,
// No AWS protocol supports this: https://github.com/awslabs/smithy/blob/3a0d0233b2cbffebae3e14459f8aea2e83978c72/smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/protocols/ProtocolHttpPayloadValidator.java#L99-L100
//      HttpPayloadList,
//      HttpPayloadMap,
    ],
}

@http(uri: "/http-payload-union", method: "POST")
operation HttpPayloadUnion {
    input: HttpPayloadUnionInputOutput,
    output: HttpPayloadUnionInputOutput,
}

@http(uri: "/http-payload-list", method: "POST")
operation HttpPayloadList {
    input: HttpPayloadListInputOutput,
    output: HttpPayloadListInputOutput,
}

@http(uri: "/http-payload-map", method: "POST")
operation HttpPayloadMap {
    input: HttpPayloadMapInputOutput,
    output: HttpPayloadMapInputOutput,
}

structure HttpPayloadUnionInputOutput {
    @httpPayload
    unionShape: UnionShape
}

structure HttpPayloadListInputOutput {
    @httpPayload
    listShape: ListShape
}

structure HttpPayloadMapInputOutput {
    @httpPayload
    mapShape: MapShape
}

union UnionShape {
    listVariant: ListShape,
    mapVariant: MapShape
}

list ListShape {
    member: String
}

map MapShape {
    key: String,
    value: String
}

Generates in operation_ser.rs:

pub fn serialize_payload_http_payload_union_output(
    payload: &std::option::Option<crate::model::UnionShape>,
) -> Result<std::vec::Vec<u8>, aws_smithy_http::operation::BuildError> {
    let payload = match payload.as_ref() {
        Some(t) => t,
        None => return Ok(),     ■■ supplied 0 arguments
    };
    Ok(
        crate::operation_ser::serialize_member_com_amazonaws_simple_synthetic_http_payload_union_output_union_shape(payload)?
    )
}

Relevant generator code:

https://github.com/awslabs/smithy-rs/blob/ca2c7883e7c252b7686314b404ecc11d408460f5/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt#L257-L281

The httpPayload trait:

can be applied to structure members that target a string, blob, structure, union, document, map, or list.

However, we're only handling string, blob, document, and structure shapes.

Of note is that no AWS protocol supports list or map, but HttpBoundProtocolPayloadGenerator is protocol-agnostic (in that it handles all protocols that support HTTP binding traits). That's something to take into account if/when we ever support a non-AWS protocol where binding to list or map shapes is allowed.

When we fix this bug, we should ensure to include an else branch to that when that aborts code generation with an informative message, and contribute HTTP protocol tests to awslabs/smithy.

@david-perez david-perez added the bug Something isn't working label Oct 24, 2022
@82marbag 82marbag self-assigned this Oct 24, 2022
@david-perez
Copy link
Contributor Author

I think we're blocked on smithy-lang/smithy#1462.

@jdisanti jdisanti removed the blocked label Aug 30, 2023
@jdisanti jdisanti assigned jdisanti and unassigned 82marbag Aug 30, 2023
github-merge-queue bot pushed a commit that referenced this issue Aug 31, 2023
This PR incorporates the new test cases in Smithy from
smithy-lang/smithy#1908, and adds support to
`@restXml` and `@restJson1` for unions with the `@httpPayload` trait.
This resolves #1896.

This also fixes code generation for the latest `medicalimaging` SDK
model.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
ysaito1001 pushed a commit that referenced this issue Sep 15, 2023
This PR incorporates the new test cases in Smithy from
smithy-lang/smithy#1908, and adds support to
`@restXml` and `@restJson1` for unions with the `@httpPayload` trait.
This resolves #1896.

This also fixes code generation for the latest `medicalimaging` SDK
model.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
rcoh added a commit to awslabs/aws-sdk-rust that referenced this issue Nov 2, 2023
Update to the first commit where nothing in history has a bad revision:

```
 git rev-list 5c6b1a1..release-2023-11-01 | tac | xargs -I {} bash -ce 'git checkout {} && grep "smithy-lang/smithy-rs#1896" codegen-core -r'
```
Velfi pushed a commit to awslabs/aws-sdk-rust that referenced this issue Nov 2, 2023
Update to the first commit where nothing in history has a bad revision:

```
 git rev-list 5c6b1a1..release-2023-11-01 | tac | xargs -I {} bash -ce 'git checkout {} && grep "smithy-lang/smithy-rs#1896" codegen-core -r'
```

<!--

IMPORTANT:

> Making changes to examples? 

Be sure to make example changes in the awsdocs/aws-doc-sdk-examples
repository (https://github.com/awsdocs/aws-doc-sdk-examples).
The examples in aws-sdk-rust are copied from the `rust_dev_preview/`
directory in that repository.


> Making changes to code?

All the code in aws-sdk-rust is auto-generated by smithy-rs
(https://github.com/awslabs/smithy-rs).
Changes to code need to be made in that repository.

-->


## Motivation and Context
<!-- Why is this change required? What problem does it solve? -->
<!-- If it fixes an open issue, please link to the issue here -->

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants