1616package software .amazon .smithy .aws .typescript .codegen ;
1717
1818import java .util .Map ;
19+ import java .util .Objects ;
1920import java .util .TreeMap ;
2021import java .util .function .BiFunction ;
2122import software .amazon .smithy .aws .typescript .codegen .validation .UnaryFunctionCall ;
23+ import software .amazon .smithy .codegen .core .ReservedWords ;
24+ import software .amazon .smithy .codegen .core .ReservedWordsBuilder ;
2225import software .amazon .smithy .codegen .core .Symbol ;
2326import software .amazon .smithy .codegen .core .SymbolProvider ;
2427import software .amazon .smithy .model .Model ;
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,8 @@ 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, {" , "});" ,
220+ reservedWords .escape (shape .getId ().getName (serviceShape )), () -> {
212221 // Use a TreeMap to sort the members.
213222 Map <String , MemberShape > members = new TreeMap <>(shape .getAllMembers ());
214223 members .forEach ((memberName , memberShape ) -> {
0 commit comments