Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use validator.ValidateHttpResponse #41

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/golang/mock v1.6.0
github.com/minio/pkg v1.7.5
github.com/pb33f/libopenapi v0.15.14
github.com/pb33f/libopenapi-validator v0.0.42
github.com/pb33f/libopenapi-validator v0.0.44
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/pb33f/libopenapi v0.15.14 h1:A0fn45jbthDyFGXfu5bYIZVsWyPI6hJYm3wG143MT8o=
github.com/pb33f/libopenapi v0.15.14/go.mod h1:PEXNwvtT4KNdjrwudp5OYnD1ryqK6uJ68aMNyWvoMuc=
github.com/pb33f/libopenapi-validator v0.0.42 h1:bfwPWlxUFHtvPNi0PH+EVpQBU2kA3Db9rVdFkfmUVac=
github.com/pb33f/libopenapi-validator v0.0.42/go.mod h1:kU1JYyXIRlpmsWx3NkL+drNNttLADMgdaNzJgXDhec0=
github.com/pb33f/libopenapi-validator v0.0.44 h1:z7SVS6mMVv/f4V73e9H1UCiWrMzMg2ubE6d/0FACfq8=
github.com/pb33f/libopenapi-validator v0.0.44/go.mod h1:kU1JYyXIRlpmsWx3NkL+drNNttLADMgdaNzJgXDhec0=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
4 changes: 2 additions & 2 deletions httpstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,13 @@ func (m *matcher) ResponseExample(opts ...responseExampleOption) {
}
}
doc := *m.router.openAPI3Doc
v3, errs := doc.BuildV3Model()
v3m, errs := doc.BuildV3Model()
if errs != nil {
m.router.t.Errorf("failed to build OpenAPI v3 model: %v", errors.Join(errs...))
return
}
fn := func(w http.ResponseWriter, r *http.Request) {
pathItem, errs, pathValue := paths.FindPath(r, &v3.Model)
pathItem, errs, pathValue := paths.FindPath(r, &v3m.Model)
if pathItem == nil || errs != nil {
var err error
for _, e := range errs {
Expand Down
12 changes: 2 additions & 10 deletions openapi3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"io"
"net/http"

rvalidator "github.com/pb33f/libopenapi-validator/responses"
)

var _ http.ResponseWriter = (*recorder)(nil)
Expand Down Expand Up @@ -56,16 +54,10 @@ func (rt *Router) setOpenApi3Vaildator() error {
if rt.openAPI3Doc == nil {
return nil
}
doc := *rt.openAPI3Doc
v3, errs := doc.BuildV3Model()
if len(errs) > 0 {
return errors.Join(errs...)
}
rv := rvalidator.NewResponseBodyValidator(&v3.Model)
mw := func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
v := *rt.openAPI3Validator
if !rt.skipValidateRequest {
v := *rt.openAPI3Validator
_, errs := v.ValidateHttpRequest(r)
if len(errs) > 0 {
var err error
Expand All @@ -79,7 +71,7 @@ func (rt *Router) setOpenApi3Vaildator() error {
next.ServeHTTP(rec, r)

if !rt.skipValidateResponse {
_, errs := rv.ValidateResponseBody(r, rec.toResponse())
_, errs := v.ValidateHttpResponse(r, rec.toResponse())
if len(errs) > 0 {
var err error
for _, e := range errs {
Expand Down
Loading