Skip to content

Commit

Permalink
cannot reproduce #353 (#354)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
  • Loading branch information
fenollp authored Apr 29, 2021
1 parent abfd78f commit 070c628
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions routers/gorillamux/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package gorillamux_test

import (
"context"
"fmt"
"net/http"

"github.com/getkin/kin-openapi/openapi3"
"github.com/getkin/kin-openapi/openapi3filter"
"github.com/getkin/kin-openapi/routers/gorillamux"
)

func Example() {
ctx := context.Background()
loader := &openapi3.Loader{Context: ctx, IsExternalRefsAllowed: true}
doc, err := loader.LoadFromFile("../../openapi3/testdata/pathref.openapi.yml")
if err != nil {
panic(err)
}
if err = doc.Validate(ctx); err != nil {
panic(err)
}
router, err := gorillamux.NewRouter(doc)
if err != nil {
panic(err)
}
httpReq, err := http.NewRequest(http.MethodGet, "/test", nil)
if err != nil {
panic(err)
}

route, pathParams, err := router.FindRoute(httpReq)
if err != nil {
panic(err)
}

requestValidationInput := &openapi3filter.RequestValidationInput{
Request: httpReq,
PathParams: pathParams,
Route: route,
}
if err := openapi3filter.ValidateRequest(ctx, requestValidationInput); err != nil {
panic(err)
}

responseValidationInput := &openapi3filter.ResponseValidationInput{
RequestValidationInput: requestValidationInput,
Status: 200,
Header: http.Header{"Content-Type": []string{"application/json"}},
}
responseValidationInput.SetBodyBytes([]byte(`{}`))

err = openapi3filter.ValidateResponse(ctx, responseValidationInput)
fmt.Println(err)
// Output:
// response body doesn't match the schema: Field must be set to string or not be present
// Schema:
// {
// "type": "string"
// }
//
// Value:
// "object"
}

0 comments on commit 070c628

Please sign in to comment.