Compare commits
No commits in common. "d6b6331defdfd33f36258caf26b0b82ce794cd28" and "41b61745d25a65817209dd5dddbb5f9b66896a99" have entirely different histories.
d6b6331def
...
41b61745d2
219
src/smithy.zig
219
src/smithy.zig
|
@ -65,14 +65,6 @@ pub const Smithy = struct {
|
|||
self.allocator.free(v.value);
|
||||
self.allocator.free(v.traits);
|
||||
},
|
||||
.@"enum" => |v| {
|
||||
for (v.members) |m| self.allocator.free(m.traits);
|
||||
self.allocator.free(v.members);
|
||||
self.allocator.free(v.traits);
|
||||
},
|
||||
.unit => |v| {
|
||||
self.allocator.free(v.traits);
|
||||
},
|
||||
}
|
||||
}
|
||||
self.allocator.free(self.shapes);
|
||||
|
@ -106,23 +98,20 @@ pub const TraitType = enum {
|
|||
http_payload,
|
||||
json_name,
|
||||
xml_name,
|
||||
required, // required on the server
|
||||
client_optional, // optional as far as the client is concerned
|
||||
required,
|
||||
documentation,
|
||||
pattern,
|
||||
range,
|
||||
length,
|
||||
box,
|
||||
sparse,
|
||||
enum_value,
|
||||
aws_query_error,
|
||||
};
|
||||
pub const Trait = union(TraitType) {
|
||||
aws_api_service: struct {
|
||||
sdk_id: []const u8,
|
||||
arn_namespace: ?[]const u8,
|
||||
cloudformation_name: ?[]const u8,
|
||||
cloudtrail_event_source: ?[]const u8,
|
||||
arn_namespace: []const u8,
|
||||
cloudformation_name: []const u8,
|
||||
cloudtrail_event_source: []const u8,
|
||||
endpoint_prefix: []const u8,
|
||||
},
|
||||
aws_auth_sigv4: struct {
|
||||
|
@ -142,7 +131,6 @@ pub const Trait = union(TraitType) {
|
|||
http_query: []const u8,
|
||||
http_payload: struct {},
|
||||
required: struct {},
|
||||
client_optional: void,
|
||||
documentation: []const u8,
|
||||
pattern: []const u8,
|
||||
range: struct { // most data is actually integers, but as some are floats, we'll use that here
|
||||
|
@ -155,11 +143,6 @@ pub const Trait = union(TraitType) {
|
|||
},
|
||||
box: struct {},
|
||||
sparse: struct {},
|
||||
enum_value: []const u8,
|
||||
aws_query_error: struct {
|
||||
http_response_code: i64,
|
||||
code: []const u8,
|
||||
},
|
||||
};
|
||||
const ShapeType = enum {
|
||||
blob,
|
||||
|
@ -184,8 +167,6 @@ const ShapeType = enum {
|
|||
service,
|
||||
operation,
|
||||
resource,
|
||||
@"enum",
|
||||
unit,
|
||||
};
|
||||
const TraitsOnly = struct {
|
||||
traits: []Trait,
|
||||
|
@ -244,11 +225,6 @@ const Shape = union(ShapeType) {
|
|||
traits: []Trait,
|
||||
},
|
||||
resource: TraitsOnly,
|
||||
@"enum": struct {
|
||||
members: []TypeMember,
|
||||
traits: []Trait,
|
||||
},
|
||||
unit: TraitsOnly,
|
||||
};
|
||||
|
||||
// https://awslabs.github.io/smithy/1.0/spec/aws/index.html
|
||||
|
@ -290,10 +266,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
|||
.namespace = id_info.namespace,
|
||||
.name = id_info.name,
|
||||
.member = id_info.member,
|
||||
.shape = getShape(allocator, kv.value_ptr.*) catch |e| {
|
||||
std.log.err("Caught error parsing shape with name {s}: {}", .{ id_info.name, e });
|
||||
return e;
|
||||
},
|
||||
.shape = try getShape(allocator, kv.value_ptr.*),
|
||||
});
|
||||
}
|
||||
// This seems to be a synonym for the simple type "string"
|
||||
|
@ -355,121 +328,6 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
|||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#Blob",
|
||||
.namespace = "smithy.api",
|
||||
.name = "Blob",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.blob = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#Unit",
|
||||
.namespace = "smithy.api",
|
||||
.name = "Unit",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.unit = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#Long",
|
||||
.namespace = "smithy.api",
|
||||
.name = "Long",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.long = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#Float",
|
||||
.namespace = "smithy.api",
|
||||
.name = "Float",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.float = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#Document",
|
||||
.namespace = "smithy.api",
|
||||
.name = "Document",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.document = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
// These "Primitive" versions only appear to differ in that they have defaults
|
||||
// defined. Not currently handled:
|
||||
// byte PrimitiveByte
|
||||
// short PrimitiveShort
|
||||
|
||||
try list.append(.{
|
||||
.id = "smithy.api#PrimitiveBoolean",
|
||||
.namespace = "smithy.api",
|
||||
.name = "PrimitiveBoolean",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.boolean = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#PrimitiveInteger",
|
||||
.namespace = "smithy.api",
|
||||
.name = "PrimitiveInteger",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.integer = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#PrimitiveDouble",
|
||||
.namespace = "smithy.api",
|
||||
.name = "PrimitiveDouble",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.double = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#PrimitiveLong",
|
||||
.namespace = "smithy.api",
|
||||
.name = "PrimitiveLong",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.long = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
try list.append(.{
|
||||
.id = "smithy.api#PrimitiveFloat",
|
||||
.namespace = "smithy.api",
|
||||
.name = "PrimitiveFloat",
|
||||
.member = null,
|
||||
.shape = Shape{
|
||||
.float = .{
|
||||
.traits = &.{},
|
||||
},
|
||||
},
|
||||
});
|
||||
return list.toOwnedSlice();
|
||||
}
|
||||
|
||||
|
@ -568,13 +426,6 @@ fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseErro
|
|||
return Shape{ .member = try parseTraitsOnly(allocator, shape) };
|
||||
if (std.mem.eql(u8, shape_type, "resource"))
|
||||
return Shape{ .resource = try parseTraitsOnly(allocator, shape) };
|
||||
if (std.mem.eql(u8, shape_type, "enum"))
|
||||
return Shape{
|
||||
.@"enum" = .{
|
||||
.members = try parseMembers(allocator, shape.object.get("members")),
|
||||
.traits = try parseTraits(allocator, shape.object.get("traits")),
|
||||
},
|
||||
};
|
||||
|
||||
std.debug.print("Invalid Type: {s}", .{shape_type});
|
||||
return SmithyParseError.InvalidType;
|
||||
|
@ -635,9 +486,9 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
|
|||
return Trait{
|
||||
.aws_api_service = .{
|
||||
.sdk_id = value.object.get("sdkId").?.string,
|
||||
.arn_namespace = if (value.object.get("arnNamespace")) |a| a.string else null,
|
||||
.cloudformation_name = if (value.object.get("cloudFormationName")) |n| n.string else null,
|
||||
.cloudtrail_event_source = if (value.object.get("cloudTrailEventSource")) |s| s.string else null,
|
||||
.arn_namespace = value.object.get("arnNamespace").?.string,
|
||||
.cloudformation_name = value.object.get("cloudFormationName").?.string,
|
||||
.cloudtrail_event_source = value.object.get("cloudTrailEventSource").?.string,
|
||||
// what good is a service without an endpoint? I don't know - ask amp
|
||||
.endpoint_prefix = if (value.object.get("endpointPrefix")) |endpoint| endpoint.string else "",
|
||||
},
|
||||
|
@ -650,8 +501,6 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
|
|||
};
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#required"))
|
||||
return Trait{ .required = .{} };
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#clientOptional"))
|
||||
return Trait{ .client_optional = {} };
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#sparse"))
|
||||
return Trait{ .sparse = .{} };
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#box"))
|
||||
|
@ -716,14 +565,6 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
|
|||
.code = code,
|
||||
} };
|
||||
}
|
||||
if (std.mem.eql(u8, trait_type, "aws.protocols#awsQueryError")) {
|
||||
return Trait{
|
||||
.aws_query_error = .{
|
||||
.code = value.object.get("code").?.string, // code is required
|
||||
.http_response_code = value.object.get("httpResponseCode").?.integer,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#jsonName"))
|
||||
return Trait{ .json_name = value.string };
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#xmlName"))
|
||||
|
@ -741,10 +582,6 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
|
|||
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#xmlNamespace"))
|
||||
return null;
|
||||
|
||||
if (std.mem.eql(u8, trait_type, "smithy.api#enumValue"))
|
||||
return Trait{ .enum_value = value.string };
|
||||
|
||||
// TODO: win argument with compiler to get this comptime
|
||||
const list =
|
||||
\\aws.api#arnReference
|
||||
|
@ -786,45 +623,7 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
|
|||
\\smithy.api#xmlAttribute
|
||||
\\smithy.api#xmlFlattened
|
||||
\\smithy.waiters#waitable
|
||||
\\smithy.rules#endpointTests
|
||||
\\smithy.api#input
|
||||
\\smithy.api#output
|
||||
\\smithy.api#default
|
||||
\\smithy.api#examples
|
||||
\\smithy.api#uniqueItems
|
||||
\\smithy.api#addedDefault
|
||||
\\smithy.api#resourceIdentifier
|
||||
\\smithy.api#unstable
|
||||
\\smithy.api#property
|
||||
\\smithy.api#notProperty
|
||||
\\smithy.api#recommended
|
||||
\\smithy.api#httpBearerAuth
|
||||
\\smithy.api#nestedProperties
|
||||
\\smithy.rules#endpointRuleSet
|
||||
\\smithy.rules#contextParam
|
||||
\\smithy.rules#clientContextParams
|
||||
\\smithy.rules#staticContextParams
|
||||
\\aws.cloudformation#cfnResource
|
||||
\\aws.cloudformation#cfnMutability
|
||||
\\aws.cloudformation#cfnExcludeProperty
|
||||
\\aws.cloudformation#cfnAdditionalIdentifier
|
||||
\\aws.iam#actionPermissionDescription
|
||||
\\aws.iam#requiredActions
|
||||
\\aws.iam#conditionKeys
|
||||
\\aws.iam#iamResource
|
||||
\\aws.iam#iamAction
|
||||
\\aws.iam#supportedPrincipalTypes
|
||||
\\aws.iam#defineConditionKeys
|
||||
\\aws.iam#actionName
|
||||
\\aws.api#data
|
||||
\\aws.api#controlPlane
|
||||
\\aws.api#dataPlane
|
||||
\\aws.api#tagEnabled
|
||||
\\aws.api#taggable
|
||||
\\aws.protocols#awsQueryCompatible
|
||||
\\aws.protocols#httpChecksum
|
||||
\\aws.customizations#s3UnwrappedXmlOutput
|
||||
; // NOTE: inputs/outputs are not used in AWS models, but default is and might be handy
|
||||
;
|
||||
var iterator = std.mem.split(u8, list, "\n");
|
||||
while (iterator.next()) |known_but_unimplemented| {
|
||||
if (std.mem.eql(u8, trait_type, known_but_unimplemented))
|
||||
|
|
Loading…
Reference in New Issue
Block a user