Skip to content

Commit 4cd164c

Browse files
author
Jamie Tanna
committed
sq
1 parent 63e1a91 commit 4cd164c

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

oapi_validate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func validateRequest(r *http.Request, router routers.Router, options *Options) (
9090
if errors.Is(err, routers.ErrMethodNotAllowed) {
9191
return http.StatusMethodNotAllowed, err
9292
}
93+
9394
return http.StatusNotFound, err // We failed to find a matching route for the request.
9495
}
9596

oapi_validate_example_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ components:
163163
logResponseBody(rr)
164164
fmt.Println()
165165

166+
// ================================================================================
167+
fmt.Println("# A request with an invalid HTTP method, to a valid path, is rejected with an HTTP 405 Method Not Allowed")
168+
body = map[string]string{
169+
"invalid": "not expected",
170+
}
171+
172+
data, err = json.Marshal(body)
173+
must(err)
174+
175+
req, err = http.NewRequest(http.MethodPatch, "/resource", bytes.NewReader(data))
176+
must(err)
177+
req.Header.Set("Content-Type", "application/json")
178+
179+
rr = httptest.NewRecorder()
180+
181+
server.ServeHTTP(rr, req)
182+
183+
fmt.Printf("Received an HTTP %d response. Expected HTTP 405\n", rr.Code)
184+
logResponseBody(rr)
185+
fmt.Println()
186+
166187
// ================================================================================
167188
fmt.Println("# A request that is well-formed is passed through to the Handler")
168189
body = map[string]string{
@@ -207,6 +228,10 @@ components:
207228
// Received an HTTP 400 response. Expected HTTP 400
208229
// Response body: request body has an error: doesn't match schema: property "invalid" is unsupported
209230
//
231+
// # A request with an invalid HTTP method, to a valid path, is rejected with an HTTP 405 Method Not Allowed
232+
// Received an HTTP 405 response. Expected HTTP 405
233+
// Response body: method not allowed
234+
//
210235
// # A request that is well-formed is passed through to the Handler
211236
// POST /resource was called
212237
// Received an HTTP 204 response. Expected HTTP 204

0 commit comments

Comments
 (0)