serverlessworkflow/sdk-go

Content that have auth contains undesired key which causes unmarshal errors

spolti opened this issue · 2 comments

What happened:
When we try to marshal and unmarshal a workflow that have the auth set, it will fail, example:

Error:

panic: authDefinitions value '{"defs":[{"name":"testAuth","scheme":"bearer","properties":{"token":"test_token"}},{"name":"testAuth2","scheme":"basic","properties":{"username":"test_user","password":"test_pwd"}}]}' is not supported, it must be an object or string

What you expected to happen:

How to reproduce it:
Execute this piece of code:

func main() {
	workflow, err := parser.FromJSONSource([]byte(`
{
  "id": "applicantrequest",
  "version": "1.0",
  "name": "Applicant Request Decision Workflow",
  "description": "Determine if applicant request is valid",
  "start": "CheckApplication",
  "specVersion": "0.7",
  "auth": [
    {
      "name": "testAuth",
      "scheme": "bearer",
      "properties": {
        "token": "test_token"
      }
    },
    {
      "name": "testAuth2",
      "scheme": "basic",
      "properties": {
        "username": "test_user",
        "password": "test_pwd"
      }
    }
  ],
  "states": [
    {
	  "name": "Hello State",
	  "type": "inject",
      "data": {
		"result": "Hello World!"
	  },
	  "end": true
    }
  ]
}
`))
	if err != nil {
		panic(err)
	}

	b, err := json.Marshal(workflow)
	if err != nil {
		panic(err)
	}

	workflow = nil
	err = json.Unmarshal(b, &workflow)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%+v", workflow)
}

Anything else we need to know?:

Environment:

  • Specification version used:
  • Go version:

more or less, the reported you gets nil if no auth is defined.

this is because the workflow can't be unmarshalled if there is auth define due the "defs" thing.