diff --git a/go.mod b/go.mod index f73c443..df5a98d 100644 --- a/go.mod +++ b/go.mod @@ -3,19 +3,10 @@ module github.com/miketonks/swag-validator go 1.12 require ( - github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect - github.com/gin-gonic/gin v1.3.0 - github.com/golang/protobuf v1.3.1 // indirect - github.com/json-iterator/go v1.1.6 // indirect + github.com/gin-gonic/gin v1.4.0 github.com/labstack/echo v3.3.10+incompatible - github.com/labstack/gommon v0.3.0 // indirect - github.com/miketonks/swag v0.0.0-20190717104731-91ce91166750 - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/miketonks/swag v0.0.0-20191028095334-d5fe47229537 github.com/stretchr/testify v1.4.0 - github.com/ugorji/go v1.1.4 // indirect github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/net v0.0.0-20190607181551-461777fb6f67 // indirect - gopkg.in/go-playground/assert.v1 v1.2.1 // indirect - gopkg.in/go-playground/validator.v8 v8.18.2 // indirect ) diff --git a/swag-validator.go b/swag-validator.go index 16bd35b..288cf31 100644 --- a/swag-validator.go +++ b/swag-validator.go @@ -288,6 +288,8 @@ func SwaggerValidator(api *swagger.API) gin.HandlerFunc { // SwaggerValidatorEcho middleware func SwaggerValidatorEcho(api *swagger.API) echo.MiddlewareFunc { + basePath := strings.TrimRight(api.BasePath, "/") + apiMap := map[string]gojsonschema.JSONLoader{} for _, p := range api.Paths { for _, e := range []*swagger.Endpoint{ @@ -305,7 +307,7 @@ func SwaggerValidatorEcho(api *swagger.API) echo.MiddlewareFunc { schema.Definitions = buildSchemaDefinitions(api) schemaLoader := gojsonschema.NewGoLoader(schema) - key := e.Method + api.BasePath + swag.ColonPath(e.Path) + key := e.Method + basePath + swag.ColonPath(e.Path) apiMap[key] = schemaLoader } } diff --git a/swag-validator_echo_test.go b/swag-validator_echo_test.go index 7eaea2c..c7cfb33 100644 --- a/swag-validator_echo_test.go +++ b/swag-validator_echo_test.go @@ -181,10 +181,11 @@ func TestPathEcho(t *testing.T) { // Even if the handler is a lambda, it still does not work. // Therefore have to create a new api for each endpoint iteratively for _, testCase := range testTable { - api := swag.New(swag.Endpoints(endpoint.New("GET", "/validate-test"+testCase.urlWParm, "Test the validator", - endpoint.Handler(func(echo.Context) error { return nil }), - testCase.path, - ))) + api := swag.New( + swag.Endpoints(endpoint.New("GET", "/validate-test"+testCase.urlWParm, "Test the validator", + endpoint.Handler(func(echo.Context) error { return nil }), + testCase.path, + ))) r := createEngineEcho(api) diff --git a/swag-validator_gin_test.go b/swag-validator_gin_test.go index 926d3d2..1d021b2 100644 --- a/swag-validator_gin_test.go +++ b/swag-validator_gin_test.go @@ -18,7 +18,8 @@ import ( ) func createEngineGin(api *swagger.API) (r *gin.Engine) { - r = gin.Default() + gin.SetMode(gin.ReleaseMode) + r = gin.New() r.Use(sv.SwaggerValidator(api)) api.Walk(func(path string, endpoint *swagger.Endpoint) { h := endpoint.Handler.(func(c *gin.Context))