Skip to content

Commit 8f9bf0c

Browse files
committed
allow empty auth definitions in parser
fixes #110 Signed-off-by: spolti <[email protected]>
1 parent 85c2f4d commit 8f9bf0c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

model/auth.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
"fmt"
2020
"reflect"
2121

22-
validator "github.com/go-playground/validator/v10"
22+
"github.com/go-playground/validator/v10"
23+
2324
val "github.com/serverlessworkflow/sdk-go/v2/validator"
2425
)
2526

@@ -43,7 +44,7 @@ func AuthDefinitionsStructLevelValidation(structLevel validator.StructLevel) {
4344

4445
// AuthDefinitions used to define authentication information applied to resources defined in the operation property of function definitions
4546
type AuthDefinitions struct {
46-
Defs []Auth
47+
Defs []Auth `json:"defs,omitempty"`
4748
}
4849

4950
// AuthType ...
@@ -105,9 +106,12 @@ func (a *AuthDefinitions) UnmarshalJSON(b []byte) error {
105106
return a.unmarshalFile(b)
106107
case '[':
107108
return a.unmarshalMany(b)
109+
case '{': // single values are not supported, should we support it?
110+
return fmt.Errorf("authDefinitions value '%s' is not supported, it must be an object or string", string(b))
111+
default:
112+
// nil can be returned as both cases are returning errors in case of unmarshal problem.
113+
return nil
108114
}
109-
110-
return fmt.Errorf("auth value '%s' is not supported, it must be an array or string", string(b))
111115
}
112116

113117
func (a *AuthDefinitions) unmarshalFile(data []byte) error {

model/auth_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ func TestAuthDefinitionsStructLevelValidation(t *testing.T) {
3131
}
3232
testCases := []testCase{
3333
{
34-
desp: "nil defs",
35-
authDefs: AuthDefinitions{
36-
Defs: nil,
37-
},
38-
err: ``,
34+
desp: "nil defs",
35+
authDefs: AuthDefinitions{},
36+
err: ``,
3937
},
4038
{
4139
desp: "zero length defs",

model/workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type BaseWorkflow struct {
108108
// Auth definitions can be used to define authentication information that should be applied to resources defined in the operation
109109
// property of function definitions. It is not used as authentication information for the function invocation,
110110
// but just to access the resource containing the function invocation information.
111-
Auth AuthDefinitions `json:"auth,omitempty"`
111+
Auth *AuthDefinitions `json:"auth,omitempty"`
112112
}
113113

114114
// Workflow base definition

0 commit comments

Comments
 (0)