diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5cdecc97b..6c192f969 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -142,3 +142,15 @@ jobs: T Tag XML + + check-goimports: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.17.0' + - run: go install github.com/incu6us/goimports-reviser/v2@v2.5.1 + - run: which goimports-reviser + - run: find . -type f -iname '*.go' ! -iname '*.pb.go' -exec goimports-reviser -file-path {} \; + - run: git --no-pager diff --exit-code diff --git a/go.mod b/go.mod index df32d6a7e..50aba584b 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,10 @@ module github.com/getkin/kin-openapi go 1.16 require ( - github.com/ghodss/yaml v1.0.0 github.com/go-openapi/jsonpointer v0.19.5 github.com/gorilla/mux v1.8.0 + github.com/invopop/yaml v0.1.0 github.com/stretchr/testify v1.5.1 - gopkg.in/yaml.v2 v2.3.0 + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 2b289d716..a123aaff6 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,14 @@ 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/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= 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/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc= +github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= 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= @@ -27,5 +27,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 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= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/openapi2/openapi2_test.go b/openapi2/openapi2_test.go index 8d3efdf8a..65e92d601 100644 --- a/openapi2/openapi2_test.go +++ b/openapi2/openapi2_test.go @@ -6,8 +6,9 @@ import ( "io/ioutil" "reflect" + "github.com/invopop/yaml" + "github.com/getkin/kin-openapi/openapi2" - "github.com/ghodss/yaml" ) func Example() { diff --git a/openapi2conv/issue187_test.go b/openapi2conv/issue187_test.go index a7016893a..93914d9f9 100644 --- a/openapi2conv/issue187_test.go +++ b/openapi2conv/issue187_test.go @@ -5,10 +5,11 @@ import ( "encoding/json" "testing" + "github.com/invopop/yaml" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi2" "github.com/getkin/kin-openapi/openapi3" - "github.com/ghodss/yaml" - "github.com/stretchr/testify/require" ) func v2v3JSON(spec2 []byte) (doc3 *openapi3.T, err error) { @@ -162,7 +163,7 @@ paths: "200": description: description ` - require.Equal(t, string(spec3), expected) + require.YAMLEq(t, string(spec3), expected) err = doc3.Validate(context.Background()) require.NoError(t, err) diff --git a/openapi2conv/issue440_test.go b/openapi2conv/issue440_test.go index 24f7a29e9..2478384ff 100644 --- a/openapi2conv/issue440_test.go +++ b/openapi2conv/issue440_test.go @@ -6,9 +6,10 @@ import ( "os" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi2" "github.com/getkin/kin-openapi/openapi3" - "github.com/stretchr/testify/require" ) func TestIssue440(t *testing.T) { diff --git a/openapi3/example.go b/openapi3/example.go index 080845cad..ee40d9e37 100644 --- a/openapi3/example.go +++ b/openapi3/example.go @@ -4,8 +4,9 @@ import ( "context" "fmt" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) type Examples map[string]*ExampleRef diff --git a/openapi3/extension_test.go b/openapi3/extension_test.go index 9d009024e..a99537892 100644 --- a/openapi3/extension_test.go +++ b/openapi3/extension_test.go @@ -5,8 +5,9 @@ import ( "fmt" "testing" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/stretchr/testify/require" + + "github.com/getkin/kin-openapi/jsoninfo" ) func ExampleExtensionProps_DecodeWith() { diff --git a/openapi3/header.go b/openapi3/header.go index 84ffd8866..75e5dd1e2 100644 --- a/openapi3/header.go +++ b/openapi3/header.go @@ -5,8 +5,9 @@ import ( "errors" "fmt" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) type Headers map[string]*HeaderRef diff --git a/openapi3/link.go b/openapi3/link.go index 2f0bc57c9..7f0c49d4d 100644 --- a/openapi3/link.go +++ b/openapi3/link.go @@ -5,8 +5,9 @@ import ( "errors" "fmt" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) type Links map[string]*LinkRef diff --git a/openapi3/loader.go b/openapi3/loader.go index 8af733c3b..e2f131e40 100644 --- a/openapi3/loader.go +++ b/openapi3/loader.go @@ -12,7 +12,7 @@ import ( "strconv" "strings" - "github.com/ghodss/yaml" + "github.com/invopop/yaml" ) func foundUnresolvedRef(ref string) error { diff --git a/openapi3/media_type.go b/openapi3/media_type.go index dd33b99b2..fc95244c6 100644 --- a/openapi3/media_type.go +++ b/openapi3/media_type.go @@ -3,8 +3,9 @@ package openapi3 import ( "context" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) // MediaType is specified by OpenAPI/Swagger 3.0 standard. diff --git a/openapi3/openapi3_test.go b/openapi3/openapi3_test.go index 69a2f959b..7736310cc 100644 --- a/openapi3/openapi3_test.go +++ b/openapi3/openapi3_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/ghodss/yaml" + "github.com/invopop/yaml" "github.com/stretchr/testify/require" ) diff --git a/openapi3/operation.go b/openapi3/operation.go index cb9644a77..58750ffbf 100644 --- a/openapi3/operation.go +++ b/openapi3/operation.go @@ -6,8 +6,9 @@ import ( "fmt" "strconv" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) // Operation represents "operation" specified by" OpenAPI/Swagger 3.0 standard. diff --git a/openapi3/parameter.go b/openapi3/parameter.go index b32898c65..77834847d 100644 --- a/openapi3/parameter.go +++ b/openapi3/parameter.go @@ -6,8 +6,9 @@ import ( "fmt" "strconv" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) type ParametersMap map[string]*ParameterRef diff --git a/openapi3/race_test.go b/openapi3/race_test.go index 4ac31c38e..c617cfe49 100644 --- a/openapi3/race_test.go +++ b/openapi3/race_test.go @@ -4,8 +4,9 @@ import ( "context" "testing" - "github.com/getkin/kin-openapi/openapi3" "github.com/stretchr/testify/require" + + "github.com/getkin/kin-openapi/openapi3" ) func TestRaceyPatternSchema(t *testing.T) { diff --git a/openapi3/refs.go b/openapi3/refs.go index a706834ca..0bf737ff7 100644 --- a/openapi3/refs.go +++ b/openapi3/refs.go @@ -3,8 +3,9 @@ package openapi3 import ( "context" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) // Ref is specified by OpenAPI/Swagger 3.0 standard. diff --git a/openapi3/request_body.go b/openapi3/request_body.go index 559eb7122..c97563a11 100644 --- a/openapi3/request_body.go +++ b/openapi3/request_body.go @@ -5,8 +5,9 @@ import ( "errors" "fmt" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) type RequestBodies map[string]*RequestBodyRef diff --git a/openapi3/response.go b/openapi3/response.go index 23e2f4449..31ea257d1 100644 --- a/openapi3/response.go +++ b/openapi3/response.go @@ -6,8 +6,9 @@ import ( "fmt" "strconv" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) // Responses is specified by OpenAPI/Swagger 3.0 standard. diff --git a/openapi3/schema.go b/openapi3/schema.go index 214f4f635..4c8df1cba 100644 --- a/openapi3/schema.go +++ b/openapi3/schema.go @@ -12,8 +12,9 @@ import ( "strconv" "unicode/utf16" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) const ( diff --git a/openapi3/security_scheme.go b/openapi3/security_scheme.go index 10057de6b..52c3ef218 100644 --- a/openapi3/security_scheme.go +++ b/openapi3/security_scheme.go @@ -5,8 +5,9 @@ import ( "errors" "fmt" - "github.com/getkin/kin-openapi/jsoninfo" "github.com/go-openapi/jsonpointer" + + "github.com/getkin/kin-openapi/jsoninfo" ) type SecuritySchemes map[string]*SecuritySchemeRef diff --git a/openapi3/unique_items_checker_test.go b/openapi3/unique_items_checker_test.go index 85147c67a..270b797e1 100644 --- a/openapi3/unique_items_checker_test.go +++ b/openapi3/unique_items_checker_test.go @@ -4,8 +4,9 @@ import ( "strings" "testing" - "github.com/getkin/kin-openapi/openapi3" "github.com/stretchr/testify/require" + + "github.com/getkin/kin-openapi/openapi3" ) func TestRegisterArrayUniqueItemsChecker(t *testing.T) { diff --git a/openapi3filter/req_resp_decoder.go b/openapi3filter/req_resp_decoder.go index 1b5f0c5d5..a54b3bb47 100644 --- a/openapi3filter/req_resp_decoder.go +++ b/openapi3filter/req_resp_decoder.go @@ -14,7 +14,7 @@ import ( "strconv" "strings" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "github.com/getkin/kin-openapi/openapi3" ) diff --git a/openapi3filter/req_resp_decoder_test.go b/openapi3filter/req_resp_decoder_test.go index c733bd028..8bd62b1c5 100644 --- a/openapi3filter/req_resp_decoder_test.go +++ b/openapi3filter/req_resp_decoder_test.go @@ -15,9 +15,10 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" legacyrouter "github.com/getkin/kin-openapi/routers/legacy" - "github.com/stretchr/testify/require" ) func TestDecodeParameter(t *testing.T) { diff --git a/openapi3filter/validate_readonly_test.go b/openapi3filter/validate_readonly_test.go index 454a927e9..1152ec886 100644 --- a/openapi3filter/validate_readonly_test.go +++ b/openapi3filter/validate_readonly_test.go @@ -6,9 +6,10 @@ import ( "net/http" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" legacyrouter "github.com/getkin/kin-openapi/routers/legacy" - "github.com/stretchr/testify/require" ) func TestValidatingRequestBodyWithReadOnlyProperty(t *testing.T) { diff --git a/openapi3filter/validate_request_test.go b/openapi3filter/validate_request_test.go index b43f6c813..957b6925e 100644 --- a/openapi3filter/validate_request_test.go +++ b/openapi3filter/validate_request_test.go @@ -10,11 +10,12 @@ import ( "net/http" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/routers" "github.com/getkin/kin-openapi/routers/gorillamux" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func setupTestRouter(t *testing.T, spec string) routers.Router { diff --git a/openapi3filter/validate_set_default_test.go b/openapi3filter/validate_set_default_test.go index bacffe529..40714051a 100644 --- a/openapi3filter/validate_set_default_test.go +++ b/openapi3filter/validate_set_default_test.go @@ -8,9 +8,10 @@ import ( "net/url" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" legacyrouter "github.com/getkin/kin-openapi/routers/legacy" - "github.com/stretchr/testify/require" ) func TestValidatingRequestParameterAndSetDefault(t *testing.T) { diff --git a/openapi3filter/validation_discriminator_test.go b/openapi3filter/validation_discriminator_test.go index c7d614403..adabf409d 100644 --- a/openapi3filter/validation_discriminator_test.go +++ b/openapi3filter/validation_discriminator_test.go @@ -5,9 +5,10 @@ import ( "net/http" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" legacyrouter "github.com/getkin/kin-openapi/routers/legacy" - "github.com/stretchr/testify/require" ) func TestValidationWithDiscriminatorSelection(t *testing.T) { diff --git a/openapi3filter/validation_error_test.go b/openapi3filter/validation_error_test.go index 10d46f855..b9151b878 100644 --- a/openapi3filter/validation_error_test.go +++ b/openapi3filter/validation_error_test.go @@ -10,9 +10,10 @@ import ( "net/http/httptest" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/routers" - "github.com/stretchr/testify/require" ) func newPetstoreRequest(t *testing.T, method, path string, body io.Reader) *http.Request { diff --git a/openapi3filter/validation_test.go b/openapi3filter/validation_test.go index 2f7cf80e6..cd1fa8990 100644 --- a/openapi3filter/validation_test.go +++ b/openapi3filter/validation_test.go @@ -14,9 +14,10 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" legacyrouter "github.com/getkin/kin-openapi/routers/legacy" - "github.com/stretchr/testify/require" ) type ExampleRequest struct { diff --git a/openapi3gen/openapi3gen_test.go b/openapi3gen/openapi3gen_test.go index a85f5da4a..a4c2d52e9 100644 --- a/openapi3gen/openapi3gen_test.go +++ b/openapi3gen/openapi3gen_test.go @@ -10,9 +10,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/openapi3gen" - "github.com/stretchr/testify/require" ) func ExampleGenerator_SchemaRefs() { diff --git a/routers/gorillamux/router.go b/routers/gorillamux/router.go index 83bbf829e..67be47452 100644 --- a/routers/gorillamux/router.go +++ b/routers/gorillamux/router.go @@ -12,9 +12,10 @@ import ( "sort" "strings" + "github.com/gorilla/mux" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/routers" - "github.com/gorilla/mux" ) var _ routers.Router = &Router{} diff --git a/routers/gorillamux/router_test.go b/routers/gorillamux/router_test.go index 90f5c3dba..31bf416ed 100644 --- a/routers/gorillamux/router_test.go +++ b/routers/gorillamux/router_test.go @@ -6,9 +6,10 @@ import ( "sort" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/routers" - "github.com/stretchr/testify/require" ) func TestRouter(t *testing.T) { diff --git a/routers/issue356_test.go b/routers/issue356_test.go index 307e52aea..3e4b9fa1d 100644 --- a/routers/issue356_test.go +++ b/routers/issue356_test.go @@ -8,12 +8,13 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/openapi3filter" "github.com/getkin/kin-openapi/routers" "github.com/getkin/kin-openapi/routers/gorillamux" "github.com/getkin/kin-openapi/routers/legacy" - "github.com/stretchr/testify/require" ) func TestIssue356(t *testing.T) { diff --git a/routers/legacy/issue444_test.go b/routers/legacy/issue444_test.go index 222ecbba4..c1e9b14f2 100644 --- a/routers/legacy/issue444_test.go +++ b/routers/legacy/issue444_test.go @@ -6,10 +6,11 @@ import ( "net/http/httptest" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/openapi3filter" legacyrouter "github.com/getkin/kin-openapi/routers/legacy" - "github.com/stretchr/testify/require" ) func TestIssue444(t *testing.T) { diff --git a/routers/legacy/router_test.go b/routers/legacy/router_test.go index bfc7e11e5..d4779f58a 100644 --- a/routers/legacy/router_test.go +++ b/routers/legacy/router_test.go @@ -6,9 +6,10 @@ import ( "sort" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/getkin/kin-openapi/routers" - "github.com/stretchr/testify/require" ) func TestRouter(t *testing.T) {