|
7 | 7 | "reflect" |
8 | 8 | "runtime/debug" |
9 | 9 |
|
| 10 | + "embed" |
| 11 | + |
10 | 12 | "github.com/viant/datly/utils/types" |
11 | 13 | "github.com/viant/datly/view/state" |
12 | 14 | "github.com/viant/datly/view/state/kind/locator" |
@@ -55,12 +57,33 @@ func (s *Session) Bind(ctx context.Context, dest interface{}, opts ...hstate.Opt |
55 | 57 | destType := reflect.TypeOf(dest) |
56 | 58 | sType := types.EnsureStruct(destType) |
57 | 59 | stateType, ok := s.Types.Lookup(sType) |
58 | | - if !ok { |
59 | | - if stateType, err = state.NewType( |
60 | | - state.WithSchema(state.NewSchema(destType)), |
61 | | - state.WithResource(s.resource), |
62 | | - ); err != nil { |
63 | | - return err |
| 60 | + |
| 61 | + var embedFs *embed.FS |
| 62 | + if embedder, ok := dest.(state.Embedder); ok { |
| 63 | + embedFs = embedder.EmbedFS() |
| 64 | + } |
| 65 | + |
| 66 | + if !ok && s.component != nil { |
| 67 | + |
| 68 | + if s.component.Input.Type.Type() != nil { |
| 69 | + if destType == s.component.Input.Type.Type().Type() { |
| 70 | + stateType = &s.component.Input.Type |
| 71 | + } |
| 72 | + } |
| 73 | + if s.component.Output.Type.Type() != nil { |
| 74 | + if destType == s.component.Output.Type.Type().Type() { |
| 75 | + stateType = &s.component.Output.Type |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + if stateType == nil { |
| 80 | + if stateType, err = state.NewType( |
| 81 | + state.WithSchema(state.NewSchema(destType)), |
| 82 | + state.WithResource(s.resource), |
| 83 | + state.WithFS(embedFs), |
| 84 | + ); err != nil { |
| 85 | + return err |
| 86 | + } |
64 | 87 | } |
65 | 88 | s.Types.Put(stateType) |
66 | 89 | } |
|
0 commit comments