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");
|
try writer.writeAll("try jw.endObject();\n");
|
||||||
|
|
||||||
if (is_optional) {
|
if (is_optional) {
|
||||||
|
try writer.writeAll("} else {\n");
|
||||||
|
try writer.writeAll("try jw.write(null);\n");
|
||||||
try writer.writeAll("}\n");
|
try writer.writeAll("}\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
69
src/aws.zig
69
src/aws.zig
|
@ -2703,30 +2703,53 @@ test "jsonStringify" {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "jsonStringify nullable object" {
|
test "jsonStringify nullable object" {
|
||||||
const request = services.lambda.CreateAliasRequest{
|
// structure is not null
|
||||||
.function_name = "foo",
|
{
|
||||||
.function_version = "bar",
|
const request = services.lambda.CreateAliasRequest{
|
||||||
.name = "baz",
|
.function_name = "foo",
|
||||||
.routing_config = services.lambda.AliasRoutingConfiguration{
|
.function_version = "bar",
|
||||||
.additional_version_weights = null,
|
.name = "baz",
|
||||||
},
|
.routing_config = services.lambda.AliasRoutingConfiguration{
|
||||||
};
|
.additional_version_weights = null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const request_json = try std.json.stringifyAlloc(std.testing.allocator, request, .{});
|
const request_json = try std.json.stringifyAlloc(std.testing.allocator, request, .{});
|
||||||
defer std.testing.allocator.free(request_json);
|
defer std.testing.allocator.free(request_json);
|
||||||
|
|
||||||
const json_parsed = try std.json.parseFromSlice(struct {
|
const json_parsed = try std.json.parseFromSlice(struct {
|
||||||
FunctionName: []const u8,
|
FunctionName: []const u8,
|
||||||
FunctionVersion: []const u8,
|
FunctionVersion: []const u8,
|
||||||
Name: []const u8,
|
Name: []const u8,
|
||||||
RoutingConfig: struct {
|
RoutingConfig: struct {
|
||||||
AdditionalVersionWeights: ?struct {},
|
AdditionalVersionWeights: ?struct {},
|
||||||
},
|
},
|
||||||
}, testing.allocator, request_json, .{ .ignore_unknown_fields = true });
|
}, testing.allocator, request_json, .{ .ignore_unknown_fields = true });
|
||||||
defer json_parsed.deinit();
|
defer json_parsed.deinit();
|
||||||
|
|
||||||
try testing.expectEqualStrings("foo", json_parsed.value.FunctionName);
|
try testing.expectEqualStrings("foo", json_parsed.value.FunctionName);
|
||||||
try testing.expectEqualStrings("bar", json_parsed.value.FunctionVersion);
|
try testing.expectEqualStrings("bar", json_parsed.value.FunctionVersion);
|
||||||
try testing.expectEqualStrings("baz", json_parsed.value.Name);
|
try testing.expectEqualStrings("baz", json_parsed.value.Name);
|
||||||
try testing.expectEqual(null, json_parsed.value.RoutingConfig.AdditionalVersionWeights);
|
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