diff --git a/.changeset/selfish-planes-give.md b/.changeset/selfish-planes-give.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/selfish-planes-give.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/EnumGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/EnumGenerator.java index d6fdcb34a74..59a5eba7070 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/EnumGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/EnumGenerator.java @@ -49,7 +49,7 @@ * import { TypedYesNo } from "./TypedYesNo"; * * interface MyStructure { - * "yesNo": TypedYesNo | string; + * "yesNo": TypedYesNo; * } * } */ diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IntEnumGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IntEnumGenerator.java index 19b7bed2e85..1a1a5262c89 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IntEnumGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IntEnumGenerator.java @@ -51,7 +51,7 @@ * import { FaceCard } from "./FaceCard"; * * interface MyStructure { - * "facecard": FaceCard | number; + * "facecard": FaceCard; * } * } */ diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java index 6efd9c0f2c8..d8f940c8943 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java @@ -353,11 +353,7 @@ public Symbol memberShape(MemberShape shape) { .orElseThrow(() -> new CodegenException("Shape not found: " + shape.getTarget())); Symbol targetSymbol = toSymbol(targetShape); - if (targetShape.isIntEnumShape()) { - return createMemberSymbolWithIntEnumTarget(targetSymbol); - } - - if (targetSymbol.getProperties().containsKey(EnumTrait.class.getName())) { + if (targetSymbol.getProperties().containsKey(EnumTrait.class.getName()) || targetShape.isIntEnumShape()) { return createMemberSymbolWithEnumTarget(targetSymbol); } @@ -371,24 +367,15 @@ public Symbol memberShape(MemberShape shape) { return targetSymbol; } - // Enums are considered "open", meaning it is a backward compatible change to add new - // members. Adding the `string` variant allows for previously generated clients to be - // able to handle unknown enum values that may be added in the future. + // Enums were considered "open" with the union `| string` or `| number`, meaning it was a backwards + // compatible change to add new members. This behavior was later removed to improve the helpfulness + // of closed enumerated union types. + // For overrides, users should use available type system overrides such as "as any" or + // pragma comments. private Symbol createMemberSymbolWithEnumTarget(Symbol targetSymbol) { return targetSymbol.toBuilder() .namespace(null, "/") - .name(targetSymbol.getName() + " | string") - .addReference(targetSymbol) - .build(); - } - - // IntEnums are considered "open", meaning it is a backward compatible change to add new - // members. Adding the `number` variant allows for previously generated clients to be - // able to handle unknown int enum values that may be added in the future. - private Symbol createMemberSymbolWithIntEnumTarget(Symbol targetSymbol) { - return targetSymbol.toBuilder() - .namespace(null, "/") - .name(targetSymbol.getName() + " | number") + .name(targetSymbol.getName()) .addReference(targetSymbol) .build(); } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptUtils.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptUtils.java index ac5c76451b1..c3cf7b089dc 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptUtils.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptUtils.java @@ -66,7 +66,7 @@ private static boolean isValidPropertyName(String value) { /** * Creates a list of sorted, pipe separated enum variants as a union. * - *

For example, `"foo" | "baz" | string`. Note: special characters + *

For example, `"foo" | "baz"`. Note: special characters * and quotes are escaped as needed. * * @param values Values to create into a union. diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/SymbolProviderTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/SymbolProviderTest.java index f8555889ce8..e3b0ef404ed 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/SymbolProviderTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/SymbolProviderTest.java @@ -194,7 +194,7 @@ public void usesLazyJsonStringForJsonMediaType() { } @Test - public void addsUnknownStringEnumVariant() { + public void omitsUnknownStringEnumVariant() { EnumTrait trait = EnumTrait.builder() .addEnum(EnumDefinition.builder().value("FOO").name("FOO").build()) .addEnum(EnumDefinition.builder().value("BAR").name("BAR").build()) @@ -218,11 +218,11 @@ public void addsUnknownStringEnumVariant() { SymbolProvider provider = new SymbolVisitor(model, settings); Symbol memberSymbol = provider.toSymbol(member); - assertThat(memberSymbol.getName(), equalTo("EnumString | string")); + assertThat(memberSymbol.getName(), equalTo("EnumString")); } @Test - public void addsUnknownNumberIntEnumVariant() { + public void omitsUnknownNumberIntEnumVariant() { IntEnumShape shape = IntEnumShape.builder() .id("com.foo#Foo") .addMember("BAR", 2) @@ -246,7 +246,7 @@ public void addsUnknownNumberIntEnumVariant() { SymbolProvider provider = new SymbolVisitor(model, settings); Symbol memberSymbol = provider.toSymbol(member); - assertThat(memberSymbol.getName(), equalTo("Foo | number")); + assertThat(memberSymbol.getName(), equalTo("Foo")); } }