move service model to its own file
This will need further refactoring to incorporate genned stuff
This commit is contained in:
parent
1a97775287
commit
b1397d896e
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
.cache
|
||||
zig-cache
|
||||
codegen/models/*.zig
|
||||
codegen/codegen
|
||||
|
|
|
@ -11,7 +11,7 @@ pub fn build(b: *Builder) void {
|
|||
// Standard release options allow the person running `zig build` to select
|
||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||
const mode = b.standardReleaseOptions();
|
||||
const exe = b.addExecutable("start-hand-test", "src/main.zig");
|
||||
const exe = b.addExecutable("demo", "src/main.zig");
|
||||
|
||||
// TODO: Generate src/models.zig
|
||||
|
||||
|
|
108
src/aws.zig
108
src/aws.zig
|
@ -2,117 +2,13 @@ const std = @import("std");
|
|||
|
||||
const awshttp = @import("awshttp.zig");
|
||||
const json = @import("json.zig");
|
||||
const servicemodel = @import("servicemodel.zig");
|
||||
|
||||
const log = std.log.scoped(.aws);
|
||||
|
||||
pub const Options = awshttp.Options;
|
||||
|
||||
// Code "generation" prototype
|
||||
// TODO: Make generic
|
||||
pub fn Services() type {
|
||||
const types = [_]type{
|
||||
Service("sts"),
|
||||
};
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.layout = .Auto,
|
||||
.fields = &[_]std.builtin.TypeInfo.StructField{
|
||||
.{
|
||||
.name = "sts",
|
||||
.field_type = types[0],
|
||||
.default_value = new(types[0]),
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
},
|
||||
.decls = &[_]std.builtin.TypeInfo.Declaration{},
|
||||
.is_tuple = false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
fn ServiceActionResponse(comptime service: []const u8, comptime action: []const u8) type {
|
||||
if (std.mem.eql(u8, service, "sts") and std.mem.eql(u8, action, "get_caller_identity")) {
|
||||
return struct {
|
||||
arn: []const u8,
|
||||
user_id: []const u8,
|
||||
account: []const u8,
|
||||
};
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
|
||||
fn ServiceAction(comptime service: []const u8, comptime action: []const u8) type {
|
||||
if (std.mem.eql(u8, service, "sts") and std.mem.eql(u8, action, "get_caller_identity")) {
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.layout = .Auto,
|
||||
.fields = &[_]std.builtin.TypeInfo.StructField{
|
||||
.{
|
||||
.name = "Request",
|
||||
.field_type = type,
|
||||
.default_value = struct {},
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
.{
|
||||
.name = "action_name",
|
||||
.field_type = @TypeOf("GetCallerIdentity"),
|
||||
.default_value = "GetCallerIdentity",
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
// TODO: maybe best is to separate requests from responses in whole other struct?
|
||||
.{
|
||||
.name = "Response",
|
||||
.field_type = type,
|
||||
.default_value = ServiceActionResponse("sts", "get_caller_identity"),
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
},
|
||||
.decls = &[_]std.builtin.TypeInfo.Declaration{},
|
||||
.is_tuple = false,
|
||||
},
|
||||
});
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
|
||||
pub const services = Services(){};
|
||||
|
||||
fn new(comptime T: type) T {
|
||||
return T{};
|
||||
}
|
||||
fn Service(comptime service: []const u8) type {
|
||||
if (std.mem.eql(u8, "sts", service)) {
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.layout = .Auto,
|
||||
.fields = &[_]std.builtin.TypeInfo.StructField{
|
||||
.{
|
||||
.name = "version",
|
||||
.field_type = @TypeOf("2011-06-15"),
|
||||
.default_value = "2011-06-15",
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
.{
|
||||
.name = "get_caller_identity",
|
||||
.field_type = ServiceAction("sts", "get_caller_identity"),
|
||||
.default_value = new(ServiceAction("sts", "get_caller_identity")),
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
},
|
||||
.decls = &[_]std.builtin.TypeInfo.Declaration{},
|
||||
.is_tuple = false,
|
||||
},
|
||||
});
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
// End code "generation" prototype
|
||||
pub const services = servicemodel.services;
|
||||
|
||||
pub const Aws = struct {
|
||||
allocator: *std.mem.Allocator,
|
||||
|
|
125
src/servicemodel.zig
Normal file
125
src/servicemodel.zig
Normal file
|
@ -0,0 +1,125 @@
|
|||
const std = @import("std");
|
||||
const models = @import("models.zig");
|
||||
const json = @import("json.zig");
|
||||
|
||||
const Model = []struct {
|
||||
smithy: []const u8,
|
||||
metadata: struct {
|
||||
suppressions: []struct {
|
||||
id: []const u8,
|
||||
namespace: []const u8,
|
||||
},
|
||||
},
|
||||
shapes: struct
|
||||
};
|
||||
const model = {
|
||||
var stream = json.TokenStream.init(models);
|
||||
const res = json.parse(Config, &stream, .{});
|
||||
// Assert no error can occur since we are
|
||||
// parsing this JSON at comptime!
|
||||
break :x res catch unreachable;
|
||||
};
|
||||
// TODO: Make generic
|
||||
fn Services() type {
|
||||
const types = [_]type{
|
||||
Service("sts"),
|
||||
};
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.layout = .Auto,
|
||||
.fields = &[_]std.builtin.TypeInfo.StructField{
|
||||
.{
|
||||
.name = "sts",
|
||||
.field_type = types[0],
|
||||
.default_value = new(types[0]),
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
},
|
||||
.decls = &[_]std.builtin.TypeInfo.Declaration{},
|
||||
.is_tuple = false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
fn ServiceActionResponse(comptime service: []const u8, comptime action: []const u8) type {
|
||||
if (std.mem.eql(u8, service, "sts") and std.mem.eql(u8, action, "get_caller_identity")) {
|
||||
return struct {
|
||||
arn: []const u8,
|
||||
user_id: []const u8,
|
||||
account: []const u8,
|
||||
};
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
|
||||
fn ServiceAction(comptime service: []const u8, comptime action: []const u8) type {
|
||||
if (std.mem.eql(u8, service, "sts") and std.mem.eql(u8, action, "get_caller_identity")) {
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.layout = .Auto,
|
||||
.fields = &[_]std.builtin.TypeInfo.StructField{
|
||||
.{
|
||||
.name = "Request",
|
||||
.field_type = type,
|
||||
.default_value = struct {},
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
.{
|
||||
.name = "action_name",
|
||||
.field_type = @TypeOf("GetCallerIdentity"),
|
||||
.default_value = "GetCallerIdentity",
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
.{
|
||||
.name = "Response",
|
||||
.field_type = type,
|
||||
.default_value = ServiceActionResponse("sts", "get_caller_identity"),
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
},
|
||||
.decls = &[_]std.builtin.TypeInfo.Declaration{},
|
||||
.is_tuple = false,
|
||||
},
|
||||
});
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
|
||||
pub const services = Services(){};
|
||||
|
||||
fn new(comptime T: type) T {
|
||||
return T{};
|
||||
}
|
||||
fn Service(comptime service: []const u8) type {
|
||||
if (std.mem.eql(u8, "sts", service)) {
|
||||
return @Type(.{
|
||||
.Struct = .{
|
||||
.layout = .Auto,
|
||||
.fields = &[_]std.builtin.TypeInfo.StructField{
|
||||
.{
|
||||
.name = "version",
|
||||
.field_type = @TypeOf("2011-06-15"),
|
||||
.default_value = "2011-06-15",
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
.{
|
||||
.name = "get_caller_identity",
|
||||
.field_type = ServiceAction("sts", "get_caller_identity"),
|
||||
.default_value = new(ServiceAction("sts", "get_caller_identity")),
|
||||
.is_comptime = false,
|
||||
.alignment = 0,
|
||||
},
|
||||
},
|
||||
.decls = &[_]std.builtin.TypeInfo.Declaration{},
|
||||
.is_tuple = false,
|
||||
},
|
||||
});
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
// End code "generation" prototype
|
Loading…
Reference in New Issue
Block a user