Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miketonks committed Oct 28, 2019
1 parent 7b46650 commit bfa0722
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
13 changes: 2 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 3 additions & 1 deletion swag-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
}
Expand Down
9 changes: 5 additions & 4 deletions swag-validator_echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion swag-validator_gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit bfa0722

Please sign in to comment.