Skip to content

Commit

Permalink
fix: fix InstillFormat validate function (#745)
Browse files Browse the repository at this point in the history
Because

- The InstillFormat validator wasn't generating the correct
InstillFormat for array items.

This commit

- Fixes the InstillFormat validation function.
  • Loading branch information
donch1989 authored Oct 16, 2024
1 parent bf1e091 commit b2e0705
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/component/base/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func CompileInstillAcceptFormats(sch *structpb.Struct) error {
itemInstillAcceptFormats := []interface{}{}
for _, item := range v.GetListValue().AsSlice() {
if strings.HasPrefix(item.(string), "array:") {
itemInstillAcceptFormats = append(itemInstillAcceptFormats, strings.Split(item.(string), ":")[1])
_, itemInstillAcceptFormat, _ := strings.Cut(item.(string), ":")
itemInstillAcceptFormats = append(itemInstillAcceptFormats, itemInstillAcceptFormat)
}
}
if len(itemInstillAcceptFormats) > 0 {
Expand Down Expand Up @@ -201,7 +202,7 @@ func CompileInstillFormat(sch *structpb.Struct) error {
}
if k == "instillFormat" {
if strings.HasPrefix(v.GetStringValue(), "array:") {
itemInstillFormat := strings.Split(v.GetStringValue(), ":")[1]
_, itemInstillFormat, _ := strings.Cut(v.GetStringValue(), ":")
sch.Fields["items"] = structpb.NewStructValue(&structpb.Struct{Fields: make(map[string]*structpb.Value)})
sch.Fields["items"].GetStructValue().Fields["instillFormat"], err = structpb.NewValue(itemInstillFormat)
if err != nil {
Expand Down

0 comments on commit b2e0705

Please sign in to comment.