-
Notifications
You must be signed in to change notification settings - Fork 192
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
Migrate to EnumShape #1932
Migrate to EnumShape #1932
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. |
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 looks good! Just a couple minor comments.
writer.rustBlock("impl <T> #T<T> for $enumName where T: #T<str>", RuntimeType.From, RuntimeType.AsRef) { | ||
rustBlock("fn from(s: T) -> Self") { | ||
rust("$enumName(s.as_ref().to_owned())") | ||
// TODO(https://github.com/awslabs/smithy-rs/issues/1700): handle IntEnum |
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.
Does it generate invalid code or throw an exception when encountering an integer enum? If not, we should make it do so for 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.
Changed so that it throws an exception both here and when the conversion fails
...n-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt
Show resolved
Hide resolved
Heh. We may need to upgrade the SDK models for this to pass. The current S3 model is IDLv1. Unfortunately, we can't upgrade the models until our endpoints 2.0 implementation lands though. |
It fails on EC2 and S3. For EC2 v2:
For S3 v2:
|
This PR is waiting for the migration to v2 models; there are missing features on the client before this migration can be done. When test models are in v2, this PR can be merged. (agreed with @jdisanti ) |
I can update the models once #1972 is merged. |
The models are updated. This should be unblocked now. |
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
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.
Looks good! Just a few comments.
Can you also rename renderBuildEnforcingRequiredAndEnumTraitsFn
from ServerBuilderGeneratorWithoutPublicConstrainedTypes.kt
, to, perhaps, renderBuildEnforcingRequiredTraitAndEnumValuesFn
?
EnumGenerator(model, symbolProvider, this, shape, enum).render() | ||
} | ||
if (shape.hasTrait<EnumTrait>()) { | ||
throw CodegenException("Unnamed @enum shapes are unsupported: $shape") |
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 error message accurate? My understanding from looking at this is that the model transformer might fail to convert an unnamed enum if e.g. one of its values cannot be safely synthesized into a valid name. So it's not like we don't support unnamed @enum
shapes entirely, just the ones that we failed to convert when synthesizeEnumNames
is set, right?. Aside: is that flag enabled by default?
If the above is correct, I'd fail here with a more informative error message, perhaps instructing the user to look in the log output above for the INFO
messages that the transformer from awslabs/smithy printed indicating the exact reason why the enum could not be converted.
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.
Correct, I've changed to a better log message, thanks!
...ient/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitorTest.kt
Outdated
Show resolved
Hide resolved
...ient/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitorTest.kt
Show resolved
Hide resolved
@@ -62,4 +63,42 @@ class CodegenVisitorTest { | |||
val baselineModel = visitor.baselineTransform(model) | |||
baselineModel.getShapesWithTrait(ShapeId.from("smithy.api#mixin")).isEmpty() shouldBe true | |||
} | |||
|
|||
@Test | |||
fun `baseline transform verify string enum converted to EnumShape`() { |
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.
nit: I'd add a negative test too that asserts we throw an exception when an unnamed enum could not be converted to an enum shape.
.../src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt
Outdated
Show resolved
Hide resolved
...e/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt
Outdated
Show resolved
Hide resolved
...e/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt
Show resolved
Hide resolved
codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt
Outdated
Show resolved
Hide resolved
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt
Outdated
Show resolved
Hide resolved
...er/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt
Show resolved
Hide resolved
Signed-off-by: Daniele Ahmed <[email protected]>
is StringShape -> if (shape.hasTrait<EnumTrait>()) { | ||
enumMeta(shape) | ||
} else null | ||
is EnumShape -> enumMeta(shape) |
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 can now make enumMeta
accept EnumShape
instead of StringShape
.
we've decided to begin closing old PRs that we don't plan to work on in the near future. Please let us know if you still think this PR is needed |
Deprecate EnumTrait and migrate to EnumShape.
Closes #1671
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.