-
Notifications
You must be signed in to change notification settings - Fork 189
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 IDL 2.0 nullability semantics #1725
Conversation
@@ -211,7 +211,7 @@ open class SymbolVisitor( | |||
private fun handleOptionality(symbol: Symbol, member: MemberShape): Symbol = | |||
if (config.handleRequired && member.isRequired) { | |||
symbol | |||
} else if (nullableIndex.isNullable(member)) { | |||
} else if (nullableIndex.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT)) { |
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.
The server code generator is also using this code, so this may need to pass in a different CheckMode
for its use-case?
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.
Yes, the server code generator will need to useNullableIndex.CheckMode.SERVER
for this check.
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.
Let's add the CheckMode
as a member of SymbolVisitorConfig
so that it can be set correctly for the server codegen.
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 have pushed and update for this.
fun createModelFromLines(vararg lines: String): Model { | ||
var source = lines.joinToString(separator = "\n") | ||
return Model.assembler() | ||
.addUnparsedModel("test.smithy", source) | ||
.assemble() | ||
.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.
We already have a String.asSmithyModel()
extension function: https://github.com/awslabs/smithy-rs/blob/d81bf3c47a4ce35a2b6c66611323057f7e30181e/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt#L91
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.
Sounds good, I will remove this and use asSmithyModel
.
val model = createModelFromLines( | ||
"\$version: \"1.0\"", | ||
"namespace foo.bar", | ||
"structure MyStruct {", | ||
" quux: $primitiveType", | ||
"}" | ||
) |
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.
Example of using asSmithyModel
:
import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel
// ...
val model = """
namespace foo.bar
structure MyStruct {
quux: $primitiveType
}
""".asSmithyModel()
val updates = arrayListOf<Shape>() | ||
for (struct in model.structureShapes) { | ||
for (member in struct.allMembers.values) { | ||
updates.add(member.toBuilder().addTrait(ClientOptionalTrait()).build()) |
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.
Can we rename this customization to reflect what it's doing now?
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.
Yes, I will do so.
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 PR actually changes the behavior I think? it used to box primitives only but now it boxes everything?
Forgot to mention, the |
531cc4d
to
b853aca
Compare
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 can't test this patch locally. I get the following when invoking Gradle. I've tried clearing caches to no avail. Do you know what's going on?
> Task :buildSrc:compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildSrc:compileKotlin'.
> Error while evaluating property 'filteredArgumentsMap' of task ':buildSrc:compileKotlin'
> Could not resolve all files for configuration ':buildSrc:compileClasspath'.
> Could not find software.amazon.smithy:smithy-codegen-core:1.25.0.
Searched in the following locations:
- file:/home/ANT.AMAZON.COM/davidpz/.m2/repository/software/amazon/smithy/smithy-codegen-core/1.25.0/smithy-codegen-core-1.25.0.pom
- https://repo.maven.apache.org/maven2/software/amazon/smithy/smithy-codegen-core/1.25.0/smithy-codegen-core-1.25.0.pom
- https://dl.google.com/dl/android/maven2/software/amazon/smithy/smithy-codegen-core/1.25.0/smithy-codegen-core-1.25.0.pom
Required by:
project :buildSrc
> Could not find software.amazon.smithy:smithy-utils:1.25.0.
Searched in the following locations:
- file:/home/ANT.AMAZON.COM/davidpz/.m2/repository/software/amazon/smithy/smithy-utils/1.25.0/smithy-utils-1.25.0.pom
- https://repo.maven.apache.org/maven2/software/amazon/smithy/smithy-utils/1.25.0/smithy-utils-1.25.0.pom
- https://dl.google.com/dl/android/maven2/software/amazon/smithy/smithy-utils/1.25.0/smithy-utils-1.25.0.pom
Required by:
project :buildSrc
> Could not find software.amazon.smithy:smithy-protocol-test-traits:1.25.0.
Searched in the following locations:
- file:/home/ANT.AMAZON.COM/davidpz/.m2/repository/software/amazon/smithy/smithy-protocol-test-traits/1.25.0/smithy-protocol-test-traits-1.25.0.pom
- https://repo.maven.apache.org/maven2/software/amazon/smithy/smithy-protocol-test-traits/1.25.0/smithy-protocol-test-traits-1.25.0.pom
- https://dl.google.com/dl/android/maven2/software/amazon/smithy/smithy-protocol-test-traits/1.25.0/smithy-protocol-test-traits-1.25.0.pom
Required by:
project :buildSrc
> Could not find software.amazon.smithy:smithy-aws-traits:1.25.0.
Searched in the following locations:
- file:/home/ANT.AMAZON.COM/davidpz/.m2/repository/software/amazon/smithy/smithy-aws-traits/1.25.0/smithy-aws-traits-1.25.0.pom
- https://repo.maven.apache.org/maven2/software/amazon/smithy/smithy-aws-traits/1.25.0/smithy-aws-traits-1.25.0.pom
- https://dl.google.com/dl/android/maven2/software/amazon/smithy/smithy-aws-traits/1.25.0/smithy-aws-traits-1.25.0.pom
Required by:
project :buildSrc
> Could not find software.amazon.smithy:smithy-aws-iam-traits:1.25.0.
Searched in the following locations:
- file:/home/ANT.AMAZON.COM/davidpz/.m2/repository/software/amazon/smithy/smithy-aws-iam-traits/1.25.0/smithy-aws-iam-traits-1.25.0.pom
- https://repo.maven.apache.org/maven2/software/amazon/smithy/smithy-aws-iam-traits/1.25.0/smithy-aws-iam-traits-1.25.0.pom
- https://dl.google.com/dl/android/maven2/software/amazon/smithy/smithy-aws-iam-traits/1.25.0/smithy-aws-iam-traits-1.25.0.pom
Required by:
project :buildSrc
> Could not find software.amazon.smithy:smithy-aws-cloudformation-traits:1.25.0.
Searched in the following locations:
- file:/home/ANT.AMAZON.COM/davidpz/.m2/repository/software/amazon/smithy/smithy-aws-cloudformation-traits/1.25.0/smithy-aws-cloudformation-traits-1.25.0.pom
- https://repo.maven.apache.org/maven2/software/amazon/smithy/smithy-aws-cloudformation-traits/1.25.0/smithy-aws-cloudformation-traits-1.25.0.pom
- https://dl.google.com/dl/android/maven2/software/amazon/smithy/smithy-aws-cloudformation-traits/1.25.0/smithy-aws-cloudformation-traits-1.25.0.pom
Required by:
project :buildSrc
@@ -211,7 +212,7 @@ open class SymbolVisitor( | |||
private fun handleOptionality(symbol: Symbol, member: MemberShape): Symbol = |
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.
So now that we have NullableIndex.CheckMode.SERVER
, can't we simply implement this as below?
private fun handleOptionality(symbol: Symbol, member: MemberShape) =
symbol.letIf(nullableIndex.isMemberNullable(member, config.nullabilityCheckMode)) { symbol.makeOptional() }
Smithy 1.25 isn't released yet. @sugmanue is testing with a local Maven repository. |
f6fc216
to
4839471
Compare
4839471
to
fd73873
Compare
a75c205
to
e417661
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
…ges (#2988) ## Motivation and Context #1725 exposed the need for easily configuring builder behavior between client & server ## Description - extract builderGenerator interface and attach it to `codegenContext` to avoid loads of threading it up and down ## Testing - codegen unit tests - [x] codegen diff audit ## 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 - [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK 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._
Motivation and Context
Changed the code to properly handle the nullability semantics for both, 1.0 and 2.0 models.
Description
isNullable
and instead used theisMemberNullable
withCheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT
which will make the semantics equivalent to looking for aBox
trait which will work for both 1.0 and 2.0 models.ClientOptionalTrait
instead of adding aBox
trait using a transformer, this will make will have the same semantic implications that the previous code.mavenLocal
which was needed to test the changes.Testing
aws-sdk-rust
and validated that there were no changes in the generated code.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.