Compare commits

...

2 Commits

Author SHA1 Message Date
17f115d9c6
fix tests broken in 0a5a08a 2024-03-30 08:59:14 -07:00
melhindi
0b2d6e6a1b
Fix compilation issues on zig master 2024-03-30 08:53:23 -07:00
2 changed files with 15 additions and 11 deletions

View File

@ -30,9 +30,9 @@ pub fn build(b: *std.Build) void {
b.installArtifact(lib);
const module = b.addModule("smithy", .{
.source_file = .{ .path = "src/smithy.zig" },
.root_source_file = .{ .path = "src/smithy.zig" },
});
lib.addModule("smithy", module);
lib.root_module.addImport("smithy", module);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.

View File

@ -7,14 +7,16 @@ pub const Smithy = struct {
metadata: ModelMetadata,
shapes: []ShapeInfo,
allocator: std.mem.Allocator,
json_source: std.json.Parsed(std.json.Value),
const Self = @This();
pub fn init(allocator: std.mem.Allocator, version: []const u8, metadata: ModelMetadata, shapeinfo: []ShapeInfo) Smithy {
pub fn init(allocator: std.mem.Allocator, version: []const u8, metadata: ModelMetadata, shapeinfo: []ShapeInfo, json_source: std.json.Parsed(std.json.Value)) Smithy {
return .{
.version = version,
.metadata = metadata,
.shapes = shapeinfo,
.allocator = allocator,
.json_source = json_source,
};
}
pub fn deinit(self: Self) void {
@ -76,6 +78,7 @@ pub const Smithy = struct {
}
}
self.allocator.free(self.shapes);
self.json_source.deinit();
}
};
pub const ShapeInfo = struct {
@ -99,13 +102,13 @@ pub const TraitType = enum {
aws_auth_sigv4,
aws_protocol,
ec2_query_name,
json_name,
xml_name,
http,
http_header,
http_label,
http_query,
http_payload,
json_name,
xml_name,
required,
documentation,
pattern,
@ -253,10 +256,10 @@ pub const AwsProtocol = enum {
};
pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy {
// construct a parser. We're not copying strings here, but that may
// be a poor decision
// construct a parser. We're not copying strings here
// Instead, we keep the original json string around
// This might be bad if we only need a small fraction of the original json source
var vt = try std.json.parseFromSlice(std.json.Value, allocator, json_model, .{});
defer vt.deinit();
return Smithy.init(
allocator,
vt.value.object.get("smithy").?.string,
@ -265,6 +268,7 @@ pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy {
.suppressions = &.{},
},
try shapes(allocator, vt.value.object.get("shapes").?.object),
vt,
);
}
@ -572,7 +576,7 @@ fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseErro
}
fn parseMembers(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]TypeMember {
var rc: []TypeMember = &.{};
const rc: []TypeMember = &.{};
if (shape == null)
return rc;
@ -606,7 +610,7 @@ fn parseTraitsOnly(allocator: std.mem.Allocator, shape: std.json.Value) SmithyPa
}
fn parseTraits(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]Trait {
var rc: []Trait = &.{};
const rc: []Trait = &.{};
if (shape == null)
return rc;
@ -864,7 +868,7 @@ fn read_file_to_string(allocator: std.mem.Allocator, file_name: []const u8, max_
return file.readToEndAlloc(allocator, max_bytes);
}
const test_data: []const u8 = @embedFile("test.json");
const intrinsic_type_count: usize = 5; // 5 intrinsic types are added to every model
const intrinsic_type_count: usize = 15; // 15 intrinsic types are added to every model (see shapes() function)
test "parse string" {
const test_string =