Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
package software.amazon.smithy.aws.typescript.codegen;

import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
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;
Expand All @@ -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;
Expand All @@ -57,6 +61,10 @@ final class JsonShapeSerVisitor extends DocumentShapeSerVisitor {

private final BiFunction<MemberShape, String, String> 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.
Expand Down Expand Up @@ -208,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, {", "});", shape.getId().getName(serviceShape), () -> {
writer.openBlock("return $L.visit(input, {", "});",
reservedWords.escape(shape.getId().getName(serviceShape)), () -> {
// Use a TreeMap to sort the members.
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
members.forEach((memberName, memberShape) -> {
Expand Down
Loading