Skip to content

Commit a5284e9

Browse files
Yarn-efenollp
andauthored
Add support for allowEmptyValue (#515)
Co-authored-by: Pierre Fenoll <[email protected]>
1 parent b29c7b7 commit a5284e9

File tree

7 files changed

+453
-115
lines changed

7 files changed

+453
-115
lines changed

openapi3filter/fixtures/petstore.json

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,111 @@
211211
]
212212
}
213213
},
214+
"/pets/": {
215+
"get": {
216+
"tags": [
217+
"pet"
218+
],
219+
"summary": "Find pets by the specified filters",
220+
"description": "Returns a list of pets that comply with the specified filters",
221+
"operationId": "findPets",
222+
"parameters": [
223+
{
224+
"name": "status",
225+
"in": "query",
226+
"description": "Status values that need to be considered for filter",
227+
"required": false,
228+
"explode": true,
229+
"allowEmptyValue": true,
230+
"schema": {
231+
"type": "array",
232+
"items": {
233+
"type": "string",
234+
"enum": [
235+
"available",
236+
"pending",
237+
"sold"
238+
],
239+
"default": "available"
240+
}
241+
}
242+
},
243+
{
244+
"name": "tags",
245+
"in": "query",
246+
"description": "Tags to filter by",
247+
"required": false,
248+
"explode": true,
249+
"schema": {
250+
"type": "array",
251+
"items": {
252+
"type": "string"
253+
}
254+
}
255+
},
256+
{
257+
"name": "kind",
258+
"in": "query",
259+
"description": "Kinds to filter by",
260+
"required": false,
261+
"explode": false,
262+
"style": "pipeDelimited",
263+
"schema": {
264+
"type": "array",
265+
"items": {
266+
"type": "string",
267+
"enum": [
268+
"dog",
269+
"cat",
270+
"turtle",
271+
"bird,with,commas"
272+
]
273+
}
274+
}
275+
}
276+
],
277+
"responses": {
278+
"200": {
279+
"description": "successful operation",
280+
"content": {
281+
"application/xml": {
282+
"schema": {
283+
"type": "array",
284+
"items": {
285+
"allOf": [
286+
{"$ref": "#/components/schemas/Pet"},
287+
{"$ref": "#/components/schemas/PetRequiredProperties"}
288+
]
289+
}
290+
}
291+
},
292+
"application/json": {
293+
"schema": {
294+
"type": "array",
295+
"items": {
296+
"allOf": [
297+
{"$ref": "#/components/schemas/Pet"},
298+
{"$ref": "#/components/schemas/PetRequiredProperties"}
299+
]
300+
}
301+
}
302+
}
303+
}
304+
},
305+
"400": {
306+
"description": "Invalid status value"
307+
}
308+
},
309+
"security": [
310+
{
311+
"petstore_auth": [
312+
"write:pets",
313+
"read:pets"
314+
]
315+
}
316+
]
317+
}
318+
},
214319
"/pet/findByTags": {
215320
"get": {
216321
"tags": [

openapi3filter/internal.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package openapi3filter
22

33
import (
4+
"reflect"
45
"strings"
56
)
67

@@ -11,3 +12,14 @@ func parseMediaType(contentType string) string {
1112
}
1213
return contentType[:i]
1314
}
15+
16+
func isNilValue(value interface{}) bool {
17+
if value == nil {
18+
return true
19+
}
20+
switch reflect.TypeOf(value).Kind() {
21+
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
22+
return reflect.ValueOf(value).IsNil()
23+
}
24+
return false
25+
}

0 commit comments

Comments
 (0)