http trait necessary for rest json support
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Emil Lerch 2021-08-13 11:03:11 -07:00
parent 17b0ae9551
commit 6f53ed6dcf
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 28 additions and 0 deletions

View File

@ -166,6 +166,16 @@ fn generateOperation(allocator: *std.mem.Allocator, operation: smithy.ShapeInfo,
const operation_name = avoidReserved(snake_case_name); const operation_name = avoidReserved(snake_case_name);
try writer.print("pub const {s}: struct ", .{operation_name}); try writer.print("pub const {s}: struct ", .{operation_name});
_ = try writer.write("{\n"); _ = try writer.write("{\n");
for (operation.shape.operation.traits) |trait| {
if (trait == .http) {
_ = try writer.write(" pub const http_config = .{\n");
try writer.print(" .method = \"{s}\",\n", .{trait.http.method});
try writer.print(" .uri = \"{s}\",\n", .{trait.http.uri});
try writer.print(" .success_code = {d},\n", .{trait.http.code});
_ = try writer.write(" };\n\n");
}
}
try writer.print(" action_name: []const u8 = \"{s}\",\n", .{operation.name}); try writer.print(" action_name: []const u8 = \"{s}\",\n", .{operation.name});
_ = try writer.write(" Request: type = "); _ = try writer.write(" Request: type = ");
if (operation.shape.operation.input) |member| { if (operation.shape.operation.input) |member| {

View File

@ -91,6 +91,7 @@ pub const TraitType = enum {
aws_auth_sigv4, aws_auth_sigv4,
aws_protocol, aws_protocol,
ec2_query_name, ec2_query_name,
http,
json_name, json_name,
required, required,
documentation, documentation,
@ -114,6 +115,11 @@ pub const Trait = union(TraitType) {
aws_protocol: AwsProtocol, aws_protocol: AwsProtocol,
ec2_query_name: []const u8, ec2_query_name: []const u8,
json_name: []const u8, json_name: []const u8,
http: struct {
method: []const u8,
uri: []const u8,
code: i64 = 200,
},
required: struct {}, required: struct {},
documentation: []const u8, documentation: []const u8,
pattern: []const u8, pattern: []const u8,
@ -539,6 +545,18 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
if (std.mem.eql(u8, trait_type, "aws.protocols#ec2QueryName")) if (std.mem.eql(u8, trait_type, "aws.protocols#ec2QueryName"))
return Trait{ .ec2_query_name = value.String }; return Trait{ .ec2_query_name = value.String };
if (std.mem.eql(u8, trait_type, "smithy.api#http")) {
var code: i64 = 200;
if (value.Object.get("code")) |v| {
if (v == .Integer)
code = v.Integer;
}
return Trait{ .http = .{
.method = value.Object.get("method").?.String,
.uri = value.Object.get("uri").?.String,
.code = code,
} };
}
if (std.mem.eql(u8, trait_type, "smithy.api#jsonName")) if (std.mem.eql(u8, trait_type, "smithy.api#jsonName"))
return Trait{ .json_name = value.String }; return Trait{ .json_name = value.String };