support for enum, document, and...dear lord...unit
This commit is contained in:
parent
3a027b6cd9
commit
79d73cf09f
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.smithy = .{
|
.smithy = .{
|
||||||
.url = "https://git.lerch.org/lobo/smithy/archive/41b61745d25a65817209dd5dddbb5f9b66896a99.tar.gz",
|
.url = "https://git.lerch.org/lobo/smithy/archive/d6b6331defdfd33f36258caf26b0b82ce794cd28.tar.gz",
|
||||||
.hash = "122087deb0ae309b2258d59b40d82fe5921fdfc35b420bb59033244851f7f276fa34",
|
.hash = "1220695f5be11b7bd714f6181c60b0e590da5da7411de111ca51cacf1ea4a8169669",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,6 +295,7 @@ fn countReferences(shape: smithy.ShapeInfo, shapes: std.StringHashMap(smithy.Sha
|
||||||
.bigInteger,
|
.bigInteger,
|
||||||
.bigDecimal,
|
.bigDecimal,
|
||||||
.timestamp,
|
.timestamp,
|
||||||
|
.unit,
|
||||||
=> {},
|
=> {},
|
||||||
.document, .member, .resource => {}, // less sure about these?
|
.document, .member, .resource => {}, // less sure about these?
|
||||||
.list => |i| try countReferences(shapes.get(i.member_target).?, shapes, shape_references, stack),
|
.list => |i| try countReferences(shapes.get(i.member_target).?, shapes, shape_references, stack),
|
||||||
|
@ -325,6 +326,7 @@ fn countReferences(shape: smithy.ShapeInfo, shapes: std.StringHashMap(smithy.Sha
|
||||||
}
|
}
|
||||||
if (op.errors) |i| try countAllReferences(i, shapes, shape_references, stack);
|
if (op.errors) |i| try countAllReferences(i, shapes, shape_references, stack);
|
||||||
},
|
},
|
||||||
|
.@"enum" => |m| try countTypeMembersReferences(m.members, shapes, shape_references, stack),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,20 +531,26 @@ fn generateOperation(allocator: std.mem.Allocator, operation: smithy.ShapeInfo,
|
||||||
try writer.print("action_name: []const u8 = \"{s}\",\n", .{operation.name});
|
try writer.print("action_name: []const u8 = \"{s}\",\n", .{operation.name});
|
||||||
try outputIndent(state, writer);
|
try outputIndent(state, writer);
|
||||||
_ = try writer.write("Request: type = ");
|
_ = try writer.write("Request: type = ");
|
||||||
if (operation.shape.operation.input) |member| {
|
if (operation.shape.operation.input == null or
|
||||||
|
(try shapeInfoForId(operation.shape.operation.input.?, state)).shape == .unit)
|
||||||
|
{
|
||||||
|
_ = try writer.write("struct {\n");
|
||||||
|
try generateMetadataFunction(operation_name, state, writer);
|
||||||
|
} else if (operation.shape.operation.input) |member| {
|
||||||
if (try generateTypeFor(member, writer, state, false)) unreachable; // we expect only structs here
|
if (try generateTypeFor(member, writer, state, false)) unreachable; // we expect only structs here
|
||||||
_ = try writer.write("\n");
|
_ = try writer.write("\n");
|
||||||
try generateMetadataFunction(operation_name, state, writer);
|
try generateMetadataFunction(operation_name, state, writer);
|
||||||
} else {
|
|
||||||
_ = try writer.write("struct {\n");
|
|
||||||
try generateMetadataFunction(operation_name, state, writer);
|
|
||||||
}
|
}
|
||||||
_ = try writer.write(",\n");
|
_ = try writer.write(",\n");
|
||||||
try outputIndent(state, writer);
|
try outputIndent(state, writer);
|
||||||
_ = try writer.write("Response: type = ");
|
_ = try writer.write("Response: type = ");
|
||||||
if (operation.shape.operation.output) |member| {
|
if (operation.shape.operation.output == null or
|
||||||
|
(try shapeInfoForId(operation.shape.operation.output.?, state)).shape == .unit)
|
||||||
|
{
|
||||||
|
_ = try writer.write("struct {}"); // we want to maintain consistency with other ops
|
||||||
|
} else if (operation.shape.operation.output) |member| {
|
||||||
if (try generateTypeFor(member, writer, state, true)) unreachable; // we expect only structs here
|
if (try generateTypeFor(member, writer, state, true)) unreachable; // we expect only structs here
|
||||||
} else _ = try writer.write("struct {}"); // we want to maintain consistency with other ops
|
}
|
||||||
_ = try writer.write(",\n");
|
_ = try writer.write(",\n");
|
||||||
|
|
||||||
if (operation.shape.operation.errors) |errors| {
|
if (operation.shape.operation.errors) |errors| {
|
||||||
|
@ -691,7 +699,12 @@ fn generateTypeFor(shape_id: []const u8, writer: anytype, state: GenerationState
|
||||||
_ = try writer.write("}");
|
_ = try writer.write("}");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// Document is unstructured data, so bag of bytes it is
|
||||||
|
// https://smithy.io/2.0/spec/simple-types.html#document
|
||||||
|
.document => |s| try generateSimpleTypeFor(s, "[]const u8", writer),
|
||||||
.string => |s| try generateSimpleTypeFor(s, "[]const u8", writer),
|
.string => |s| try generateSimpleTypeFor(s, "[]const u8", writer),
|
||||||
|
.unit => |s| try generateSimpleTypeFor(s, "struct {}", writer), // Would be better as void, but doing so creates inconsistency we don't want clients to have to deal with
|
||||||
|
.@"enum" => |s| try generateSimpleTypeFor(s, "[]const u8", writer), // This should be closer to uniontype, but the generated code will look ugly, and Smithy 2.0 requires that enums are open (clients accept unspecified values). So string is the best analog
|
||||||
.integer => |s| try generateSimpleTypeFor(s, "i64", writer),
|
.integer => |s| try generateSimpleTypeFor(s, "i64", writer),
|
||||||
.list => {
|
.list => {
|
||||||
_ = try writer.write("[]");
|
_ = try writer.write("[]");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user