Skip to content

Commit 53e6c3b

Browse files
authored
Stop depend on the github.com/getkin/kin-openapi/routers/legacy (#383)
* Stop depend on the github.com/getkin/kin-openapi/routers/legacy * Fix tests for 031723a
1 parent 77cf27d commit 53e6c3b

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

oapi_validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/getkin/kin-openapi/openapi3"
2525
"github.com/getkin/kin-openapi/openapi3filter"
2626
"github.com/getkin/kin-openapi/routers"
27-
"github.com/getkin/kin-openapi/routers/legacy"
27+
"github.com/getkin/kin-openapi/routers/gorillamux"
2828
"github.com/labstack/echo/v4"
2929
echomiddleware "github.com/labstack/echo/v4/middleware"
3030
)
@@ -67,7 +67,7 @@ type Options struct {
6767

6868
// Create a validator from a swagger object, with validation options
6969
func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) echo.MiddlewareFunc {
70-
router, err := legacy.NewRouter(swagger)
70+
router, err := gorillamux.NewRouter(swagger)
7171
if err != nil {
7272
panic(err)
7373
}

oapi_validate_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"errors"
2020
"net/http"
2121
"net/http/httptest"
22+
"net/url"
2223
"testing"
2324

2425
"github.com/deepmap/oapi-codegen/pkg/testutil"
@@ -35,7 +36,7 @@ info:
3536
version: 1.0.0
3637
title: TestServer
3738
servers:
38-
- url: http://deepmap.ai
39+
- url: http://deepmap.ai/
3940
paths:
4041
/resource:
4142
get:
@@ -106,13 +107,23 @@ components:
106107
bearerFormat: JWT
107108
`
108109

109-
func doGet(t *testing.T, e *echo.Echo, url string) *httptest.ResponseRecorder {
110-
response := testutil.NewRequest().Get(url).WithAcceptJson().Go(t, e)
110+
func doGet(t *testing.T, e *echo.Echo, rawURL string) *httptest.ResponseRecorder {
111+
u, err := url.Parse(rawURL)
112+
if err != nil {
113+
t.Fatalf("Invalid url: %s", rawURL)
114+
}
115+
116+
response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, e)
111117
return response.Recorder
112118
}
113119

114-
func doPost(t *testing.T, e *echo.Echo, url string, jsonBody interface{}) *httptest.ResponseRecorder {
115-
response := testutil.NewRequest().Post(url).WithJsonBody(jsonBody).Go(t, e)
120+
func doPost(t *testing.T, e *echo.Echo, rawURL string, jsonBody interface{}) *httptest.ResponseRecorder {
121+
u, err := url.Parse(rawURL)
122+
if err != nil {
123+
t.Fatalf("Invalid url: %s", rawURL)
124+
}
125+
126+
response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, e)
116127
return response.Recorder
117128
}
118129

0 commit comments

Comments
 (0)