Skip to content

Commit

Permalink
fix: invalid serialization of empty body (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell committed Feb 6, 2020
1 parent 2278f3e commit 8a4dd05
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void deserializeMap(GenerationContext context, MapShape shape) {

// Get the right serialization for each entry in the map. Undefined
// outputs won't have this deserializer invoked.
writer.write("let mapParams: any = {};");
writer.write("const mapParams: any = {};");
writer.openBlock("Object.keys(output).forEach(key => {", "});", () -> {
// Dispatch to the output value provider for any additional handling.
writer.write("mapParams[key] = $L;", target.accept(getMemberVisitor("output[key]")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void serializeMap(GenerationContext context, MapShape shape) {

// Get the right serialization for each entry in the map. Undefined
// inputs won't have this serializer invoked.
writer.write("let mapParams: any = {};");
writer.write("const mapParams: any = {};");
writer.openBlock("Object.keys(input).forEach(key => {", "});", () -> {
// Dispatch to the input value provider for any additional handling.
writer.write("mapParams[key] = $L;", target.accept(getMemberVisitor("input[key]")));
Expand All @@ -88,7 +88,7 @@ public void serializeMap(GenerationContext context, MapShape shape) {
public void serializeStructure(GenerationContext context, StructureShape shape) {
TypeScriptWriter writer = context.getWriter();

writer.write("let bodyParams: any = {};");
writer.write("const bodyParams: any = {};");
// Use a TreeMap to sort the members.
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
members.forEach((memberName, memberShape) -> {
Expand All @@ -109,7 +109,7 @@ public void serializeStructure(GenerationContext context, StructureShape shape)
target.accept(getMemberVisitor("input." + memberName)));
});
});
writer.write("return bodyParams;");
writer.write("return (Object.entries(bodyParams).length !== 0 ? bodyParams : undefined);");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void deserializeMap(GenerationContext context, MapShape shape) {

// Get the right serialization for each entry in the map. Undefined
// outputs won't have this deserializer invoked.
writer.write("let mapParams: any = {};");
writer.write("const mapParams: any = {};");
writer.openBlock("Object.keys(output).forEach(key => {", "});", () -> {
// Dispatch to the output value provider for any additional handling.
writer.write("mapParams[key] = $L;", target.accept(getMemberVisitor("output[key]")));
Expand Down

0 comments on commit 8a4dd05

Please sign in to comment.