@@ -1306,6 +1306,58 @@ test "custom serialization for map objects" {
13061306 , buffer .items );
13071307}
13081308
1309+ test "proper serialization for kms" {
1310+ // Github issue #8
1311+ // https://github.com/elerch/aws-sdk-for-zig/issues/8
1312+ const allocator = std .testing .allocator ;
1313+ var buffer = std .ArrayList (u8 ).init (allocator );
1314+ defer buffer .deinit ();
1315+ const req = services.kms.encrypt.Request {
1316+ .encryption_algorithm = "SYMMETRIC_DEFAULT" ,
1317+ // Since encryption_context is not null, we expect "{}" to be the value
1318+ // here, not "[]", because this is our special AWS map pattern
1319+ .encryption_context = &.{},
1320+ .key_id = "42" ,
1321+ .plaintext = "foo" ,
1322+ .dry_run = false ,
1323+ .grant_tokens = &[_ ][]const u8 {},
1324+ };
1325+ try json .stringify (req , .{ .whitespace = .{} }, buffer .writer ());
1326+ try std .testing .expectEqualStrings (
1327+ \\{
1328+ \\ "KeyId": "42",
1329+ \\ "Plaintext": "foo",
1330+ \\ "EncryptionContext": {},
1331+ \\ "GrantTokens": [],
1332+ \\ "EncryptionAlgorithm": "SYMMETRIC_DEFAULT",
1333+ \\ "DryRun": false
1334+ \\}
1335+ , buffer .items );
1336+
1337+ var buffer_null = std .ArrayList (u8 ).init (allocator );
1338+ defer buffer_null .deinit ();
1339+ const req_null = services.kms.encrypt.Request {
1340+ .encryption_algorithm = "SYMMETRIC_DEFAULT" ,
1341+ // Since encryption_context here *IS* null, we expect simply "null" to be the value
1342+ .encryption_context = null ,
1343+ .key_id = "42" ,
1344+ .plaintext = "foo" ,
1345+ .dry_run = false ,
1346+ .grant_tokens = &[_ ][]const u8 {},
1347+ };
1348+ try json .stringify (req_null , .{ .whitespace = .{} }, buffer_null .writer ());
1349+ try std .testing .expectEqualStrings (
1350+ \\{
1351+ \\ "KeyId": "42",
1352+ \\ "Plaintext": "foo",
1353+ \\ "EncryptionContext": null,
1354+ \\ "GrantTokens": [],
1355+ \\ "EncryptionAlgorithm": "SYMMETRIC_DEFAULT",
1356+ \\ "DryRun": false
1357+ \\}
1358+ , buffer_null .items );
1359+ }
1360+
13091361test "REST Json v1 builds proper queries" {
13101362 const allocator = std .testing .allocator ;
13111363 const svs = Services (.{.lambda }){};
0 commit comments