Skip to content

Commit 0ec04ff

Browse files
authored
fix(*): update auth type to array or string (#71)
Signed-off-by: lsytj0413 <511121939@qq.com> Signed-off-by: lsytj0413 <511121939@qq.com>
1 parent 073c322 commit 0ec04ff

File tree

5 files changed

+192
-10
lines changed

5 files changed

+192
-10
lines changed

model/auth.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,25 @@ func (a *AuthDefinitions) UnmarshalJSON(b []byte) error {
9292
if len(b) == 0 {
9393
return fmt.Errorf("no bytes to unmarshal")
9494
}
95+
9596
// See if we can guess based on the first character
9697
switch b[0] {
97-
case '{':
98-
return a.unmarshalSingle(b)
98+
case '"':
99+
return a.unmarshalFile(b)
99100
case '[':
100101
return a.unmarshalMany(b)
101102
}
102-
return nil
103+
104+
return fmt.Errorf("auth value '%s' not support, it must be an array or string", string(b))
103105
}
104106

105-
func (a *AuthDefinitions) unmarshalSingle(data []byte) error {
106-
var auth Auth
107-
err := json.Unmarshal(data, &auth)
107+
func (a *AuthDefinitions) unmarshalFile(data []byte) error {
108+
b, err := unmarshalFile(data)
108109
if err != nil {
109110
return err
110111
}
111-
a.Defs = []Auth{auth}
112-
return nil
112+
113+
return a.unmarshalMany(b)
113114
}
114115

115116
func (a *AuthDefinitions) unmarshalMany(data []byte) error {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"id": "applicantrequest",
3+
"version": "1.0",
4+
"name": "Applicant Request Decision Workflow",
5+
"description": "Determine if applicant request is valid",
6+
"start": "CheckApplication",
7+
"specVersion": "0.7",
8+
"auth": "./testdata/workflows/urifiles/auth.json",
9+
"functions": [
10+
{
11+
"name": "sendRejectionEmailFunction",
12+
"operation": "http://myapis.org/applicationapi.json#emailRejection"
13+
}
14+
],
15+
"retries": [
16+
{
17+
"name": "TimeoutRetryStrategy",
18+
"delay": "PT1M",
19+
"maxAttempts": "5"
20+
}
21+
],
22+
"states": [
23+
{
24+
"name": "CheckApplication",
25+
"type": "switch",
26+
"dataConditions": [
27+
{
28+
"condition": "{{ $.applicants[?(@.age >= 18)] }}",
29+
"transition": {
30+
"nextState": "StartApplication"
31+
}
32+
},
33+
{
34+
"condition": "{{ $.applicants[?(@.age < 18)] }}",
35+
"transition": {
36+
"nextState": "RejectApplication"
37+
}
38+
}
39+
],
40+
"default": {
41+
"transition": {
42+
"nextState": "RejectApplication"
43+
}
44+
}
45+
},
46+
{
47+
"name": "StartApplication",
48+
"type": "operation",
49+
"actions": [
50+
{
51+
"subFlowRef": {
52+
"workflowId": "startApplicationWorkflowId"
53+
}
54+
}
55+
],
56+
"end": {
57+
"terminate": true
58+
}
59+
},
60+
{
61+
"name": "RejectApplication",
62+
"type": "operation",
63+
"actionMode": "sequential",
64+
"actions": [
65+
{
66+
"functionRef": {
67+
"refName": "sendRejectionEmailFunction",
68+
"parameters": {
69+
"applicant": "{{ $.applicant }}"
70+
}
71+
}
72+
}
73+
],
74+
"end": {
75+
"terminate": true
76+
}
77+
}
78+
]
79+
}

parser/testdata/workflows/applicationrequest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"description": "Determine if applicant request is valid",
66
"start": "CheckApplication",
77
"specVersion": "0.7",
8-
"auth": {
8+
"auth": [{
99
"name": "testAuth",
1010
"scheme": "bearer",
1111
"properties": {
1212
"token": "test_token"
1313
}
14-
},
14+
}],
1515
"functions": [
1616
{
1717
"name": "sendRejectionEmailFunction",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"name": "testAuth",
4+
"scheme": "bearer",
5+
"properties": {
6+
"token": "test_token"
7+
}
8+
},
9+
{
10+
"name": "testAuth2",
11+
"scheme": "basic",
12+
"properties": {
13+
"username": "test_user",
14+
"password": "test_pwd"
15+
}
16+
}
17+
]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"id": "applicantrequest",
3+
"version": "1.0",
4+
"name": "Applicant Request Decision Workflow",
5+
"description": "Determine if applicant request is valid",
6+
"start": "CheckApplication",
7+
"specVersion": "0.7",
8+
"auth": {
9+
"name": "testAuth",
10+
"scheme": "bearer",
11+
"properties": {
12+
"token": "test_token"
13+
}
14+
},
15+
"functions": [
16+
{
17+
"name": "sendRejectionEmailFunction",
18+
"operation": "http://myapis.org/applicationapi.json#emailRejection"
19+
}
20+
],
21+
"retries": [
22+
{
23+
"name": "TimeoutRetryStrategy",
24+
"delay": "PT1M",
25+
"maxAttempts": "5"
26+
}
27+
],
28+
"states": [
29+
{
30+
"name": "CheckApplication",
31+
"type": "switch",
32+
"dataConditions": [
33+
{
34+
"condition": "{{ $.applicants[?(@.age >= 18)] }}",
35+
"transition": {
36+
"nextState": "StartApplication"
37+
}
38+
},
39+
{
40+
"condition": "{{ $.applicants[?(@.age < 18)] }}",
41+
"transition": {
42+
"nextState": "RejectApplication"
43+
}
44+
}
45+
],
46+
"default": {
47+
"transition": {
48+
"nextState": "RejectApplication"
49+
}
50+
}
51+
},
52+
{
53+
"name": "StartApplication",
54+
"type": "operation",
55+
"actions": [
56+
{
57+
"subFlowRef": {
58+
"workflowId": "startApplicationWorkflowId"
59+
}
60+
}
61+
],
62+
"end": {
63+
"terminate": true
64+
}
65+
},
66+
{
67+
"name": "RejectApplication",
68+
"type": "operation",
69+
"actionMode": "sequential",
70+
"actions": [
71+
{
72+
"functionRef": {
73+
"refName": "sendRejectionEmailFunction",
74+
"parameters": {
75+
"applicant": "{{ $.applicant }}"
76+
}
77+
}
78+
}
79+
],
80+
"end": {
81+
"terminate": true
82+
}
83+
}
84+
]
85+
}

0 commit comments

Comments
 (0)