Skip to content

Commit

Permalink
- added handler mbus notification support
Browse files Browse the repository at this point in the history
- enhanced two level package imports support
  • Loading branch information
adranwit committed Sep 12, 2024
1 parent 20ef3a9 commit 2f58bc4
Show file tree
Hide file tree
Showing 20 changed files with 320 additions and 74 deletions.
30 changes: 29 additions & 1 deletion cmd/command/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/viant/datly/view/extension"
"github.com/viant/datly/view/state"
"github.com/viant/tagly/format/text"
"github.com/viant/xreflect"
"golang.org/x/mod/modfile"

"path"
"reflect"
"strings"
Expand Down Expand Up @@ -240,14 +243,15 @@ func (s *Service) buildHandlerIfNeeded(ruleOptions *options.Rule, dSQL *string)
return nil
}

aState, err := inference.NewState(ruleOptions.SourceCodeLocation(), rule.InputType, extension.Config.Types)
aState, err := inference.NewState(ruleOptions.ComponentPath(), rule.InputType, extension.Config.Types)
if err != nil {
return err
}
rule.Handler = &handler.Handler{
Type: rule.Type,
InputType: rule.InputType,
OutputType: rule.OutputType,
MessageBus: rule.MessageBus,
Arguments: rule.HandlerArgs,
}
var entityParam *inference.Parameter
Expand Down Expand Up @@ -276,6 +280,22 @@ func (s *Service) buildHandlerIfNeeded(ruleOptions *options.Rule, dSQL *string)
tmpl := codegen.NewTemplate(rule, &inference.Spec{Type: aType})
tmpl.SetResource(&translator.Resource{Rule: rule})

for _, param := range aState {
if param.Schema.PackagePath != "" {
modFile, err := ruleOptions.Module()
if err != nil || modFile == nil {
return fmt.Errorf("missing mod file: %w", err)
}
goImps := xreflect.GoImports{{Name: "", Module: param.Schema.PackagePath}}
pkg := param.Schema.GetPackage()

if pkgPath := goImps.Lookup(pkg); pkgPath != "" {
pkgPath = s.updateImportPath(pkgPath, modFile)
typeName := pkgPath + "." + param.Schema.SimpleTypeName()
tmpl.Imports.AddType(typeName)
}
}
}
tmpl.Imports.AddType(rule.InputType)
tmpl.Imports.AddType(rule.Type)
if aType != nil {
Expand All @@ -297,6 +317,14 @@ func (s *Service) buildHandlerIfNeeded(ruleOptions *options.Rule, dSQL *string)
return nil
}

func (s *Service) updateImportPath(path string, file *modfile.Module) string {
ret := strings.Replace(path, file.Mod.Path, "", 1)
if strings.HasPrefix(ret, "/") {
ret = ret[1:]
}
return ret
}

func (s *Service) generateTemplate(gen *options.Generate, template *codegen.Template, info *plugin.Info) error {
//needed for both go and velty
opts := s.translateGenerationOptions(gen, info)
Expand Down
1 change: 1 addition & 0 deletions cmd/command/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/viant/datly/internal/plugin"
"github.com/viant/datly/internal/translator"
"github.com/viant/pgo"

"os"
"os/exec"
)
Expand Down
40 changes: 39 additions & 1 deletion cmd/options/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/viant/datly/internal/setter"
"github.com/viant/datly/internal/translator/parser"
"github.com/viant/parsly"
"golang.org/x/mod/modfile"
"os"
"path"
"path/filepath"
Expand All @@ -25,12 +26,49 @@ type Rule struct {
Output []string
Index int
ModuleLocation string `short:"m" long:"module" description:"go module package root" default:"pkg"`
module *modfile.Module
Generated bool
SkipCompDef bool `short:"B" long:"sComp" description:"skip component def"`
}

