From a2a55a80b9396b547399d825be6e310723dda5b4 Mon Sep 17 00:00:00 2001 From: Wes Date: Wed, 7 Feb 2024 09:27:24 -0700 Subject: [PATCH] fix: add imports for type parameter datarefs (#889) They were missing in the code gen for clients --- backend/schema/module.go | 8 ++++++++ backend/schema/schema_test.go | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/schema/module.go b/backend/schema/module.go index 85bc6dfc81..571102afc8 100644 --- a/backend/schema/module.go +++ b/backend/schema/module.go @@ -149,6 +149,14 @@ func (m *Module) Imports() []string { if n.Module != "" && n.Module != m.Name { imports[n.Module] = true } + // add imports for type parameters DataRefs as well + for _, p := range n.TypeParameters { + if p, ok := p.(*DataRef); ok { + if p.Module != "" && p.Module != m.Name { + imports[p.Module] = true + } + } + } case *VerbRef: if n.Module != "" && n.Module != m.Name { diff --git a/backend/schema/schema_test.go b/backend/schema/schema_test.go index 3bbfdd9d50..35d7b5f60f 100644 --- a/backend/schema/schema_test.go +++ b/backend/schema/schema_test.go @@ -55,15 +55,19 @@ func normaliseString(s string) string { func TestImports(t *testing.T) { input := ` module test { + data Generic { + value T + } data Data { ref other.Data ref another.Data + ref Generic } } ` schema, err := ParseModuleString("", input) assert.NoError(t, err) - assert.Equal(t, []string{"another", "other"}, schema.Imports()) + assert.Equal(t, []string{"another", "new", "other"}, schema.Imports()) } func TestVisit(t *testing.T) {