-
Notifications
You must be signed in to change notification settings - Fork 193
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
add support for nullable struct members when generating AWS SDKs #2916
Conversation
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
I think we should also note that certain fields are required in the generated docs |
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.
I'm so excited about this!
val errorMessageMember = errorShape.errorMessageMember() | ||
// If the message member is optional and wasn't set, we set a generic error message. | ||
if (errorMessageMember != null) { | ||
if (errorMessageMember.isOptional) { | ||
rust( | ||
""" | ||
if tmp.message.is_none() { | ||
tmp.message = _error_message; | ||
} | ||
""", | ||
) | ||
} |
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.
is this dropping it if it's not optional?
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.
AFAICT, this code is meant to set an error message. When the message is optional and wasn't provided, we set a generic message. This code isn't relevant when the message is required, as we can count on one being included in the response.
} else { | ||
rust("Ok(Some(builder.build()))") | ||
if (hasFallibleBuilder(shape, symbolProvider)) { |
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.
I think this can be if (hasFaillibleBuilder || !returnSymbolToParse.isUnconstrained)
?
Alternatively, can we push returnSymbolToParse
as an argument to hasFallibleBuilder
? That might help us make sure we caught all of these locations.
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.
I don't see how the logic can be simplified that way. I also don't see how passing returnSymbolToParse
as an argument to hasFallibleBuilder
simplifies things. returnSymbolToParse
is about whether we should parse a value for a shape into its associated unconstrained type. In the client this is always false
because it has no notion of constraint traits.
CHANGELOG.next.toml
Outdated
message = "Struct members modeled as required are no longer wrapped in `Option`s." | ||
references = ["smithy-rs#2916", "aws-sdk-rust#536"] |
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.
upgrade guidance would be helpful (it's simple but just listing it out is probably handy.)
An FAQ for why some members are still not optional would also be helpful
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.
done #2929
return; | ||
} | ||
} | ||
} | ||
|
||
pub(crate) struct Route53ResourceIdInterceptor<G, T> | ||
where | ||
G: for<'a> Fn(&'a mut T) -> &'a mut Option<String>, | ||
G: for<'a> Fn(&'a mut T) -> Option<&'a mut String>, |
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.
side note, might be nice to replace these existential types with a trait for clarity
...codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt
Outdated
Show resolved
Hide resolved
.attribute_definitions( | ||
AttributeDefinition::builder() | ||
.attribute_name("title") | ||
.attribute_type(ScalarAttributeType::S) | ||
.build(), | ||
.build() | ||
.unwrap(), |
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.
side note: I wonder if we want this API to accept impl TryInto<AttributeDefinitions>
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.
put another way, what if users could pass a builder directly?
...nt/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt
Outdated
Show resolved
Hide resolved
...gen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt
Outdated
Show resolved
Hide resolved
...are/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt
Outdated
Show resolved
Hide resolved
A new generated diff is ready to view.
A new doc preview is ready to view. |
update code in response to PR comments
A new generated diff is ready to view.
A new doc preview is ready to view. |
update serde tests to cover more cases
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.
I think the PR description needs to be updated. The option is nullabilityCheckMode
.
a20dc37
to
99de898
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
.build() | ||
.unwrap(), |
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.
Should we change build
to try_build
and add a build
that panics?
Switch to sdk branch = next Handle nullability change for smithy-lang/smithy-rs#2916 Handle nullability change for smithy-lang/smithy-rs#2995
Switch to sdk branch = next Handle nullability change for smithy-lang/smithy-rs#2916 Handle nullability change for smithy-lang/smithy-rs#2995
Switch to sdk branch = next Handle nullability change for smithy-lang/smithy-rs#2916 Handle nullability change for smithy-lang/smithy-rs#2995
Switch to sdk branch = next Handle nullability change for smithy-lang/smithy-rs#2916 Handle nullability change for smithy-lang/smithy-rs#2995
Switch to sdk branch = next Handle nullability change for smithy-lang/smithy-rs#2916 Handle nullability change for smithy-lang/smithy-rs#2995
Motivation and Context
smithy-rs#1767 aws-sdk-rust#536
Description
This PR adds support for nullability i.e. much less unwraps will be required when using the AWS SDK. For generic clients, this new behavior can be enabled in codegen by setting
nullabilityCheckMode: "Client"
in their codegen config:Testing
Ran existing tests
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.