serverlessworkflow / sdk-go

Go SDK for Serverless Workflow
http://serverlessworkflow.io
Apache License 2.0
90 stars 35 forks source link

Action-FuncRef-Invoke is not unmarshaling into InvokeType #179

Closed ilewin closed 1 year ago

ilewin commented 1 year ago

Although Action.FunctionRef.Invoke field is set in the JSON while unmarshaling into a struct the field is not set. Seems due to the fact that its of InvokeType.

Expect to unmarshal correclty

set invoke in FuncRef Action and try to unmarshal into a struct


func (f *FunctionRef) UnmarshalJSON(data []byte) error {
    funcRef := make(map[string]interface{})
    if err := json.Unmarshal(data, &funcRef); err != nil {
        f.RefName, err = unmarshalString(data)
        if err != nil {
            return err
        }
        return nil
    }

    f.RefName = requiresNotNilOrEmpty(funcRef["refName"])
    if _, found := funcRef["arguments"]; found {
        f.Arguments = funcRef["arguments"].(map[string]interface{})
    }
    f.SelectionSet = requiresNotNilOrEmpty(funcRef["selectionSet"])

    // Missing part ?
       if _, found := funcRef["invoke"]; found {
        if invoke, ok := funcRef["invoke"].(string); ok {
            f.Invoke = InvokeType(invoke)
        }
    }
       // End of  Missing part
    return nil
}
ricardozanini commented 1 year ago

@ilewin thanks for reporting it. Can you open a PR to fix it? I think it's rather simple.

spolti commented 1 year ago

Seems that it is fixed already, added a small check to make sure it is unmarshalled: https://github.com/serverlessworkflow/sdk-go/pull/184

ricardozanini commented 1 year ago

Seems that it is fixed already, added a small check to make sure it is unmarshalled: #184

Approved!