func (r *Rule) SourceCodeLocation() string {
// Module returns go module
func (r *Rule) Module() (*modfile.Module, error) {
if r.module != nil {
return r.module, nil
}
var err error
fs := afs.New()
r.module, err = r.loadModFile(fs, url.Join(r.Project, "go.mod"))
if err != nil {
return r.module, err
}
if r.module == nil {
r.module, err = r.loadModFile(fs, url.Join(r.ModuleLocation, "go.mod"))
if err != nil {
return r.module, err
}
}
return r.module, nil
}

func (r *Rule) loadModFile(fs afs.Service, URL string) (*modfile.Module, error) {
if ok, _ := fs.Exists(context.Background(), URL); ok {
data, err := fs.DownloadWithURL(context.Background(), URL)
if err != nil {
return nil, err
}
aFile, err := modfile.Parse("", data, nil)
if err != nil {
return nil, err
}
return aFile.Module, nil
}
return nil, nil
}

func (r *Rule) ComponentPath() string {
fileFolder := r.GoModuleLocation()

if r.ModulePrefix != "" {
fileFolder = url.Join(fileFolder, r.ModulePrefix)
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ require (
github.com/viant/afsc v1.9.1
github.com/viant/assertly v0.9.1-0.20220620174148-bab013f93a60
github.com/viant/bigquery v0.3.3
github.com/viant/cloudless v1.9.9-0.20240725201210-d3d3fbe48d88
github.com/viant/cloudless v1.11.0
github.com/viant/dsc v0.16.2 // indirect
github.com/viant/dsunit v0.10.8
github.com/viant/dyndb v0.1.4-0.20221214043424-27654ab6ed9c
github.com/viant/gmetric v0.3.1-0.20230405233616-cc90deee60c4
github.com/viant/godiff v0.4.1
github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b
github.com/viant/pgo v0.11.0
github.com/viant/scy v0.11.1-0.20240809212619-84029a5e3755
github.com/viant/scy v0.12.0
github.com/viant/sqlx v0.15.1
github.com/viant/structql v0.4.2-0.20240712002135-b1ef22dd834f
github.com/viant/toolbox v0.36.0
github.com/viant/velty v0.2.1-0.20230927172116-ba56497b5c85
github.com/viant/xreflect v0.6.2
github.com/viant/xreflect v0.7.0
github.com/viant/xunsafe v0.9.4
golang.org/x/mod v0.16.0
golang.org/x/oauth2 v0.19.0 // indirect
Expand Down
26 changes: 6 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1083,10 +1083,6 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
github.com/viant/aerospike v0.2.4 h1:sMZk5iutLASDQRwIK6lkX0G/s5Ki85G0oj1UcSE3T4E=
github.com/viant/aerospike v0.2.4/go.mod h1:3Xw7jzP8bvJjRdTPV/TsM9lGEIyj3bPxbvmIVhfCU5E=
github.com/viant/aerospike v0.2.6 h1:CiFGRblA/BxN63P5NuUDujOpNj0FaSCzNDoKiUsrPdo=
github.com/viant/aerospike v0.2.6/go.mod h1:YBQqHjUaSBA6PvMGZE/k92hc+DEy71GGvc0GsYzjVXA=
github.com/viant/aerospike v0.2.7 h1:rgvdUEFxseCk7flFfEx21WCUTELxCUmQhzou7WIsULQ=
github.com/viant/aerospike v0.2.7/go.mod h1:2VIRdUyd3bP14rCXXeVIXeuy6Fd2ncL15yLm2sDtKQo=
github.com/viant/afs v1.25.1-0.20231110184132-877ed98abca1 h1:q83rO9rKNCsT/W9x9EBmCVt24yjFDRmhslLhaL4h7DE=
Expand All @@ -1099,8 +1095,8 @@ github.com/viant/assertly v0.9.1-0.20220620174148-bab013f93a60 h1:VFJvCOHKXv4IqX
github.com/viant/assertly v0.9.1-0.20220620174148-bab013f93a60/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/bigquery v0.3.3 h1:ZJw4FtfrmYAJwf8T5nz0PYdHlb7ixHLpCN7+y+akjBo=
github.com/viant/bigquery v0.3.3/go.mod h1:EYjfaKz5a0ho9Wg48+NzHnwOuA+Q81c0I0lBUEtsX8s=
github.com/viant/cloudless v1.9.9-0.20240725201210-d3d3fbe48d88 h1:PuQP3Nv9cOKuWgngY8zDKGQyw+8DQdn4KolkTMwk2mg=
github.com/viant/cloudless v1.9.9-0.20240725201210-d3d3fbe48d88/go.mod h1:t6BDFAXg3s3/aULrPrR885vNmyI4MoHfXNu+TIzl/M0=
github.com/viant/cloudless v1.11.0 h1:TnQxPV/7Zow5h46WqABsofP+BfaerIiyCHnPyzG8sWs=
github.com/viant/cloudless v1.11.0/go.mod h1:WawTnnRlMzsHGypTXxMY7yCjwcbMoWvtb0iZq5WyqQo=
github.com/viant/dsc v0.16.2 h1:Kw8zNct6dTISVZpartYK4MlKiwSSqIdRSq5CYjtZcc4=
github.com/viant/dsc v0.16.2/go.mod h1:vkBPh3XSXUBB/ePbEO0VsKPaiN4JLRuB3QVftbS6KI4=
github.com/viant/dsunit v0.10.8 h1:egq8LH4ogXTweFhzl/RqPhM9PNJtG35sbe02KnjFj3I=
Expand All @@ -1119,12 +1115,8 @@ github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b h1:3q166tV28yFdbFV+
github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b/go.mod h1:85fneXJbErKMGhSQto3A5ElTQCwl3t74U9cSV0waBHw=
github.com/viant/pgo v0.11.0 h1:PNuYVhwTfyrAHGBO6lxaMFuHP4NkjKV8ULecz3OWk8c=
github.com/viant/pgo v0.11.0/go.mod h1:MFzHmkRFZlciugEgUvpl/3grK789PBSH4dUVSLOSo+Q=
github.com/viant/scy v0.11.1-0.20240809212619-84029a5e3755 h1:sWN+z/MrbhborVF9NhdQl8LMnHkotZNAkx/aTScanAA=
github.com/viant/scy v0.11.1-0.20240809212619-84029a5e3755/go.mod h1:Lz1VPlmjVi4ydZ5ikP/d5uQS/xYs22HG23++PgLRlKQ=
github.com/viant/sqlparser v0.7.1 h1:YUBsIOUnY8WaF4sdKDz6MqA1+sP5q5QuewE465W2LAM=
github.com/viant/sqlparser v0.7.1/go.mod h1:2QRGiGZYk2/pjhORGG1zLVQ9JO+bXFhqIVi31mkCRPg=
github.com/viant/sqlparser v0.7.2 h1:8U7W2I160m3vlDotJpsgW/OxroxwjDj3mdwAgP5AAXw=
github.com/viant/sqlparser v0.7.2/go.mod h1:2QRGiGZYk2/pjhORGG1zLVQ9JO+bXFhqIVi31mkCRPg=
github.com/viant/scy v0.12.0 h1:Fo0DHviM1LHjj2XmtgIERmeh+z4X66AUXnUCTswFXT4=
github.com/viant/scy v0.12.0/go.mod h1:Lz1VPlmjVi4ydZ5ikP/d5uQS/xYs22HG23++PgLRlKQ=
github.com/viant/sqlparser v0.7.4 h1:/jXiB2zC9cDXTwR0TgF2evrHC5oQPCAkkf0KZfe9Vks=
github.com/viant/sqlparser v0.7.4/go.mod h1:2QRGiGZYk2/pjhORGG1zLVQ9JO+bXFhqIVi31mkCRPg=
github.com/viant/sqlx v0.15.1 h1:JgZPTfFZEfV6ocnkGqhiHA8R620UBPQopUOfR+tTYMk=
Expand All @@ -1143,14 +1135,10 @@ github.com/viant/velty v0.2.1-0.20230927172116-ba56497b5c85 h1:zKk+6hqUipkJXCPCH
github.com/viant/velty v0.2.1-0.20230927172116-ba56497b5c85/go.mod h1:Q/UXviI2Nli8WROEpYd/BELMCSvnulQeyNrbPmMiS/Y=
github.com/viant/x v0.3.0 h1:/3A0z/uySGxMo6ixH90VAcdjI00w5e3REC1zg5hzhJA=
github.com/viant/x v0.3.0/go.mod h1:54jP3qV+nnQdNDaWxEwGTAAzCu9sx9er9htiwTW/Mcw=
github.com/viant/xdatly v0.5.4-0.20240808174705-681c88dd32fa h1:ezJDEcPmKM1EW7tJYvZ5NV+ioIsg0+2PzvBHoSfI1og=
github.com/viant/xdatly v0.5.4-0.20240808174705-681c88dd32fa/go.mod h1:YwNS31k5r1Ldw5s7wmQXUKaalN6BWcfX9qePO/b/ilc=
github.com/viant/xdatly v0.5.4-0.20240904221257-06e43f22d5f0 h1:+3rGYbklkuQ7h+zF0RPrUUxN8BQWeQaHOCWyEu1Vmhk=
github.com/viant/xdatly v0.5.4-0.20240904221257-06e43f22d5f0/go.mod h1:YwNS31k5r1Ldw5s7wmQXUKaalN6BWcfX9qePO/b/ilc=
github.com/viant/xdatly/extension v0.0.0-20231013204918-ecf3c2edf259 h1:9Yry3PUBDzc4rWacOYvAq/TKrTV0agvMF0gwm2gaoHI=
github.com/viant/xdatly/extension v0.0.0-20231013204918-ecf3c2edf259/go.mod h1:fb8YgbVadk8X5ZLz49LWGzWmQlZd7Y/I5wE0ru44bIo=
github.com/viant/xdatly/handler v0.0.0-20240808174705-681c88dd32fa h1:Clv8cnXLuY55QoBeaoIe5pfAbxPw9TyaBMMOlQvvjSU=
github.com/viant/xdatly/handler v0.0.0-20240808174705-681c88dd32fa/go.mod h1:bBa479sCB55VymMrXFccluUFkf6oRI77xhtnWIcL8K0=
github.com/viant/xdatly/handler v0.0.0-20240904221257-06e43f22d5f0 h1:BkfvWH4jucNeZaFjmu9Ya9fdCHsMQayVZzlD7kViUz8=
github.com/viant/xdatly/handler v0.0.0-20240904221257-06e43f22d5f0/go.mod h1:bBa479sCB55VymMrXFccluUFkf6oRI77xhtnWIcL8K0=
github.com/viant/xdatly/types/core v0.0.0-20240109065401-9758ebacb4bb h1:X4emK6TIR6IXiFlQz9wEdCi5RJMG3dg3e8+VLQ2zhnM=
Expand All @@ -1161,10 +1149,8 @@ github.com/viant/xlsy v0.3.0 h1:j/cADAd41XcxfAGSyPUZmEOHbVe2dcjdVI6JiTKA6ws=
github.com/viant/xlsy v0.3.0/go.mod h1:RajfF9HkL/PfIxRCvZSubpNlpdMUNDKYZp8C1o3vF4Q=
github.com/viant/xmlify v0.1.1-0.20231127181625-8a6b48ceea12 h1:j7I0D1M5lvmc5dxXzSyx99GSfYiilrSc1hnmFFL+jrg=
github.com/viant/xmlify v0.1.1-0.20231127181625-8a6b48ceea12/go.mod h1:w25+umH6nthlQ8ACT3K2/YJOLlbTXKLQXkdqFs6ky9s=
github.com/viant/xreflect v0.6.2 h1:PzpiTHHMwqMV2ScDJph+pMkk+JvuXFZFj6xwnM/E6sc=
github.com/viant/xreflect v0.6.2/go.mod h1:BwI+lqFjhKv2Vn4E0Jt6nvbwcFOWrM6H+sOMOX3JiU4=
github.com/viant/xunsafe v0.9.3 h1:XvV6c0AWpyq2cdJmBDJn73tcJ4FE3w3LRJWdiRR+wNk=
github.com/viant/xunsafe v0.9.3/go.mod h1:V3RCwtqpbNPznhmHysyAOpsyuSVkIYWo1Ewip7qb9/s=
github.com/viant/xreflect v0.7.0 h1:989U0URnqh2V4W/fJebYhPz00VEfi7febzS887IQb/8=
github.com/viant/xreflect v0.7.0/go.mod h1:BwI+lqFjhKv2Vn4E0Jt6nvbwcFOWrM6H+sOMOX3JiU4=
github.com/viant/xunsafe v0.9.4 h1:FcebICUWn1ZLJNdp7pGCpJGpjh2cT5YKFoWE79h9jkw=
github.com/viant/xunsafe v0.9.4/go.mod h1:V3RCwtqpbNPznhmHysyAOpsyuSVkIYWo1Ewip7qb9/s=
github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
Expand Down
13 changes: 9 additions & 4 deletions internal/inference/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (p *Parameter) SyncObject() {
}

// TODO unify with state.BuildParameter (by converting field *ast.Field to reflect.StructField)
func buildParameter(field *ast.Field, aTag *tags.Tag, types *xreflect.Types, embedFS *embed.FS) (*Parameter, error) {
func buildParameter(field *ast.Field, aTag *tags.Tag, types *xreflect.Types, embedFS *embed.FS, imps xreflect.GoImports) (*Parameter, error) {
//SQL := extractSQL(field)
if field.Tag == nil {
return nil, nil
Expand Down Expand Up @@ -270,20 +270,25 @@ func buildParameter(field *ast.Field, aTag *tags.Tag, types *xreflect.Types, emb
if err != nil {
return nil, fmt.Errorf("failed to create param: %v due to %w", param.Name, err)
}

if strings.Contains(fieldType, "struct{") {
typeName := ""
if field.Tag != nil {
if typeName, _ = reflect.StructTag(strings.Trim(field.Tag.Value, "`")).Lookup("typeName"); typeName == "" {
typeName = field.Names[0].Name
}
}
rType, err := types.Lookup(typeName, xreflect.WithTypeDefinition(fieldType))
aType := xreflect.NewType(typeName, xreflect.WithTypeDefinition(fieldType), xreflect.WithGoImports(imps))
rType, err := types.LookupType(aType)
if err != nil {
return nil, fmt.Errorf("failed to create param: %v due reflect.Type %w", param.Name, err)
}
param.Schema = state.NewSchema(rType)
param.Schema = state.NewSchema(rType, state.WithPackagePath(aType.PackagePath))
} else {
param.Schema = &state.Schema{DataType: fieldType}

aType := xreflect.NewType(fieldType, xreflect.WithGoImports(imps))
_, _ = types.LookupType(aType) //to populate package path
param.Schema = &state.Schema{DataType: fieldType, PackagePath: aType.PackagePath}
}

param.Schema.Cardinality = cardinality
Expand Down
39 changes: 25 additions & 14 deletions internal/inference/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (s State) Parameters() state.Parameters {
return result
}

func (s State) Compact(modulePath string) (State, error) {
if err := s.EnsureReflectTypes(modulePath, ""); err != nil {
func (s State) Compact(modulePath string, registry *xreflect.Types) (State, error) {
if err := s.EnsureReflectTypes(modulePath, "", registry); err != nil {
return nil, err
}
var result = State{}
Expand Down Expand Up @@ -342,23 +342,26 @@ func (s State) ensureSchema(dirTypes *xreflect.DirTypes) error {
continue
}
paramDataType := param.Schema.DataType
paramType, err := xreflect.Parse(paramDataType, xreflect.WithTypeLookup(func(name string, options ...xreflect.Option) (reflect.Type, error) {
result, err := dirTypes.Type(name)
if err == nil {
return result, nil
}
return dirTypes.Registry.Lookup(name, options...)
}))
paramType, err := xreflect.Parse(paramDataType,
xreflect.WithGoImports(dirTypes.GoImports),
xreflect.WithTypeLookup(func(name string, options ...xreflect.Option) (reflect.Type, error) {
result, err := dirTypes.Type(name)
if err == nil {
return result, nil
}
options = append(options, xreflect.WithGoImports(dirTypes.GoImports))
return dirTypes.Registry.Lookup(name, options...)
}))
if err != nil {
return fmt.Errorf("invalid parameter '%v' schema: '%v' %w", param.Name, param.Schema.DataType, err)
}

oldSchema := param.Schema
param.Schema = state.NewSchema(paramType)
param.Schema.DataType = paramDataType

if oldSchema != nil {
param.Schema.Cardinality = oldSchema.Cardinality
param.Schema.PackagePath = oldSchema.PackagePath
}
}
return nil
Expand Down Expand Up @@ -440,8 +443,11 @@ func (s State) enureStructQLType(param *Parameter) error {
return nil
}

func (s State) EnsureReflectTypes(modulePath string, pkg string) error {
typeRegistry := xreflect.NewTypes(xreflect.WithPackagePath(modulePath), xreflect.WithRegistry(extension.Config.Types))
func (s State) EnsureReflectTypes(modulePath string, pkg string, registry *xreflect.Types) error {
if registry == nil {
registry = extension.Config.Types
}
typeRegistry := xreflect.NewTypes(xreflect.WithPackagePath(modulePath), xreflect.WithRegistry(registry))
for _, param := range s {
if param.Schema == nil {
continue
Expand Down Expand Up @@ -661,13 +667,16 @@ func NewState(modulePath, dataType string, types *xreflect.Types) (State, error)
embedHolder := discoverEmbeds(embedRoot)
embedFS := embedHolder.EmbedFs()
var aState = State{}
var goImports xreflect.GoImports
dirTypes, err := xreflect.ParseTypes(baseDir,
xreflect.WithParserMode(parser.ParseComments),
xreflect.WithRegistry(types),
xreflect.WithOnField(func(typeName string, field *ast.Field) error {
xreflect.WithOnField(func(typeName string, field *ast.Field, imports xreflect.GoImports) error {
if field.Tag == nil {
return nil
}
goImports = append(goImports, imports...)

fieldTag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
aTag, err := tags.ParseStateTags(fieldTag, embedFS)
if err != nil {
Expand All @@ -685,7 +694,7 @@ func NewState(modulePath, dataType string, types *xreflect.Types) (State, error)
name = field.Names[0].Name
}
setter.SetStringIfEmpty(&pTag.Name, name)
param, err := buildParameter(field, aTag, types, embedFS)
param, err := buildParameter(field, aTag, types, embedFS, imports)
if param == nil {
return err
}
Expand All @@ -710,12 +719,14 @@ func NewState(modulePath, dataType string, types *xreflect.Types) (State, error)
return nil
}))

dirTypes.GoImports = goImports
if err != nil {
return nil, err
}
if _, err = dirTypes.Type(dataType); err != nil {
return nil, err
}
dirTypes.GoImports = goImports
if err = aState.ensureSchema(dirTypes); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/translator/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (r *Resource) loadState(ctx context.Context, URL string) error {
xreflect.WithParserMode(parser.ParseComments),
xreflect.WithRegistry(typeRegistry),
xreflect.WithModule(r.Module, r.rule.ModuleLocation),
xreflect.WithOnField(func(typeName string, field *ast.Field) error {
xreflect.WithOnField(func(typeName string, field *ast.Field, imports xreflect.GoImports) error {
return nil
}), xreflect.WithOnLookup(func(packagePath, pkg, typeName string, rType reflect.Type) {
if pkg == "" {
Expand Down
6 changes: 3 additions & 3 deletions internal/translator/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Service) updateOutputParameters(resource *Resource, rootViewlet *Viewle
}
}

if err = resource.OutputState.EnsureReflectTypes(resource.rule.ModuleLocation, resource.rule.Package()); err != nil {
if err = resource.OutputState.EnsureReflectTypes(resource.rule.ModuleLocation, resource.rule.Package(), resource.typeRegistry); err != nil {
return err
}

Expand Down Expand Up @@ -425,11 +425,11 @@ func (s *Service) adjustTransferCodecType(resource *Resource, parameter *state.P
}

var err error
if adjustedDest, err = adjustedDest.Compact(resource.rule.ModuleLocation); err != nil {
if adjustedDest, err = adjustedDest.Compact(resource.rule.ModuleLocation, resource.typeRegistry); err != nil {
return nil, fmt.Errorf("failed to rewrite transfer type: %v %w", parameter.Name, err)
}
adjustedType, err := adjustedDest.Parameters().ReflectType(resource.rule.ModuleLocation, types.Lookup)
if adjustedDest, err = adjustedDest.Compact(resource.rule.ModuleLocation); err != nil {
if adjustedDest, err = adjustedDest.Compact(resource.rule.ModuleLocation, resource.typeRegistry); err != nil {
return nil, fmt.Errorf("failed to adjust transfer type: %v %w", parameter.Name, err)
}
return adjustedType, nil
Expand Down
Loading

0 comments on commit 2f58bc4

Please sign in to comment.