From 6f53ed6dcf1caef39f8550d8bb22cb3923c6b765 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 13 Aug 2021 11:03:11 -0700 Subject: [PATCH] http trait necessary for rest json support --- codegen/src/main.zig | 10 ++++++++++ smithy/src/smithy.zig | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/codegen/src/main.zig b/codegen/src/main.zig index 02d2d9a..0108a2d 100644 --- a/codegen/src/main.zig +++ b/codegen/src/main.zig @@ -166,6 +166,16 @@ fn generateOperation(allocator: *std.mem.Allocator, operation: smithy.ShapeInfo, const operation_name = avoidReserved(snake_case_name); try writer.print("pub const {s}: struct ", .{operation_name}); _ = 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.write(" Request: type = "); if (operation.shape.operation.input) |member| { diff --git a/smithy/src/smithy.zig b/smithy/src/smithy.zig index e30b69e..44411e3 100644 --- a/smithy/src/smithy.zig +++ b/smithy/src/smithy.zig @@ -91,6 +91,7 @@ pub const TraitType = enum { aws_auth_sigv4, aws_protocol, ec2_query_name, + http, json_name, required, documentation, @@ -114,6 +115,11 @@ pub const Trait = union(TraitType) { aws_protocol: AwsProtocol, ec2_query_name: []const u8, json_name: []const u8, + http: struct { + method: []const u8, + uri: []const u8, + code: i64 = 200, + }, required: struct {}, documentation: []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")) 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")) return Trait{ .json_name = value.String };