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-bound constrained shapes don't work in the server #2583

Closed
david-perez opened this issue Apr 17, 2023 · 0 comments · Fixed by #2584
Closed

@httpPayload-bound constrained shapes don't work in the server #2583

david-perez opened this issue Apr 17, 2023 · 0 comments · Fixed by #2584
Labels
bug Something isn't working server Rust server SDK

Comments

@david-perez
Copy link
Contributor

Internal tracking: P73926463

(Somewhat) minimal reproducer:

$version: "2.0"

namespace com.amazonaws.simple

use aws.protocols#restJson1
use smithy.framework#ValidationException

@restJson1
service SimpleService {
    operations: [
        Dummy
    ]
}

@http(code: 200, method: "PUT", uri: "/dummy")
operation Dummy {
    input: Dummy_Input
    output: Dummy_Output
    errors: [ValidationException]
}

@input
structure Dummy_Input {
    @required
    @httpPayload
    template: Fancy,
}

@output
structure Dummy_Output {
}

enum ThisOrThat {
    This
    That
}

structure Fancy {
    this_or_that: ThisOrThat
}

Produces:

pub fn deser_structure_crate_model_fancy_payload(
    input: &[u8],
) -> Result<crate::model::Fancy, aws_smithy_json::deserialize::error::DeserializeError> {
    let mut tokens_owned =
        aws_smithy_json::deserialize::json_token_iter(crate::json_deser::or_empty_doc(input))
            .peekable();
    let tokens = &mut tokens_owned;
    let result = crate::json_deser::deser_structure_crate_model_fancy(tokens)?.ok_or_else(|| {
        aws_smithy_json::deserialize::error::DeserializeError::custom(
            "expected payload member value",
        )
    });
    if tokens.next().is_some() {
        return Err(
            aws_smithy_json::deserialize::error::DeserializeError::custom(
                "found more JSON tokens after completing parsing",
            ),
        );
    }
    result
}

Which causes:

error[E0308]: mismatched types
  --> simple/src/json_deser.rs:70:5
   |
53 | ) -> Result<crate::model::Fancy, aws_smithy_json::deserialize::error::DeserializeError> {
   |      ---------------------------------------------------------------------------------- expected `Result<Fancy, DeserializeError>` because of return type
...
70 |     result
   |     ^^^^^^ expected struct `Fancy`, found struct `Builder`
   |
   = note: expected enum `Result<Fancy, _>`
              found enum `Result<fancy::Builder, _>`
@david-perez david-perez added bug Something isn't working server Rust server SDK labels Apr 17, 2023
david-perez added a commit that referenced this issue Apr 17, 2023
The issue is we're not changing the return type of the payload
deserializing function to be the unconstrained type (e.g. the builder in
case of an `@httpPayload`-bound structure shape) when the shape is
constrained.

Yet another example of why code-generating `constraints.smithy` (see #2101)
is important.

Closes #2583.
unexge pushed a commit that referenced this issue Apr 24, 2023
…#2584)

The issue is we're not changing the return type of the payload
deserializing function to be the unconstrained type (e.g. the builder in
case of an `@httpPayload`-bound structure shape) when the shape is
constrained.

Yet another example of why code-generating `constraints.smithy` (see
#2101)
is important.

Closes #2583.

## Testing

The added integration test operation fails to compile without this
patch.

## 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

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
rcoh pushed a commit that referenced this issue Apr 24, 2023
…#2584)

The issue is we're not changing the return type of the payload
deserializing function to be the unconstrained type (e.g. the builder in
case of an `@httpPayload`-bound structure shape) when the shape is
constrained.

Yet another example of why code-generating `constraints.smithy` (see
#2101)
is important.

Closes #2583.

## Testing

The added integration test operation fails to compile without this
patch.

## 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

----

_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 server Rust server SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant