diff --git a/go.mod b/go.mod index ca8c44a..f6b1a9a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/oapi-codegen/echo-middleware go 1.20 require ( - github.com/deepmap/oapi-codegen v1.14.0 github.com/getkin/kin-openapi v0.118.0 github.com/labstack/echo/v4 v4.11.1 github.com/stretchr/testify v1.8.4 @@ -24,6 +23,7 @@ require ( github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/perimeterx/marshmallow v1.1.4 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect golang.org/x/crypto v0.12.0 // indirect diff --git a/go.sum b/go.sum index 25d24f9..6dbe457 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deepmap/oapi-codegen v1.14.0 h1:b51/kQwH69rjN5pu+8j/Q5fUGD/rUclLAcGLQWQwa3E= -github.com/deepmap/oapi-codegen v1.14.0/go.mod h1:QcEpzjVDwJEH3Fq6I7XYkI0M/JwvoL82ToYveaeVMAw= github.com/getkin/kin-openapi v0.118.0 h1:z43njxPmJ7TaPpMSCQb7PN0dEYno4tyBPQcrFdHoLuM= github.com/getkin/kin-openapi v0.118.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -62,10 +60,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= diff --git a/oapi_validate_test.go b/oapi_validate_test.go index 06a4229..8bc6a11 100644 --- a/oapi_validate_test.go +++ b/oapi_validate_test.go @@ -15,8 +15,10 @@ package echomiddleware import ( + "bytes" "context" _ "embed" + "encoding/json" "errors" "io" "net/http" @@ -24,7 +26,6 @@ import ( "net/url" "testing" - "github.com/deepmap/oapi-codegen/pkg/testutil" "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/openapi3filter" "github.com/labstack/echo/v4" @@ -42,8 +43,18 @@ func doGet(t *testing.T, e *echo.Echo, rawURL string) *httptest.ResponseRecorder t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Get(u.RequestURI()).WithHost(u.Host).WithAcceptJson().GoWithHTTPHandler(t, e) - return response.Recorder + r, err := http.NewRequest(http.MethodGet, u.String(), nil) + if err != nil { + t.Fatalf("Could not construct a request: %s", rawURL) + } + r.Header.Set("accept", "application/json") + r.Header.Set("host", u.Host) + + tt := httptest.NewRecorder() + + e.ServeHTTP(tt, r) + + return tt } func doPost(t *testing.T, e *echo.Echo, rawURL string, jsonBody interface{}) *httptest.ResponseRecorder { @@ -52,8 +63,24 @@ func doPost(t *testing.T, e *echo.Echo, rawURL string, jsonBody interface{}) *ht t.Fatalf("Invalid url: %s", rawURL) } - response := testutil.NewRequest().Post(u.RequestURI()).WithHost(u.Host).WithJsonBody(jsonBody).GoWithHTTPHandler(t, e) - return response.Recorder + body, err := json.Marshal(jsonBody) + if err != nil { + t.Fatalf("Could not marshal request body: %v", err) + } + + r, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(body)) + if err != nil { + t.Fatalf("Could not construct a request for URL %s: %v", rawURL, err) + } + r.Header.Set("accept", "application/json") + r.Header.Set("content-type", "application/json") + r.Header.Set("host", u.Host) + + tt := httptest.NewRecorder() + + e.ServeHTTP(tt, r) + + return tt } func TestOapiRequestValidator(t *testing.T) {