sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

Content that have auth contains undesired key which causes unmarshal errors

Open spolti opened this issue 2 years ago • 1 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:

spolti avatar Oct 26 '22 16:10 spolti

Is this same as https://github.com/serverlessworkflow/sdk-go/issues/110?

lsytj0413 avatar Oct 27 '22 01:10 lsytj0413

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.

spolti avatar Oct 27 '22 13:10 spolti