From 4f8a85fc090f2094f1df01d716d839e895da97e0 Mon Sep 17 00:00:00 2001 From: erwinvaneyk Date: Fri, 20 Apr 2018 08:45:45 +0200 Subject: [PATCH] Fixed expression resolving for complex data structures --- pkg/controller/expr/expr.go | 35 ++++++++++++++++++++++++---- pkg/controller/invocation/actions.go | 1 - 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/pkg/controller/expr/expr.go b/pkg/controller/expr/expr.go index 51cb0cfa..cc08cfca 100644 --- a/pkg/controller/expr/expr.go +++ b/pkg/controller/expr/expr.go @@ -2,7 +2,6 @@ package expr import ( "errors" - "strings" "time" "github.com/fission/fission-workflows/pkg/types" @@ -61,10 +60,9 @@ func (oe *JavascriptExpressionParser) Resolve(rootScope interface{}, currentTask } }() - // TODO fix and add array // Handle composites - if strings.HasSuffix(expr.Type, "object") { - logrus.WithField("expr", expr).Info("Resolving object...") + if typedvalues.IsType(expr, typedvalues.TypeMap) { + logrus.WithField("expr", expr).Info("Resolving map...") i, err := typedvalues.Format(expr) if err != nil { return nil, err @@ -92,6 +90,35 @@ func (oe *JavascriptExpressionParser) Resolve(rootScope interface{}, currentTask return typedvalues.Parse(result) } + if typedvalues.IsType(expr, typedvalues.TypeList) { + logrus.WithField("expr", expr).Info("Resolving list...") + i, err := typedvalues.Format(expr) + if err != nil { + return nil, err + } + + result := []interface{}{} + obj := i.([]interface{}) + for _, v := range obj { + field, err := typedvalues.Parse(v) + if err != nil { + return nil, err + } + + resolved, err := oe.Resolve(rootScope, currentTask, field) + if err != nil { + return nil, err + } + + actualVal, err := typedvalues.Format(resolved) + if err != nil { + return nil, err + } + result = append(result, actualVal) + } + return typedvalues.Parse(result) + } + if !typedvalues.IsType(expr, typedvalues.TypeExpression) { return expr, nil } diff --git a/pkg/controller/invocation/actions.go b/pkg/controller/invocation/actions.go index e62ea2ae..708a8764 100644 --- a/pkg/controller/invocation/actions.go +++ b/pkg/controller/invocation/actions.go @@ -78,7 +78,6 @@ func (a *ActionInvokeTask) Apply() error { } // ResolveTask the inputs - // TODO make recursive inputs := map[string]*types.TypedValue{} queryScope := expr.NewScope(a.Wf, a.Wfi) for inputKey, val := range a.Task.Inputs {