fix(json): need to write null when structure is null
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 7m53s
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 7m53s
This commit is contained in:
parent
6e775e20bb
commit
3979d32a1d
2 changed files with 48 additions and 23 deletions
|
@ -213,6 +213,8 @@ fn writeStructureJson(params: WriteMemberJsonParams, writer: std.io.AnyWriter) !
|
|||
try writer.writeAll("try jw.endObject();\n");
|
||||
|
||||
if (is_optional) {
|
||||
try writer.writeAll("} else {\n");
|
||||
try writer.writeAll("try jw.write(null);\n");
|
||||
try writer.writeAll("}\n");
|
||||
}
|
||||
}
|
||||
|
|
23
src/aws.zig
23
src/aws.zig
|
@ -2703,6 +2703,8 @@ test "jsonStringify" {
|
|||
}
|
||||
|
||||
test "jsonStringify nullable object" {
|
||||
// structure is not null
|
||||
{
|
||||
const request = services.lambda.CreateAliasRequest{
|
||||
.function_name = "foo",
|
||||
.function_version = "bar",
|
||||
|
@ -2730,3 +2732,24 @@ test "jsonStringify nullable object" {
|
|||
try testing.expectEqualStrings("baz", json_parsed.value.Name);
|
||||
try testing.expectEqual(null, json_parsed.value.RoutingConfig.AdditionalVersionWeights);
|
||||
}
|
||||
|
||||
// structure is null
|
||||
{
|
||||
const request = services.kms.DecryptRequest{
|
||||
.key_id = "foo",
|
||||
.ciphertext_blob = "bar",
|
||||
};
|
||||
|
||||
const request_json = try std.json.stringifyAlloc(std.testing.allocator, request, .{});
|
||||
defer std.testing.allocator.free(request_json);
|
||||
|
||||
const json_parsed = try std.json.parseFromSlice(struct {
|
||||
KeyId: []const u8,
|
||||
CiphertextBlob: []const u8,
|
||||
}, testing.allocator, request_json, .{ .ignore_unknown_fields = true });
|
||||
defer json_parsed.deinit();
|
||||
|
||||
try testing.expectEqualStrings("foo", json_parsed.value.KeyId);
|
||||
try testing.expectEqualStrings("bar", json_parsed.value.CiphertextBlob);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue