-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openapi3filter: Fallback to string when decoding request parameters (#…
…631)
- Loading branch information
Showing
5 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package openapi3filter | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/getkin/kin-openapi/openapi3" | ||
"github.com/getkin/kin-openapi/routers/gorillamux" | ||
) | ||
|
||
func TestIssue624(t *testing.T) { | ||
loader := openapi3.NewLoader() | ||
ctx := loader.Context | ||
spec := ` | ||
openapi: 3.0.0 | ||
info: | ||
version: 1.0.0 | ||
title: Sample API | ||
paths: | ||
/items: | ||
get: | ||
description: Returns a list of stuff | ||
parameters: | ||
- description: "test non object" | ||
explode: true | ||
style: form | ||
in: query | ||
name: test | ||
required: false | ||
content: | ||
application/json: | ||
schema: | ||
anyOf: | ||
- type: string | ||
- type: integer | ||
responses: | ||
'200': | ||
description: Successful response | ||
`[1:] | ||
|
||
doc, err := loader.LoadFromData([]byte(spec)) | ||
require.NoError(t, err) | ||
|
||
err = doc.Validate(ctx) | ||
require.NoError(t, err) | ||
|
||
router, err := gorillamux.NewRouter(doc) | ||
require.NoError(t, err) | ||
httpReq, err := http.NewRequest(http.MethodGet, `/items?test=test1`, nil) | ||
require.NoError(t, err) | ||
|
||
route, pathParams, err := router.FindRoute(httpReq) | ||
require.NoError(t, err) | ||
|
||
requestValidationInput := &RequestValidationInput{ | ||
Request: httpReq, | ||
PathParams: pathParams, | ||
Route: route, | ||
} | ||
err = ValidateRequest(ctx, requestValidationInput) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters