feat: add jsonStringify method to request objects
This commit is contained in:
parent
9b673b0ff3
commit
9bc13d932a
2 changed files with 30 additions and 0 deletions
|
@ -791,6 +791,14 @@ fn generateToJsonFunction(shape_id: []const u8, writer: std.io.AnyWriter, state:
|
||||||
}
|
}
|
||||||
|
|
||||||
try writer.writeAll("return .{ .object = object_map, };\n");
|
try writer.writeAll("return .{ .object = object_map, };\n");
|
||||||
|
try writer.writeAll("}\n\n");
|
||||||
|
|
||||||
|
// json stringify function
|
||||||
|
try writer.writeAll("pub fn jsonStringify(self: @This(), jw: anytype) !void {\n");
|
||||||
|
try writer.writeAll("var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n");
|
||||||
|
try writer.writeAll("defer arena.deinit();\n");
|
||||||
|
try writer.writeAll("const json_value = try self.toJson(arena.allocator());\n");
|
||||||
|
try writer.writeAll("try jw.write(json_value);\n");
|
||||||
try writer.writeAll("}\n");
|
try writer.writeAll("}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
src/aws.zig
22
src/aws.zig
|
@ -2645,3 +2645,25 @@ test "toJson: map" {
|
||||||
|
|
||||||
try testing.expectEqualStrings("{\"arn\":\"1234\",\"tags\":{\"foo\":\"bar\"}}", request_json);
|
try testing.expectEqualStrings("{\"arn\":\"1234\",\"tags\":{\"foo\":\"bar\"}}", request_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "jsonStringify" {
|
||||||
|
var tags = [_]services.media_convert.MapOfStringKeyValue{
|
||||||
|
.{
|
||||||
|
.key = "foo",
|
||||||
|
.value = "bar",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const request = services.media_convert.TagResourceRequest{
|
||||||
|
.arn = "1234",
|
||||||
|
.tags = &tags,
|
||||||
|
};
|
||||||
|
|
||||||
|
var arena = std.heap.ArenaAllocator.init(testing.allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
|
||||||
|
const request_json = try std.json.stringifyAlloc(std.testing.allocator, request, .{});
|
||||||
|
defer std.testing.allocator.free(request_json);
|
||||||
|
|
||||||
|
try testing.expectEqualStrings("{\"arn\":\"1234\",\"tags\":{\"foo\":\"bar\"}}", request_json);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue