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

Add support for IDL 2.0 nullability semantics #1725

Merged
merged 3 commits into from
Sep 17, 2022

Conversation

sugmanue
Copy link
Contributor

@sugmanue sugmanue commented Sep 9, 2022

Motivation and Context

Changed the code to properly handle the nullability semantics for both, 1.0 and 2.0 models.

Description

  • Removed the use of the deprecated method isNullable and instead used the isMemberNullable with CheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT which will make the semantics equivalent to looking for a Box trait which will work for both 1.0 and 2.0 models.
  • Changed a unit test which now we need to specify is a 1.0 model in order for the loader to properly work
  • Changed the EC2 customization to add ClientOptionalTrait instead of adding a Box trait using a transformer, this will make will have the same semantic implications that the previous code.
  • Finally added a bunch of references to mavenLocal which was needed to test the changes.

Testing

  • Generated all the models using 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.

@sugmanue sugmanue requested review from a team as code owners September 9, 2022 17:18
@@ -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)) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Comment on lines 97 to 99
fun createModelFromLines(vararg lines: String): Model {
var source = lines.joinToString(separator = "\n")
return Model.assembler()
.addUnparsedModel("test.smithy", source)
.assemble()
.unwrap()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

Comment on lines 129 to 135
val model = createModelFromLines(
"\$version: \"1.0\"",
"namespace foo.bar",
"structure MyStruct {",
" quux: $primitiveType",
"}"
)
Copy link
Collaborator

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())
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

@jdisanti
Copy link
Collaborator

jdisanti commented Sep 9, 2022

Forgot to mention, the CHANGELOG.next.toml should have a smithy-rs entry added for the Smithy version upgrade, and for the nullability change.

@sugmanue sugmanue force-pushed the model-evolution-updates branch 2 times, most recently from 531cc4d to b853aca Compare September 12, 2022 18:25
Copy link
Contributor

@david-perez david-perez left a 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 =
Copy link
Contributor

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() }

@jdisanti
Copy link
Collaborator

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?

Smithy 1.25 isn't released yet. @sugmanue is testing with a local Maven repository.

@sugmanue sugmanue force-pushed the model-evolution-updates branch 2 times, most recently from f6fc216 to 4839471 Compare September 15, 2022 21:48
@github-actions
Copy link

A new generated diff is ready to view.

  • No codegen difference in the AWS SDK
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python

A new doc preview is ready to view.

@jdisanti jdisanti merged commit ffafbec into smithy-lang:main Sep 17, 2022
github-merge-queue bot pushed a commit that referenced this pull request Sep 19, 2023
…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._
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants