Skip to content

Commit ba3a1a9

Browse files
committed
refactor code
1 parent 2c2828d commit ba3a1a9

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

openapi3filter/issue991_test.go

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,12 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12-
func TestValidateRequestDefault(t *testing.T) {
13-
const specExplodeFalse = `
14-
openapi: 3.0.0
15-
info:
16-
title: 'Validator'
17-
version: 0.0.1
18-
paths:
19-
/category:
20-
get:
21-
parameters:
22-
- $ref: "#/components/parameters/Type"
23-
responses:
24-
'200':
25-
description: Ok
26-
components:
27-
parameters:
28-
Type:
29-
in: query
30-
name: type
31-
required: false
32-
description: Type parameter
33-
schema:
34-
type: array
35-
default:
36-
- A
37-
- B
38-
- C
39-
items:
40-
type: string
41-
enum:
42-
- A
43-
- B
44-
- C
45-
`
46-
47-
const specExplodeTrue = `
12+
func generateSpec(explode bool) string {
13+
explodeStr := "false"
14+
if explode {
15+
explodeStr = "true"
16+
}
17+
return `
4818
openapi: 3.0.0
4919
info:
5020
title: 'Validator'
@@ -63,7 +33,7 @@ components:
6333
in: query
6434
name: type
6535
required: false
66-
explode: true
36+
explode: ` + explodeStr + `
6737
description: Type parameter
6838
schema:
6939
type: array
@@ -78,7 +48,9 @@ components:
7848
- B
7949
- C
8050
`
51+
}
8152

53+
func TestValidateRequestDefault(t *testing.T) {
8254
type args struct {
8355
url string
8456
expected []string
@@ -98,7 +70,7 @@ components:
9870
},
9971
expectedModification: false,
10072
expectedErr: nil,
101-
spec: specExplodeFalse,
73+
spec: generateSpec(false),
10274
},
10375
{
10476
name: "Valid request with 1 type parameters set and explode is false",
@@ -108,7 +80,7 @@ components:
10880
},
10981
expectedModification: false,
11082
expectedErr: nil,
111-
spec: specExplodeFalse,
83+
spec: generateSpec(false),
11284
},
11385
{
11486
name: "Valid request with 2 type parameters set and explode is false",
@@ -118,7 +90,7 @@ components:
11890
},
11991
expectedModification: false,
12092
expectedErr: nil,
121-
spec: specExplodeFalse,
93+
spec: generateSpec(false),
12294
},
12395
{
12496
name: "Valid request with 1 type parameters set out of enum and explode is false",
@@ -128,7 +100,7 @@ components:
128100
},
129101
expectedModification: false,
130102
expectedErr: &RequestError{},
131-
spec: specExplodeFalse,
103+
spec: generateSpec(false),
132104
},
133105
{
134106
name: "Valid request without type parameters set and explode is true",
@@ -138,7 +110,7 @@ components:
138110
},
139111
expectedModification: false,
140112
expectedErr: nil,
141-
spec: specExplodeTrue,
113+
spec: generateSpec(true),
142114
},
143115
}
144116
for _, tc := range tests {

0 commit comments

Comments
 (0)