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

Compile error when using enum as query parameter #690

Open
MikailBag opened this issue Sep 2, 2021 · 2 comments
Open

Compile error when using enum as query parameter #690

MikailBag opened this issue Sep 2, 2021 · 2 comments
Labels
bug Something isn't working client low-priority
Milestone

Comments

@MikailBag
Copy link

Consider the following code:

$version: "1.0"

namespace aws.protocoltests.tmp

use aws.protocols#restJson1

@restJson1
service Tmp {
    version: "1.0.0",
    resources: [Probe],
}

@enum([
    {
        value: "ALIVE"
    },
    {
        value: "READY"
    }
])
string Kind


structure GetProbeInput {
    @httpLabel
    @required
    kind: Kind
}

@readonly
@http(method: "GET", uri: "/health/{kind}")
operation GetProbe {
    input: GetProbeInput,
}

resource Probe {
    read: GetProbe,
}

Given such a model, smithy-rs from HEAD produces invalid client code. Build fails with an error:

error[E0277]: the trait bound `Kind: AsRef<str>` is not satisfied
  --> enum-in-query-params/rust-codegen/src/input.rs:57:51
   |
57 |         let kind = smithy_http::label::fmt_string(input_1, false);
   |                                                   ^^^^^^^ the trait `AsRef<str>` is not implemented for `Kind`
   | 
  ::: /home/mb/projects/smithy-rs/rust-runtime/smithy-http/src/label.rs:15:22
   |
15 | pub fn fmt_string<T: AsRef<str>>(t: T, greedy: bool) -> String {
   |                      ---------- required by this bound in `smithy_http::label::fmt_string`
   |
   = note: required because of the requirements on the impl of `AsRef<str>` for `&Kind`

error: aborting due to previous error

@MikailBag
Copy link
Author

Turns out, AsRef impl is only generated if enum definitions have name property set. So the fix is to add "name" fields to all enums used in URLs.

@rcoh rcoh added the bug Something isn't working label Sep 2, 2021
@rcoh
Copy link
Collaborator

rcoh commented Sep 2, 2021

thanks for the report! you'll get a nicer client if you set a Name field so that's probably what you want to do anyway, but we'll get a fix for this out as well.

@rcoh rcoh added this to the GA milestone Dec 13, 2021
@Velfi Velfi self-assigned this Apr 4, 2022
@jdisanti jdisanti removed the sdk-ga label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working client low-priority
Projects
None yet
Development

No branches or pull requests

4 participants