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

Bug when using smithy-trait-codegen with @idRef #2476

Open
msosnicki opened this issue Nov 22, 2024 · 1 comment
Open

Bug when using smithy-trait-codegen with @idRef #2476

msosnicki opened this issue Nov 22, 2024 · 1 comment
Labels
bug This issue is a bug. trait-codegen

Comments

@msosnicki
Copy link
Contributor

Generating a code for the following trait:

@trait
structure someTrait {
    @idRef(failWhenMissing: true)
    targetId: String
}

renders the following java code:

    /**
     * Creates a builder used to build a {@link SomeTrait}.
     */
    public SmithyBuilder<SomeTrait> toBuilder() {
        return builder().sourceLocation(getSourceLocation())
            .targetId(targetId);
    }

    public static Builder builder() {
        return new Builder();
    }

    /**
     * Builder for {@link SomeTrait}.
     */
    public static final class Builder extends AbstractTraitBuilder<SomeTrait, Builder> {private ShapeId targetId;

        private Builder() {}

        public Builder targetId(String targetId) {
            this.targetId = targetId;
            return this;
        }

        @Override
        public SomeTrait build() {
            return new SomeTrait(this);
        }
    }

which doesn't compile, it attempts to assign a String into a ShapeId field

@hpmellema
Copy link
Contributor

hpmellema commented Nov 22, 2024

Definitely a bug, this has to do with the idref on a member incorrectly assuming the target is already an idref.

You can work around this for now by applying the @idref to a standalone shape like:
https://github.com/smithy-lang/smithy/blob/main/smithy-trait-codegen/src/test/resources/META-INF/smithy/idref/idref-struct-with-nested-refs.smithy

@hpmellema hpmellema added bug This issue is a bug. trait-codegen labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. trait-codegen
Projects
None yet
Development

No branches or pull requests

2 participants