Skip to content

Commit

Permalink
Add support for allowEmptyValue (#515)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Fenoll <pierrefenoll@gmail.com>
  • Loading branch information
Yarn-e and fenollp authored Mar 24, 2022
1 parent b29c7b7 commit a5284e9
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 115 deletions.
105 changes: 105 additions & 0 deletions openapi3filter/fixtures/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,111 @@
]
}
},
"/pets/": {
"get": {
"tags": [
"pet"
],
"summary": "Find pets by the specified filters",
"description": "Returns a list of pets that comply with the specified filters",
"operationId": "findPets",
"parameters": [
{
"name": "status",
"in": "query",
"description": "Status values that need to be considered for filter",
"required": false,
"explode": true,
"allowEmptyValue": true,
"schema": {
"type": "array",
"items": {
"type": "string",
"enum": [
"available",
"pending",
"sold"
],
"default": "available"
}
}
},
{
"name": "tags",
"in": "query",
"description": "Tags to filter by",
"required": false,
"explode": true,
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
{
"name": "kind",
"in": "query",
"description": "Kinds to filter by",
"required": false,
"explode": false,
"style": "pipeDelimited",
"schema": {
"type": "array",
"items": {
"type": "string",
"enum": [
"dog",
"cat",
"turtle",
"bird,with,commas"
]
}
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/xml": {
"schema": {
"type": "array",
"items": {
"allOf": [
{"$ref": "#/components/schemas/Pet"},
{"$ref": "#/components/schemas/PetRequiredProperties"}
]
}
}
},
"application/json": {
"schema": {
"type": "array",
"items": {
"allOf": [
{"$ref": "#/components/schemas/Pet"},
{"$ref": "#/components/schemas/PetRequiredProperties"}
]
}
}
}
}
},
"400": {
"description": "Invalid status value"
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
}
},
"/pet/findByTags": {
"get": {
"tags": [
Expand Down
12 changes: 12 additions & 0 deletions openapi3filter/internal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package openapi3filter

import (
"reflect"
"strings"
)

Expand All @@ -11,3 +12,14 @@ func parseMediaType(contentType string) string {
}
return contentType[:i]
}

func isNilValue(value interface{}) bool {
if value == nil {
return true
}
switch reflect.TypeOf(value).Kind() {
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
return reflect.ValueOf(value).IsNil()
}
return false
}
Loading

0 comments on commit a5284e9

Please sign in to comment.