16
16
package software .amazon .smithy .aws .typescript .codegen ;
17
17
18
18
import java .util .Map ;
19
+ import java .util .Objects ;
19
20
import java .util .TreeMap ;
20
21
import java .util .function .BiFunction ;
21
22
import software .amazon .smithy .aws .typescript .codegen .validation .UnaryFunctionCall ;
23
+ import software .amazon .smithy .codegen .core .ReservedWords ;
24
+ import software .amazon .smithy .codegen .core .ReservedWordsBuilder ;
22
25
import software .amazon .smithy .codegen .core .Symbol ;
23
26
import software .amazon .smithy .codegen .core .SymbolProvider ;
24
27
import software .amazon .smithy .model .Model ;
35
38
import software .amazon .smithy .model .traits .SparseTrait ;
36
39
import software .amazon .smithy .model .traits .TimestampFormatTrait ;
37
40
import software .amazon .smithy .model .traits .TimestampFormatTrait .Format ;
41
+ import software .amazon .smithy .typescript .codegen .TypeScriptClientCodegenPlugin ;
38
42
import software .amazon .smithy .typescript .codegen .TypeScriptDependency ;
39
43
import software .amazon .smithy .typescript .codegen .TypeScriptWriter ;
40
44
import software .amazon .smithy .typescript .codegen .integration .DocumentMemberSerVisitor ;
@@ -57,6 +61,10 @@ final class JsonShapeSerVisitor extends DocumentShapeSerVisitor {
57
61
58
62
private final BiFunction <MemberShape , String , String > memberNameStrategy ;
59
63
64
+ private final ReservedWords reservedWords = new ReservedWordsBuilder ()
65
+ .loadWords (Objects .requireNonNull (TypeScriptClientCodegenPlugin .class .getResource ("reserved-words.txt" )))
66
+ .build ();
67
+
60
68
JsonShapeSerVisitor (GenerationContext context , boolean serdeElisionEnabled ) {
61
69
this (context ,
62
70
// Use the jsonName trait value if present, otherwise use the member name.
@@ -208,7 +216,8 @@ public void serializeUnion(GenerationContext context, UnionShape shape) {
208
216
ServiceShape serviceShape = context .getService ();
209
217
210
218
// 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 )), () -> {
212
221
// Use a TreeMap to sort the members.
213
222
Map <String , MemberShape > members = new TreeMap <>(shape .getAllMembers ());
214
223
members .forEach ((memberName , memberShape ) -> {
0 commit comments