Compare commits

...
Sign in to create a new pull request.

9 commits

Author SHA1 Message Date
fd9be1afbf
more known, but ignored, traits
All checks were successful
Generic zig build / build (push) Successful in 26s
2025-05-07 12:34:10 -07:00
ec6aa300d9
more known, but ignored, traits
All checks were successful
Generic zig build / build (push) Successful in 28s
2025-05-07 12:31:53 -07:00
4187d89951
update CI for forgejo
All checks were successful
Generic zig build / build (push) Successful in 34s
2025-05-07 08:52:23 -07:00
7634a08579
move off github actions 2025-05-07 08:49:57 -07:00
9eaaada446
add support for shortsighted services that do not include a version
Some checks failed
Generic zig build / build (push) Failing after 10s
2025-05-07 08:36:46 -07:00
d8925f37b9
add .envrc for zig 0.14.0 2025-05-07 08:36:10 -07:00
342b15eebd
add aws.endpoints#standardPartitionalEndpoints to the list of known but ignored traits 2025-05-07 08:35:09 -07:00
a4c6ec6dfe
update to zig 0.14.0 2025-03-20 03:36:29 -07:00
3ed98751bc
add AwsProtocol, allowing usage within a build.zig import
All checks were successful
Generic zig build / build (push) Successful in 19s
2024-08-23 11:09:22 -07:00
5 changed files with 72 additions and 18 deletions

8
.envrc Normal file
View file

@ -0,0 +1,8 @@
# vi: ft=sh
# shellcheck shell=bash
if ! has zvm_direnv_version || ! zvm_direnv_version 2.0.0; then
source_url "https://git.lerch.org/lobo/zvm-direnv/raw/tag/2.0.0/direnvrc" "sha256-8Umzxj32hFU6G0a7Wrq0KTNDQ8XEuje2A3s2ljh/hFY="
fi
use zig 0.14.0

View file

@ -9,17 +9,20 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: elerch/setup-zig@v3
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup Zig
uses: https://github.com/mlugg/setup-zig@v1.2.1
with:
version: 0.13.0
- uses: elerch/zig-action-cache@v1.1.6
version: 0.14.0
- name: Restore Zig caches
uses: https://github.com/Hanaasagi/zig-action-cache@3954aae427f8b05914e08dfd79f15e1f2e435929
- name: Build project
run: zig build --summary all
- name: Run tests
run: zig build test --summary all
- name: Notify
uses: elerch/action-notify-ntfy@v2.github
uses: https://git.lerch.org/lobo/action-notify-ntfy@v2
if: always() && env.GITEA_ACTIONS == 'true'
with:
host: ${{ secrets.NTFY_HOST }}

View file

@ -50,3 +50,7 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
}
// define AwsProtocol to support usage within build.zig as an import
const smithy = @import("src/smithy.zig");
pub const AwsProtocol = smithy.AwsProtocol;

View file

@ -1,14 +1,14 @@
.{
.name = "smithy",
.name = .smithy,
.version = "1.0.0",
.fingerprint = 0xccfd3d0281810cb8,
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"README.md",
"LICENSE",
"build.zig",
"build.zig.zon",
"src",
"README.md",
"LICENSE",
},
.dependencies = .{
},
.dependencies = .{},
}

View file

