@@ -9,42 +9,12 @@ import (
9
9
"github.com/stretchr/testify/require"
10
10
)
11
11
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 `
48
18
openapi: 3.0.0
49
19
info:
50
20
title: 'Validator'
@@ -63,7 +33,7 @@ components:
63
33
in: query
64
34
name: type
65
35
required: false
66
- explode: true
36
+ explode: ` + explodeStr + `
67
37
description: Type parameter
68
38
schema:
69
39
type: array
@@ -78,7 +48,9 @@ components:
78
48
- B
79
49
- C
80
50
`
51
+ }
81
52
53
+ func TestValidateRequestDefault (t * testing.T ) {
82
54
type args struct {
83
55
url string
84
56
expected []string
@@ -98,7 +70,7 @@ components:
98
70
},
99
71
expectedModification : false ,
100
72
expectedErr : nil ,
101
- spec : specExplodeFalse ,
73
+ spec : generateSpec ( false ) ,
102
74
},
103
75
{
104
76
name : "Valid request with 1 type parameters set and explode is false" ,
@@ -108,7 +80,7 @@ components:
108
80
},
109
81
expectedModification : false ,
110
82
expectedErr : nil ,
111
- spec : specExplodeFalse ,
83
+ spec : generateSpec ( false ) ,
112
84
},
113
85
{
114
86
name : "Valid request with 2 type parameters set and explode is false" ,
@@ -118,7 +90,7 @@ components:
118
90
},
119
91
expectedModification : false ,
120
92
expectedErr : nil ,
121
- spec : specExplodeFalse ,
93
+ spec : generateSpec ( false ) ,
122
94
},
123
95
{
124
96
name : "Valid request with 1 type parameters set out of enum and explode is false" ,
@@ -128,7 +100,7 @@ components:
128
100
},
129
101
expectedModification : false ,
130
102
expectedErr : & RequestError {},
131
- spec : specExplodeFalse ,
103
+ spec : generateSpec ( false ) ,
132
104
},
133
105
{
134
106
name : "Valid request without type parameters set and explode is true" ,
@@ -138,7 +110,7 @@ components:
138
110
},
139
111
expectedModification : false ,
140
112
expectedErr : nil ,
141
- spec : specExplodeTrue ,
113
+ spec : generateSpec ( true ) ,
142
114
},
143
115
}
144
116
for _ , tc := range tests {
0 commit comments