Compare commits
	
		
			3 commits
		
	
	
		
			a4c6ec6dfe
			...
			9eaaada446
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 9eaaada446 | |||
| d8925f37b9 | |||
| 342b15eebd | 
					 2 changed files with 45 additions and 5 deletions
				
			
		
							
								
								
									
										8
									
								
								.envrc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.envrc
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| # vi: ft=sh | ||||
| # shellcheck shell=bash | ||||
| 
 | ||||
| if ! has zvm_direnv_version || ! zvm_direnv_version 2.0.0; then | ||||
|   source_url "https://git.lerch.org/lobo/zvm-direnv/raw/tag/2.0.0/direnvrc" "sha256-8Umzxj32hFU6G0a7Wrq0KTNDQ8XEuje2A3s2ljh/hFY=" | ||||
| fi | ||||
| 
 | ||||
| use zig 0.14.0 | ||||
|  | @ -235,7 +235,7 @@ const Shape = union(ShapeType) { | |||
|         traits: []Trait, | ||||
|     }, | ||||
|     service: struct { | ||||
|         version: []const u8, | ||||
|         version: ?[]const u8, // A version is optional in Smithy. https://smithy.io/2.0/spec/service-types.html | ||||
|         operations: [][]const u8, | ||||
|         resources: [][]const u8, | ||||
|         traits: []Trait, | ||||
|  | @ -482,7 +482,7 @@ fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseErro | |||
|     if (std.mem.eql(u8, shape_type, "service")) | ||||
|         return Shape{ | ||||
|             .service = .{ | ||||
|                 .version = shape.object.get("version").?.string, | ||||
|                 .version = if (shape.object.get("version")) |v| v.string else null, | ||||
|                 .operations = if (shape.object.get("operations")) |ops| | ||||
|                     try parseTargetList(allocator, ops.array) | ||||
|                 else | ||||
|  | @ -812,6 +812,7 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra | |||
|         \\aws.cloudformation#cfnMutability | ||||
|         \\aws.cloudformation#cfnExcludeProperty | ||||
|         \\aws.cloudformation#cfnAdditionalIdentifier | ||||
|         \\aws.endpoints#standardPartitionalEndpoints | ||||
|         \\aws.iam#actionPermissionDescription | ||||
|         \\aws.iam#requiredActions | ||||
|         \\aws.iam#conditionKeys | ||||
|  | @ -893,6 +894,37 @@ fn read_file_to_string(allocator: std.mem.Allocator, file_name: []const u8, max_ | |||
| const test_data: []const u8 = @embedFile("test.json"); | ||||
| const intrinsic_type_count: usize = 15; // 15 intrinsic types are added to every model (see shapes() function) | ||||
| 
 | ||||
| test "parse service without version" { | ||||
|     const test_string = | ||||
|         \\ { | ||||
|         \\     "smithy": "1.0", | ||||
|         \\     "shapes": { | ||||
|         \\         "com.amazonaws.sts#AWSSecurityTokenServiceV20110615": { | ||||
|         \\             "type": "service", | ||||
|         \\             "operations": [ | ||||
|         \\                 { | ||||
|         \\                     "target": "op" | ||||
|         \\                 } | ||||
|         \\             ] | ||||
|         \\         } | ||||
|         \\     } | ||||
|         \\ } | ||||
|         \\ | ||||
|         \\ | ||||
|     ; | ||||
| 
 | ||||
|     const allocator = std.testing.allocator; | ||||
|     const model = try parse(allocator, test_string); | ||||
|     defer model.deinit(); | ||||
|     try expect(std.mem.eql(u8, model.version, "1.0")); | ||||
| 
 | ||||
|     try std.testing.expectEqual(intrinsic_type_count + 1, model.shapes.len); | ||||
|     try std.testing.expectEqualStrings("com.amazonaws.sts#AWSSecurityTokenServiceV20110615", model.shapes[0].id); | ||||
|     try std.testing.expectEqualStrings("com.amazonaws.sts", model.shapes[0].namespace); | ||||
|     try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", model.shapes[0].name); | ||||
|     try std.testing.expect(model.shapes[0].member == null); | ||||
|     try std.testing.expect(model.shapes[0].shape.service.version == null); | ||||
| } | ||||
| test "parse string" { | ||||
|     const test_string = | ||||
|         \\ { | ||||
|  | @ -923,7 +955,7 @@ test "parse string" { | |||
|     try std.testing.expectEqualStrings("com.amazonaws.sts", model.shapes[0].namespace); | ||||
|     try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", model.shapes[0].name); | ||||
|     try std.testing.expect(model.shapes[0].member == null); | ||||
|     try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version); | ||||
|     try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version.?); | ||||
| } | ||||
| test "parse shape with member" { | ||||
|     const test_string = | ||||
|  | @ -953,7 +985,7 @@ test "parse shape with member" { | |||
|     try std.testing.expectEqualStrings("com.amazonaws.sts#AWSSecurityTokenServiceV20110615$member", model.shapes[0].id); | ||||
|     try std.testing.expectEqualStrings("com.amazonaws.sts", model.shapes[0].namespace); | ||||
|     try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", model.shapes[0].name); | ||||
|     try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version); | ||||
|     try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version.?); | ||||
|     try std.testing.expectEqualStrings("member", model.shapes[0].member.?); | ||||
| } | ||||
| test "parse file" { | ||||
|  | @ -978,7 +1010,7 @@ test "parse file" { | |||
|     try std.testing.expectEqualStrings("com.amazonaws.sts#AWSSecurityTokenServiceV20110615", svc.id); | ||||
|     try std.testing.expectEqualStrings("com.amazonaws.sts", svc.namespace); | ||||
|     try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", svc.name); | ||||
|     try std.testing.expectEqualStrings("2011-06-15", svc.shape.service.version); | ||||
|     try std.testing.expectEqualStrings("2011-06-15", svc.shape.service.version.?); | ||||
|     // Should be 6, but we don't handle title or xml namespace | ||||
|     try std.testing.expectEqual(@as(usize, 4), svc.shape.service.traits.len); | ||||
|     try std.testing.expectEqual(@as(usize, 8), svc.shape.service.operations.len); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue