Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Fixes generation without recasting component
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Rathke <lrathke@vmware.com>
  • Loading branch information
liamrathke committed Jun 29, 2021
1 parent efb5722 commit c052d92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 9 additions & 1 deletion pkg/view/tsgen/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ func (c *Converter) visit(w *gostrings.Builder, t reflect.Type, depth int) ([]st
}
componentNames = append(componentNames, names...)
case reflect.Map:
var keyString string = t.Key().String()
switch keyString {
// typing for validation steps causes errors with reflection, so we just lock string keys.
case "component.FormValidator":
keyString = "string"
}

// if a map is found, key the key and element to build a typescript object definition.
w.WriteString("{[key:" + t.Key().String() + "]:")
w.WriteString("{[key:" + keyString + "]:")

names, err := c.visit(w, t.Elem(), depth+1)
if err != nil {
return nil, err
Expand Down
10 changes: 6 additions & 4 deletions pkg/view/tsgen/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ func (c Component) Referenced() []ImportReference {

var refs []ImportReference
for _, r := range list {
refs = append(refs, ImportReference{
Name: r,
ImportName: strcase.KebabCase(r),
})
if c.Name != r { // Prevent nested/recursive component imports
refs = append(refs, ImportReference{
Name: r,
ImportName: strcase.KebabCase(r),
})
}
}

return refs
Expand Down
2 changes: 1 addition & 1 deletion pkg/view/tsgen/tsgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (tg *TSGen) Reflect(names []string) (*Model, error) {

m := &Model{}
if err := gob.NewDecoder(&stdout).Decode(m); err != nil {
return nil, fmt.Errorf("decode reflet model: %w", err)
return nil, fmt.Errorf("decode reflect model: %w", err)
}

return m, nil
Expand Down

0 comments on commit c052d92

Please sign in to comment.