@ -235,7 +235,7 @@ const Shape = union(ShapeType) {
traits: []Trait,
},
service: struct {
version: []const u8,
version: ?[]const u8, // A version is optional in Smithy. https://smithy.io/2.0/spec/service-types.html
operations: [][]const u8,
resources: [][]const u8,
traits: []Trait,
@ -482,7 +482,7 @@ fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseErro
if (std.mem.eql(u8, shape_type, "service"))
return Shape{
.service = .{
.version = shape.object.get("version").?.string,
.version = if (shape.object.get("version")) |v| v.string else null,
.operations = if (shape.object.get("operations")) |ops|
try parseTargetList(allocator, ops.array)
else
@ -789,6 +789,7 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
\\smithy.api#timestampFormat
\\smithy.api#xmlAttribute
\\smithy.api#xmlFlattened
\\smithy.api#requestCompression
\\smithy.waiters#waitable
\\smithy.rules#endpointTests
\\smithy.api#input
@ -804,17 +805,24 @@ fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Tra
\\smithy.api#recommended
\\smithy.api#httpBearerAuth
\\smithy.api#nestedProperties
\\smithy.api#private
\\smithy.rules#endpointRuleSet
\\smithy.rules#contextParam
\\smithy.rules#clientContextParams
\\smithy.rules#staticContextParams
\\smithy.rules#operationContextParams
\\smithy.test#smokeTests
\\aws.cloudformation#cfnResource
\\aws.cloudformation#cfnMutability
\\aws.cloudformation#cfnExcludeProperty
\\aws.cloudformation#cfnAdditionalIdentifier
\\aws.endpoints#standardPartitionalEndpoints
\\aws.endpoints#dualStackOnlyEndpoints
\\aws.endpoints#standardRegionalEndpoints
\\aws.iam#actionPermissionDescription
\\aws.iam#requiredActions
\\aws.iam#conditionKeys
\\aws.iam#conditionKeyValue
\\aws.iam#iamResource
\\aws.iam#iamAction
\\aws.iam#supportedPrincipalTypes
@ -893,6 +901,37 @@ fn read_file_to_string(allocator: std.mem.Allocator, file_name: []const u8, max_
const test_data: []const u8 = @embedFile("test.json");
const intrinsic_type_count: usize = 15; // 15 intrinsic types are added to every model (see shapes() function)
test "parse service without version" {
const test_string =
\\ {
\\ "smithy": "1.0",
\\ "shapes": {
\\ "com.amazonaws.sts#AWSSecurityTokenServiceV20110615": {
\\ "type": "service",
\\ "operations": [
\\ {
\\ "target": "op"
\\ }
\\ ]
\\ }
\\ }
\\ }
\\
\\
;
const allocator = std.testing.allocator;
const model = try parse(allocator, test_string);
defer model.deinit();
try expect(std.mem.eql(u8, model.version, "1.0"));
try std.testing.expectEqual(intrinsic_type_count + 1, model.shapes.len);
try std.testing.expectEqualStrings("com.amazonaws.sts#AWSSecurityTokenServiceV20110615", model.shapes[0].id);
try std.testing.expectEqualStrings("com.amazonaws.sts", model.shapes[0].namespace);
try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", model.shapes[0].name);
try std.testing.expect(model.shapes[0].member == null);
try std.testing.expect(model.shapes[0].shape.service.version == null);
}
test "parse string" {
const test_string =
\\ {
@ -923,7 +962,7 @@ test "parse string" {
try std.testing.expectEqualStrings("com.amazonaws.sts", model.shapes[0].namespace);
try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", model.shapes[0].name);
try std.testing.expect(model.shapes[0].member == null);
try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version);
try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version.?);
}
test "parse shape with member" {
const test_string =
@ -953,7 +992,7 @@ test "parse shape with member" {
try std.testing.expectEqualStrings("com.amazonaws.sts#AWSSecurityTokenServiceV20110615$member", model.shapes[0].id);
try std.testing.expectEqualStrings("com.amazonaws.sts", model.shapes[0].namespace);
try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", model.shapes[0].name);
try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version);
try std.testing.expectEqualStrings("2011-06-15", model.shapes[0].shape.service.version.?);
try std.testing.expectEqualStrings("member", model.shapes[0].member.?);
}
test "parse file" {
@ -978,7 +1017,7 @@ test "parse file" {
try std.testing.expectEqualStrings("com.amazonaws.sts#AWSSecurityTokenServiceV20110615", svc.id);
try std.testing.expectEqualStrings("com.amazonaws.sts", svc.namespace);
try std.testing.expectEqualStrings("AWSSecurityTokenServiceV20110615", svc.name);
try std.testing.expectEqualStrings("2011-06-15", svc.shape.service.version);
try std.testing.expectEqualStrings("2011-06-15", svc.shape.service.version.?);
// Should be 6, but we don't handle title or xml namespace
try std.testing.expectEqual(@as(usize, 4), svc.shape.service.traits.len);
try std.testing.expectEqual(@as(usize, 8), svc.shape.service.operations.len);