fix(spec): unwrap SQL wrapper metadata types

This commit is contained in:
2026-08-28 22:42:52 +02:00
parent dab4940ace
commit a68cf83be6
6 changed files with 218 additions and 19 deletions
+34
View File
@@ -0,0 +1,34 @@
package resolvemcp
import (
"testing"
"github.com/bitechdev/ResolveSpec/pkg/spectypes"
)
func TestBuildModelInfo_UnwrapsSQLTypes(t *testing.T) {
type related struct {
ID int64 `json:"id"`
}
type model struct {
Name spectypes.SqlString `gorm:"column:name" json:"name"`
Metadata spectypes.SqlJSONB `gorm:"column:metadata;type:jsonb" json:"metadata"`
Related related `json:"related"`
}
info := buildModelInfo("public", "models", model{})
columns := make(map[string]columnInfo, len(info.columns))
for _, column := range info.columns {
columns[column.jsonName] = column
}
if column, ok := columns["name"]; !ok || column.goType != "string" || !column.nullable {
t.Errorf("expected name SQL wrapper column, got %+v", column)
}
if column, ok := columns["metadata"]; !ok || !column.nullable {
t.Errorf("expected metadata SQL wrapper column, got %+v", column)
}
if len(info.relationNames) != 1 || info.relationNames[0] != "related" {
t.Errorf("expected only related to be a relation, got %v", info.relationNames)
}
}