You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: oapi_validate_example_test.go
+25-12Lines changed: 25 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,6 @@ import (
9
9
"net/http"
10
10
"net/http/httptest"
11
11
"reflect"
12
-
"strings"
13
12
14
13
"github.com/getkin/kin-openapi/openapi3"
15
14
"github.com/getkin/kin-openapi/openapi3filter"
@@ -357,6 +356,10 @@ paths:
357
356
id:
358
357
type: string
359
358
minLength: 100
359
+
name:
360
+
type: string
361
+
enum:
362
+
- Marcin
360
363
additionalProperties: false
361
364
/protected_resource:
362
365
get:
@@ -468,10 +471,6 @@ components:
468
471
case*openapi3filter.RequestError:
469
472
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())
470
473
471
-
fmt.Printf("e: %#v\n", e)
472
-
// fmt.Printf("ErrorHandlerWithOpts: An HTTP %d was returned by the middleware with error message: request body has an error: value is required but missing TODO TODO TODO\n", opts.StatusCode)
473
-
// http.Error(w, e.Error(), opts.StatusCode)
474
-
475
474
ife.RequestBody!=nil {
476
475
out+="This operation has a request body, which was "
477
476
if!e.RequestBody.Required {
@@ -480,6 +479,9 @@ components:
480
479
out+="required\n"
481
480
}
482
481
482
+
fmt.Printf("e: %#v\n", e)
483
+
fmt.Printf("e.Err: %#v\n", e.Err)
484
+
483
485
ifchildErr:=e.Unwrap(); childErr!=nil {
484
486
out+="There was a child error, which was "
485
487
switche:=childErr.(type) {
@@ -492,7 +494,7 @@ components:
492
494
493
495
fmt.Printf("ErrorHandlerWithOpts: %s\n", out)
494
496
495
-
http.Error(w, "TODO TODO TODO", opts.StatusCode)
497
+
http.Error(w, "A bad request was made - but I'm not going to tell you where or how", opts.StatusCode)
fmt.Println("# A request that is malformed is rejected with HTTP 400 Bad Request (with an invalid request body), and is then logged by the ErrorHandlerWithOpts")
// # A request that is malformed is rejected with HTTP 400 Bad Request (with no request body), and is then logged by the ErrorHandlerWithOpts
573
-
// ErrorHandlerWithOpts: An HTTP 400 was returned by the middleware with error message: request body has an error: value is required but missing TODO TODO TODO
583
+
// ErrorHandlerWithOpts: A RequestError was returned when attempting to validate the request to POST /resource: request body has an error: value is required but missing
584
+
// This operation has a request body, which was required
585
+
// There was a child error, which was an unknown type (*errors.errorString)
574
586
// Received an HTTP 400 response. Expected HTTP 400
575
-
// Response body: This was rewritten by the ErrorHandlerWithOpts TODO
587
+
// Response body: A bad request was made - but I'm not going to tell you where or how
576
588
//
577
589
// # A request that is malformed is rejected with HTTP 400 Bad Request (with an invalid request body), and is then logged by the ErrorHandlerWithOpts
578
590
// ErrorHandlerWithOpts: A RequestError was returned when attempting to validate the request to POST /resource: request body has an error: doesn't match schema: Error at "/id": minimum string length is 100
@@ -585,12 +597,13 @@ components:
585
597
// Value:
586
598
// "not-long-enough"
587
599
//
588
-
//
600
+
// This operation has a request body, which was required
601
+
// There was a child error, which was a SchemaError, which failed to validate on the minLength field
589
602
// Received an HTTP 400 response. Expected HTTP 400
590
-
// Response body: This was rewritten by the ErrorHandlerWithOpts TODO
603
+
// Response body: A bad request was made - but I'm not going to tell you where or how
591
604
//
592
605
// # A request that to an unknown path is rejected with HTTP 404 Not Found, and is then logged by the ErrorHandlerWithOpts
593
-
// ErrorHandlerWithOpts: An HTTP 400 was returned by the middleware with error message: no matching operation was found
606
+
// ErrorHandlerWithOpts: An HTTP 404 was returned by the middleware with error message: no matching operation was found
594
607
// Received an HTTP 404 response. Expected HTTP 404
595
608
// Response body: No route was found (according to ErrorHandlerWithOpts), and we changed the HTTP status code to 404
0 commit comments