-
Notifications
You must be signed in to change notification settings - Fork 190
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
Remove attributes annotation of Builder struct
#3674
Conversation
A new generated diff is ready to view.
A new doc preview is ready to view. |
Ok, I see that we actually need Builders to have the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM but we'd want this change too to apply to the server. Make the change to these files too:
ServerBuilderGenerator
ServerBuilderGeneratorWithoutPublicConstrainedTypes
Bonus points if you make things DRYer and/or document the motivation for this change with either a comment or a small test.
Thanks @david-perez! I will change those files too, as you requested. |
7d662a4
to
2b2a04b
Compare
Hello @david-perez , I have added the tests as you requested, to both client and server generators. Notice that I didn't need to make any changes to the server classes because they don't have the same bug as the client. Please let me know if you'd like me to do anything else in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests!
...c/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt
Show resolved
Hide resolved
Hello, how could we expedite this to be merged and available in the next release? |
I see some linting checks failed. I'll resolve these and update the branch |
The `struct` created for a Builder should not have attributes because these structs only derive from `Debug`, `PartialEq`, `Clone` and `Default`. None of these support attributes. This becomes a problem if a plugin tries to add attributes to the `metadata` field to configure the generated code for the `struct`. In this case, the attributes will also be added to the `Builder` struct; which is wrong.
Head branch was pushed to by a user without write access
I'm sorry I didn't see the |
Hello, the failing check is ci / Ask maintainer to run the PR bot and canary workflows. |
The
struct
created for a Builder should not have attributes because these structs only derive fromDebug
,PartialEq
,Clone
andDefault
. None of these support attributes.This becomes a problem if a plugin tries to add attributes to the
metadata
field to configure the generated code for thestruct
. In this case, the attributes will also be added to theBuilder
struct; which is wrong.Motivation and Context
I'm customizing client code generation by overriding the method:
I override the
symbol.expectRustMetadata().additionalAttributes
value and add extra values there. The generated code adds the correct attributes for thestruct
, however, it also adds these attributes to theBuilder
.The
Builder
is restricted to deriving fromDebug
,PartialEq
,Clone
andDefault
(see code).I believe this change was added by mistake in #2222.
Description
To solve the issue, I simply remove the offending line.
Testing
I don't expect any existing code to break, given that this is a bug. It only manifests when someone is customizing the generated code.
Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesCHANGELOG.next.toml
if I made changes to the AWS SDK, generated SDK code, or SDK runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.