diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f8f3669fc..41b196f7d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -25,14 +25,18 @@ jobs: go-version: 1.x - run: go version - - run: go mod download && go mod verify - - run: go test ./... + - run: go mod download && go mod tidy && go mod verify + - run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]] + shell: bash + - run: go vet ./... + - run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]] + shell: bash + - run: go fmt ./... - run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]] shell: bash + - run: go test ./... - run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]] shell: bash - - run: go get -u -a -v ./... && go mod tidy && go mod verify - - run: git --no-pager diff diff --git a/go.sum b/go.sum index 60f84360b..f1e462c68 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,3 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 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= @@ -8,8 +7,10 @@ github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUe github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= @@ -20,8 +21,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= diff --git a/openapi2conv/openapi2_conv.go b/openapi2conv/openapi2_conv.go index 03a880279..f3f8c5c34 100644 --- a/openapi2conv/openapi2_conv.go +++ b/openapi2conv/openapi2_conv.go @@ -782,9 +782,9 @@ func FromV3SecurityRequirements(requirements openapi3.SecurityRequirements) open if requirements == nil { return nil } - result := make([]map[string][]string, len(requirements)) - for i, item := range requirements { - result[i] = item + result := make([]map[string][]string, 0, len(requirements)) + for _, item := range requirements { + result = append(result, item) } return result } diff --git a/openapi3/swagger_loader.go b/openapi3/swagger_loader.go index ed2b05225..6755b2917 100644 --- a/openapi3/swagger_loader.go +++ b/openapi3/swagger_loader.go @@ -37,14 +37,14 @@ type SwaggerLoader struct { visitedFiles map[string]struct{} visitedSwaggers map[string]*Swagger + visitedExample map[*Example]struct{} visitedHeader map[*Header]struct{} + visitedLink map[*Link]struct{} visitedParameter map[*Parameter]struct{} visitedRequestBody map[*RequestBody]struct{} visitedResponse map[*Response]struct{} visitedSchema map[*Schema]struct{} visitedSecurityScheme map[*SecurityScheme]struct{} - visitedExample map[*Example]struct{} - visitedLink map[*Link]struct{} } // NewSwaggerLoader returns an empty SwaggerLoader @@ -192,15 +192,29 @@ func (swaggerLoader *SwaggerLoader) loadSwaggerFromDataWithPathInternal(data []b // ResolveRefsIn expands references if for instance spec was just unmarshalled func (swaggerLoader *SwaggerLoader) ResolveRefsIn(swagger *Swagger, path *url.URL) (err error) { + if swaggerLoader.visitedExample == nil { + swaggerLoader.visitedExample = make(map[*Example]struct{}) + } if swaggerLoader.visitedHeader == nil { swaggerLoader.visitedHeader = make(map[*Header]struct{}) + } + if swaggerLoader.visitedLink == nil { + swaggerLoader.visitedLink = make(map[*Link]struct{}) + } + if swaggerLoader.visitedParameter == nil { swaggerLoader.visitedParameter = make(map[*Parameter]struct{}) + } + if swaggerLoader.visitedRequestBody == nil { swaggerLoader.visitedRequestBody = make(map[*RequestBody]struct{}) + } + if swaggerLoader.visitedResponse == nil { swaggerLoader.visitedResponse = make(map[*Response]struct{}) + } + if swaggerLoader.visitedSchema == nil { swaggerLoader.visitedSchema = make(map[*Schema]struct{}) + } + if swaggerLoader.visitedSecurityScheme == nil { swaggerLoader.visitedSecurityScheme = make(map[*SecurityScheme]struct{}) - swaggerLoader.visitedExample = make(map[*Example]struct{}) - swaggerLoader.visitedLink = make(map[*Link]struct{}) } if swaggerLoader.visitedFiles == nil { swaggerLoader.reset()