From 34b871e65149fb6a01cc50430c713c72f6c17bde Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 28 Apr 2025 11:40:21 -0500 Subject: [PATCH 1/2] test: correct pkg used in test cases (#21) --- testdata/enums/enums.go | 2 +- testdata/enums/enums.ts | 8 ++++---- testdata/enumtypes/enumtypes.go | 2 +- testdata/enumtypes/enumtypes.ts | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/testdata/enums/enums.go b/testdata/enums/enums.go index b4a69df..82c7771 100644 --- a/testdata/enums/enums.go +++ b/testdata/enums/enums.go @@ -1,4 +1,4 @@ -package codersdk +package enums type ( EnumString string diff --git a/testdata/enums/enums.ts b/testdata/enums/enums.ts index 819fa79..63a40e7 100644 --- a/testdata/enums/enums.ts +++ b/testdata/enums/enums.ts @@ -1,22 +1,22 @@ // Code generated by 'guts'. DO NOT EDIT. -// From codersdk/enums.go +// From enums/enums.go export enum Audience { Team = "team", Tenant = "tenant", World = "world" } -// From codersdk/enums.go +// From enums/enums.go export enum EnumInt { EnumNumBar = 10, EnumNumFoo = 5 } -// From codersdk/enums.go +// From enums/enums.go export type EnumSliceType = readonly EnumString[]; -// From codersdk/enums.go +// From enums/enums.go export enum EnumString { EnumBar = "bar", EnumBaz = "baz", diff --git a/testdata/enumtypes/enumtypes.go b/testdata/enumtypes/enumtypes.go index b4a69df..d13ec85 100644 --- a/testdata/enumtypes/enumtypes.go +++ b/testdata/enumtypes/enumtypes.go @@ -1,4 +1,4 @@ -package codersdk +package enumtypes type ( EnumString string diff --git a/testdata/enumtypes/enumtypes.ts b/testdata/enumtypes/enumtypes.ts index 7392a61..cfe2902 100644 --- a/testdata/enumtypes/enumtypes.ts +++ b/testdata/enumtypes/enumtypes.ts @@ -1,19 +1,19 @@ // Code generated by 'guts'. DO NOT EDIT. -// From codersdk/enumtypes.go +// From enumtypes/enumtypes.go export type Audience = "team" | "tenant" | "world"; export const Audiences: Audience[] = ["team", "tenant", "world"]; -// From codersdk/enumtypes.go +// From enumtypes/enumtypes.go export type EnumInt = 10 | 5; export const EnumInts: EnumInt[] = [10, 5]; -// From codersdk/enumtypes.go +// From enumtypes/enumtypes.go export type EnumSliceType = readonly EnumString[]; -// From codersdk/enumtypes.go +// From enumtypes/enumtypes.go export type EnumString = "bar" | "baz" | "foo" | "qux"; export const EnumStrings: EnumString[] = ["bar", "baz", "foo", "qux"]; From ad369017e95b1edee80b110d7ed5cc4bba393d69 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 28 Apr 2025 12:00:43 -0500 Subject: [PATCH 2/2] feat: 'NotNullMaps' to handle generic arguments (#22) --- bindings/walk/walk.go | 2 +- convert_test.go | 2 ++ testdata/notnullmap/mutations | 1 + testdata/notnullmap/notnullmap.go | 10 ++++++++++ testdata/notnullmap/notnullmap.ts | 12 ++++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 testdata/notnullmap/mutations create mode 100644 testdata/notnullmap/notnullmap.go create mode 100644 testdata/notnullmap/notnullmap.ts diff --git a/bindings/walk/walk.go b/bindings/walk/walk.go index bb8d7f8..fa6d6e6 100644 --- a/bindings/walk/walk.go +++ b/bindings/walk/walk.go @@ -53,7 +53,7 @@ func Walk(v Visitor, node bindings.Node) { Walk(v, n.Type) Walk(v, n.Initializer) case *bindings.ReferenceType: - // noop + walkList(v, n.Arguments) case *bindings.LiteralKeyword: // noop case *bindings.LiteralType: diff --git a/convert_test.go b/convert_test.go index 0f01e74..95e18e8 100644 --- a/convert_test.go +++ b/convert_test.go @@ -106,6 +106,8 @@ func TestGeneration(t *testing.T) { muts := strings.Split(strings.TrimSpace(string(mutsCSV)), ",") for _, m := range muts { switch m { + case "NotNullMaps": + mutations = append(mutations, config.NotNullMaps) case "EnumAsTypes": mutations = append(mutations, config.EnumAsTypes) case "EnumLists": diff --git a/testdata/notnullmap/mutations b/testdata/notnullmap/mutations new file mode 100644 index 0000000..8f833da --- /dev/null +++ b/testdata/notnullmap/mutations @@ -0,0 +1 @@ +NotNullMaps \ No newline at end of file diff --git a/testdata/notnullmap/notnullmap.go b/testdata/notnullmap/notnullmap.go new file mode 100644 index 0000000..1957d8e --- /dev/null +++ b/testdata/notnullmap/notnullmap.go @@ -0,0 +1,10 @@ +package notnullmap + +type Foo struct { + Bar map[string]bool + Nested GenericFoo[map[string]int] +} + +type GenericFoo[T any] struct { + Bar T +} diff --git a/testdata/notnullmap/notnullmap.ts b/testdata/notnullmap/notnullmap.ts new file mode 100644 index 0000000..559b127 --- /dev/null +++ b/testdata/notnullmap/notnullmap.ts @@ -0,0 +1,12 @@ +// Code generated by 'guts'. DO NOT EDIT. + +// From notnullmap/notnullmap.go +interface Foo { + Bar: Record; + Nested: GenericFoo>; +} + +// From notnullmap/notnullmap.go +interface GenericFoo { + Bar: T; +}