From 85c3fafdd8a005ffc056994ddf1c9a91b1bec1ee Mon Sep 17 00:00:00 2001 From: George Fu Date: Fri, 13 Oct 2023 15:10:18 -0400 Subject: [PATCH] feat(enums): generate enum Record keys when target is enum (#1037) --- .changeset/rich-turtles-relate.md | 2 ++ .../smithy/typescript/codegen/StructuredMemberWriter.java | 5 ++++- .../amazon/smithy/typescript/codegen/SymbolVisitor.java | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/rich-turtles-relate.md diff --git a/.changeset/rich-turtles-relate.md b/.changeset/rich-turtles-relate.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/rich-turtles-relate.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java index 58f494fce9d..bdc727be080 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java @@ -611,7 +611,10 @@ private void writeConstraintValidatorType(TypeScriptWriter writer, Shape shape) Shape collectionMemberTargetShape = model.expectShape(collectionMemberShape.getTarget()); writer.writeInline("Iterable<$T>", getSymbolForValidatedType(collectionMemberTargetShape)); } else if (shape.isMapShape()) { - writer.writeInline("Record", getSymbolForValidatedType(((MapShape) shape).getValue())); + writer.writeInline("Record<$T, $T>", + getSymbolForValidatedType(((MapShape) shape).getKey()), + getSymbolForValidatedType(((MapShape) shape).getValue()) + ); } else if (shape instanceof SimpleShape) { writer.writeInline("$T", getSymbolForValidatedType(shape)); } else { 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 d8f940c8943..2e43aeb027c 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 @@ -193,9 +193,10 @@ public Symbol setShape(SetShape shape) { */ @Override public Symbol mapShape(MapShape shape) { - Symbol reference = toSymbol(shape.getValue()); - return createSymbolBuilder(shape, format("Record", reference.getName()), null) - .addReference(reference) + Symbol key = toSymbol(shape.getKey()); + Symbol value = toSymbol(shape.getValue()); + return createSymbolBuilder(shape, format("Record<%s, %s>", key.getName(), value.getName()), null) + .addReference(value) .build(); }