1616package software .amazon .smithy .aws .typescript .codegen ;
1717
1818import java .util .Map ;
19+ import java .util .Objects ;
1920import java .util .TreeMap ;
21+ import software .amazon .smithy .codegen .core .ReservedWords ;
22+ import software .amazon .smithy .codegen .core .ReservedWordsBuilder ;
2023import java .util .function .BiFunction ;
2124import software .amazon .smithy .aws .typescript .codegen .validation .UnaryFunctionCall ;
2225import software .amazon .smithy .codegen .core .Symbol ;
3538import software .amazon .smithy .model .traits .SparseTrait ;
3639import software .amazon .smithy .model .traits .TimestampFormatTrait ;
3740import software .amazon .smithy .model .traits .TimestampFormatTrait .Format ;
41+ import software .amazon .smithy .typescript .codegen .TypeScriptClientCodegenPlugin ;
3842import software .amazon .smithy .typescript .codegen .TypeScriptDependency ;
3943import software .amazon .smithy .typescript .codegen .TypeScriptWriter ;
4044import software .amazon .smithy .typescript .codegen .integration .DocumentMemberSerVisitor ;
@@ -57,6 +61,10 @@ final class JsonShapeSerVisitor extends DocumentShapeSerVisitor {
5761
5862 private final BiFunction <MemberShape , String , String > memberNameStrategy ;
5963
64+ private final ReservedWords reservedWords = new ReservedWordsBuilder ()
65+ .loadWords (Objects .requireNonNull (TypeScriptClientCodegenPlugin .class .getResource ("reserved-words.txt" )))
66+ .build ();
67+
6068 JsonShapeSerVisitor (GenerationContext context , boolean serdeElisionEnabled ) {
6169 this (context ,
6270 // Use the jsonName trait value if present, otherwise use the member name.
@@ -208,7 +216,7 @@ public void serializeUnion(GenerationContext context, UnionShape shape) {
208216 ServiceShape serviceShape = context .getService ();
209217
210218 // Visit over the union type, then get the right serialization for the member.
211- writer .openBlock ("return $L.visit(input, {" , "});" , shape .getId ().getName (serviceShape ), () -> {
219+ writer .openBlock ("return $L.visit(input, {" , "});" , reservedWords . escape ( shape .getId ().getName (serviceShape ) ), () -> {
212220 // Use a TreeMap to sort the members.
213221 Map <String , MemberShape > members = new TreeMap <>(shape .getAllMembers ());
214222 members .forEach ((memberName , memberShape ) -> {
0 commit comments