Skip to content

Commit 44b5e0c

Browse files
author
Jamie Tanna
committed
sq
1 parent f6d9ee2 commit 44b5e0c

1 file changed

Lines changed: 1 addition & 41 deletions

File tree

oapi_validate_example_test.go

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"errors"
87
"fmt"
98
"io"
109
"net/http"
@@ -704,46 +703,7 @@ paths:
704703
}
705704

706705
switch e := err.(type) {
707-
case *openapi3filter.SecurityRequirementsError:
708-
out := fmt.Sprintf("A SecurityRequirementsError was returned when attempting to authenticate the request to %s %s against %d Security Schemes: %s\n", opts.MatchedRoute.Route.Method, opts.MatchedRoute.Route.Path, len(e.SecurityRequirements), e.Error())
709-
for _, sr := range e.SecurityRequirements {
710-
for k, v := range sr {
711-
out += fmt.Sprintf("- %s: %v\n", k, v)
712-
}
713-
}
714-
715-
fmt.Printf("ErrorHandlerWithOpts: %s\n", out)
716-
717-
http.Error(w, "You're not allowed!", opts.StatusCode)
718-
return
719-
case *openapi3filter.RequestError:
720-
out := fmt.Sprintf("A RequestError was returned when attempting to validate the request to %s %s: %s\n", opts.MatchedRoute.Route.Method, opts.MatchedRoute.Route.Path, e.Error())
721-
722-
if e.RequestBody != nil {
723-
out += "This operation has a request body, which was "
724-
if !e.RequestBody.Required {
725-
out += "not "
726-
}
727-
out += "required\n"
728-
}
729-
730-
if childErr := e.Unwrap(); childErr != nil {
731-
out += "There was a child error, which was "
732-
switch e := childErr.(type) {
733-
case openapi3.MultiError:
734-
out += "a MultiError" + errors.Join(e).Error()
735-
case *openapi3.SchemaError:
736-
out += "a SchemaError, which failed to validate on the " + e.SchemaField + " field"
737-
default:
738-
out += "an unknown type (" + reflect.TypeOf(e).String() + ")"
739-
}
740-
}
741-
742-
fmt.Printf("ErrorHandlerWithOpts: %s\n", out)
743-
744-
http.Error(w, "A bad request was made - but I'm not going to tell you where or how", opts.StatusCode)
745-
return
746-
// NOTE that when it's a MultiError, there's more work needed here
706+
// NOTE that when it's a MultiError, there's more work needed here
747707
case openapi3.MultiError:
748708
for _, eee := range e {
749709
fmt.Printf("eee: %v\n", eee)

0 commit comments

Comments
 (0)