From 7666f3d9355109b41b0eb3ea702eceb52a62a626 Mon Sep 17 00:00:00 2001 From: smilkuri Date: Thu, 9 Oct 2025 21:18:05 +0000 Subject: [PATCH 1/2] fix(codegen): apply reserved word escaping to union shape in Json serializer --- .../aws/typescript/codegen/JsonShapeSerVisitor.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java index 77537d1a2226..b62dc43ec8c8 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java @@ -16,7 +16,10 @@ package software.amazon.smithy.aws.typescript.codegen; import java.util.Map; +import java.util.Objects; import java.util.TreeMap; +import software.amazon.smithy.codegen.core.ReservedWords; +import software.amazon.smithy.codegen.core.ReservedWordsBuilder; import java.util.function.BiFunction; import software.amazon.smithy.aws.typescript.codegen.validation.UnaryFunctionCall; import software.amazon.smithy.codegen.core.Symbol; @@ -35,6 +38,7 @@ import software.amazon.smithy.model.traits.SparseTrait; import software.amazon.smithy.model.traits.TimestampFormatTrait; import software.amazon.smithy.model.traits.TimestampFormatTrait.Format; +import software.amazon.smithy.typescript.codegen.TypeScriptClientCodegenPlugin; import software.amazon.smithy.typescript.codegen.TypeScriptDependency; import software.amazon.smithy.typescript.codegen.TypeScriptWriter; import software.amazon.smithy.typescript.codegen.integration.DocumentMemberSerVisitor; @@ -57,6 +61,10 @@ final class JsonShapeSerVisitor extends DocumentShapeSerVisitor { private final BiFunction memberNameStrategy; + private final ReservedWords reservedWords = new ReservedWordsBuilder() + .loadWords(Objects.requireNonNull(TypeScriptClientCodegenPlugin.class.getResource("reserved-words.txt"))) + .build(); + JsonShapeSerVisitor(GenerationContext context, boolean serdeElisionEnabled) { this(context, // Use the jsonName trait value if present, otherwise use the member name. @@ -208,7 +216,7 @@ public void serializeUnion(GenerationContext context, UnionShape shape) { ServiceShape serviceShape = context.getService(); // Visit over the union type, then get the right serialization for the member. - writer.openBlock("return $L.visit(input, {", "});", shape.getId().getName(serviceShape), () -> { + writer.openBlock("return $L.visit(input, {", "});", reservedWords.escape(shape.getId().getName(serviceShape)), () -> { // Use a TreeMap to sort the members. Map members = new TreeMap<>(shape.getAllMembers()); members.forEach((memberName, memberShape) -> { From ad2a84d9452d7058aba34c2d669a6c4d9c4c1db3 Mon Sep 17 00:00:00 2001 From: smilkuri Date: Thu, 9 Oct 2025 21:41:37 +0000 Subject: [PATCH 2/2] fix(codegen): fix checkstyle violations in JsonShapeSerVisitor --- .../smithy/aws/typescript/codegen/JsonShapeSerVisitor.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java index b62dc43ec8c8..04c3b195045d 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java @@ -18,10 +18,10 @@ import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import software.amazon.smithy.codegen.core.ReservedWords; -import software.amazon.smithy.codegen.core.ReservedWordsBuilder; import java.util.function.BiFunction; import software.amazon.smithy.aws.typescript.codegen.validation.UnaryFunctionCall; +import software.amazon.smithy.codegen.core.ReservedWords; +import software.amazon.smithy.codegen.core.ReservedWordsBuilder; import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.model.Model; @@ -216,7 +216,8 @@ public void serializeUnion(GenerationContext context, UnionShape shape) { ServiceShape serviceShape = context.getService(); // Visit over the union type, then get the right serialization for the member. - writer.openBlock("return $L.visit(input, {", "});", reservedWords.escape(shape.getId().getName(serviceShape)), () -> { + writer.openBlock("return $L.visit(input, {", "});", + reservedWords.escape(shape.getId().getName(serviceShape)), () -> { // Use a TreeMap to sort the members. Map members = new TreeMap<>(shape.getAllMembers()); members.forEach((memberName, memberShape) -> {