diff --git a/.golangci.yml b/.golangci.yml index 66eac0d..43e2576 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ linters: - gomoddirectives - gosmopolitan - inamedparam - - intrange # disabled while < go1.22 + #- intrange # disabled while < go1.22 - ireturn - lll - musttag diff --git a/benchmark_test.go b/benchmark_test.go index 3f7d8d2..ff58813 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -19,7 +19,7 @@ func Benchmark_KubernetesSpec(b *testing.B) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for b.Loop() { validator := NewSpecValidator(doc.Schema(), strfmt.Default) validator.Options.SkipSchemataResult = true res, _ := validator.Validate(doc) diff --git a/context.go b/context.go index 8997717..d54791c 100644 --- a/context.go +++ b/context.go @@ -27,7 +27,7 @@ func WithOperationRequest(ctx context.Context) context.Context { return withOperation(ctx, request) } -// WithOperationRequest returns a new context with operationType response +// WithOperationResponse returns a new context with operationType response // in context value func WithOperationResponse(ctx context.Context) context.Context { return withOperation(ctx, response) diff --git a/go.mod b/go.mod index 266dcad..a6d3b83 100644 --- a/go.mod +++ b/go.mod @@ -1,37 +1,37 @@ module github.com/go-openapi/validate require ( - github.com/davecgh/go-spew v1.1.1 - github.com/go-openapi/analysis v0.23.0 - github.com/go-openapi/errors v0.22.2 - github.com/go-openapi/jsonpointer v0.22.0 - github.com/go-openapi/loads v0.22.0 - github.com/go-openapi/spec v0.21.0 - github.com/go-openapi/strfmt v0.23.0 - github.com/go-openapi/swag/conv v0.25.0 - github.com/go-openapi/swag/fileutils v0.25.0 - github.com/go-openapi/swag/jsonutils v0.25.0 - github.com/go-openapi/swag/stringutils v0.25.0 + github.com/go-openapi/analysis v0.24.0 + github.com/go-openapi/errors v0.22.3 + github.com/go-openapi/jsonpointer v0.22.1 + github.com/go-openapi/loads v0.23.1 + github.com/go-openapi/spec v0.22.0 + github.com/go-openapi/strfmt v0.24.0 + github.com/go-openapi/swag/conv v0.25.1 + github.com/go-openapi/swag/fileutils v0.25.1 + github.com/go-openapi/swag/jsonutils v0.25.1 + github.com/go-openapi/swag/stringutils v0.25.1 github.com/stretchr/testify v1.11.1 - gopkg.in/yaml.v3 v3.0.1 + go.yaml.in/yaml/v3 v3.0.4 ) require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect - github.com/go-openapi/jsonreference v0.21.1 // indirect - github.com/go-openapi/swag v0.24.1 // indirect - github.com/go-openapi/swag/cmdutils v0.24.0 // indirect - github.com/go-openapi/swag/jsonname v0.24.0 // indirect - github.com/go-openapi/swag/loading v0.24.0 // indirect - github.com/go-openapi/swag/mangling v0.24.0 // indirect - github.com/go-openapi/swag/netutils v0.24.0 // indirect - github.com/go-openapi/swag/typeutils v0.25.0 // indirect - github.com/go-openapi/swag/yamlutils v0.24.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-openapi/jsonreference v0.21.2 // indirect + github.com/go-openapi/swag/jsonname v0.25.1 // indirect + github.com/go-openapi/swag/loading v0.25.1 // indirect + github.com/go-openapi/swag/mangling v0.25.1 // indirect + github.com/go-openapi/swag/typeutils v0.25.1 // indirect + github.com/go-openapi/swag/yamlutils v0.25.1 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect go.mongodb.org/mongo-driver v1.17.4 // indirect + golang.org/x/net v0.44.0 // indirect + golang.org/x/text v0.29.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) go 1.24.0 diff --git a/go.sum b/go.sum index 17f8615..3f44496 100644 --- a/go.sum +++ b/go.sum @@ -2,46 +2,42 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3d github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= 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/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU= -github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo= -github.com/go-openapi/errors v0.22.2 h1:rdxhzcBUazEcGccKqbY1Y7NS8FDcMyIRr0934jrYnZg= -github.com/go-openapi/errors v0.22.2/go.mod h1:+n/5UdIqdVnLIJ6Q9Se8HNGUXYaY6CN8ImWzfi/Gzp0= -github.com/go-openapi/jsonpointer v0.22.0 h1:TmMhghgNef9YXxTu1tOopo+0BGEytxA+okbry0HjZsM= -github.com/go-openapi/jsonpointer v0.22.0/go.mod h1:xt3jV88UtExdIkkL7NloURjRQjbeUgcxFblMjq2iaiU= -github.com/go-openapi/jsonreference v0.21.1 h1:bSKrcl8819zKiOgxkbVNRUBIr6Wwj9KYrDbMjRs0cDA= -github.com/go-openapi/jsonreference v0.21.1/go.mod h1:PWs8rO4xxTUqKGu+lEvvCxD5k2X7QYkKAepJyCmSTT8= -github.com/go-openapi/loads v0.22.0 h1:ECPGd4jX1U6NApCGG1We+uEozOAvXvJSF4nnwHZ8Aco= -github.com/go-openapi/loads v0.22.0/go.mod h1:yLsaTCS92mnSAZX5WWoxszLj0u+Ojl+Zs5Stn1oF+rs= -github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY= -github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk= -github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= -github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4= -github.com/go-openapi/swag v0.24.1 h1:DPdYTZKo6AQCRqzwr/kGkxJzHhpKxZ9i/oX0zag+MF8= -github.com/go-openapi/swag v0.24.1/go.mod h1:sm8I3lCPlspsBBwUm1t5oZeWZS0s7m/A+Psg0ooRU0A= -github.com/go-openapi/swag/cmdutils v0.24.0 h1:KlRCffHwXFI6E5MV9n8o8zBRElpY4uK4yWyAMWETo9I= -github.com/go-openapi/swag/cmdutils v0.24.0/go.mod h1:uxib2FAeQMByyHomTlsP8h1TtPd54Msu2ZDU/H5Vuf8= -github.com/go-openapi/swag/conv v0.25.0 h1:5K+e44HkOgCVE0IJTbivurzHahT62DPr2DEJqR/+4pA= -github.com/go-openapi/swag/conv v0.25.0/go.mod h1:oa1ZZnb1jubNdZlD1iAhGXt6Ic4hHtuO23MwTgAXR88= -github.com/go-openapi/swag/fileutils v0.25.0 h1:t7aQRuRfsP29dY4vfrNvDZv7RurwRHuyjUedtYVDmYY= -github.com/go-openapi/swag/fileutils v0.25.0/go.mod h1:+NXtt5xNZZqmpIpjqcujqojGFek9/w55b3ecmOdtg8M= -github.com/go-openapi/swag/jsonname v0.24.0 h1:2wKS9bgRV/xB8c62Qg16w4AUiIrqqiniJFtZGi3dg5k= -github.com/go-openapi/swag/jsonname v0.24.0/go.mod h1:GXqrPzGJe611P7LG4QB9JKPtUZ7flE4DOVechNaDd7Q= -github.com/go-openapi/swag/jsonutils v0.25.0 h1:ELKpJT29T4N/AvmDqMeDFLx2QRZQOYFthzctbIX30+A= -github.com/go-openapi/swag/jsonutils v0.25.0/go.mod h1:KYL8GyGoi6tek9ajpvn0le4BWmKoUVVv8yPxklViIMo= -github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.0 h1:ca9vKxLnJegL2bzqXRWNabKdqVGxBzrnO8/UZnr5W0Y= -github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.0/go.mod h1:kjmweouyPwRUEYMSrbAidoLMGeJ5p6zdHi9BgZiqmsg= -github.com/go-openapi/swag/loading v0.24.0 h1:ln/fWTwJp2Zkj5DdaX4JPiddFC5CHQpvaBKycOlceYc= -github.com/go-openapi/swag/loading v0.24.0/go.mod h1:gShCN4woKZYIxPxbfbyHgjXAhO61m88tmjy0lp/LkJk= -github.com/go-openapi/swag/mangling v0.24.0 h1:PGOQpViCOUroIeak/Uj/sjGAq9LADS3mOyjznmHy2pk= -github.com/go-openapi/swag/mangling v0.24.0/go.mod h1:Jm5Go9LHkycsz0wfoaBDkdc4CkpuSnIEf62brzyCbhc= -github.com/go-openapi/swag/netutils v0.24.0 h1:Bz02HRjYv8046Ycg/w80q3g9QCWeIqTvlyOjQPDjD8w= -github.com/go-openapi/swag/netutils v0.24.0/go.mod h1:WRgiHcYTnx+IqfMCtu0hy9oOaPR0HnPbmArSRN1SkZM= -github.com/go-openapi/swag/stringutils v0.25.0 h1:iYfCF45GUeI/1Yrh8rQtTFCp5K1ToqWhUdzJZwvXvv8= -github.com/go-openapi/swag/stringutils v0.25.0/go.mod h1:JLdSAq5169HaiDUbTvArA2yQxmgn4D6h4A+4HqVvAYg= -github.com/go-openapi/swag/typeutils v0.25.0 h1:iUTsxu3F3h9v6CBzVFGXKPSBQt6d8XXgYy1YAlu+HJ8= -github.com/go-openapi/swag/typeutils v0.25.0/go.mod h1:9McMC/oCdS4BKwk2shEB7x17P6HmMmA6dQRtAkSnNb8= -github.com/go-openapi/swag/yamlutils v0.24.0 h1:bhw4894A7Iw6ne+639hsBNRHg9iZg/ISrOVr+sJGp4c= -github.com/go-openapi/swag/yamlutils v0.24.0/go.mod h1:DpKv5aYuaGm/sULePoeiG8uwMpZSfReo1HR3Ik0yaG8= +github.com/go-openapi/analysis v0.24.0 h1:vE/VFFkICKyYuTWYnplQ+aVr45vlG6NcZKC7BdIXhsA= +github.com/go-openapi/analysis v0.24.0/go.mod h1:GLyoJA+bvmGGaHgpfeDh8ldpGo69fAJg7eeMDMRCIrw= +github.com/go-openapi/errors v0.22.3 h1:k6Hxa5Jg1TUyZnOwV2Lh81j8ayNw5VVYLvKrp4zFKFs= +github.com/go-openapi/errors v0.22.3/go.mod h1:+WvbaBBULWCOna//9B9TbLNGSFOfF8lY9dw4hGiEiKQ= +github.com/go-openapi/jsonpointer v0.22.1 h1:sHYI1He3b9NqJ4wXLoJDKmUmHkWy/L7rtEo92JUxBNk= +github.com/go-openapi/jsonpointer v0.22.1/go.mod h1:pQT9OsLkfz1yWoMgYFy4x3U5GY5nUlsOn1qSBH5MkCM= +github.com/go-openapi/jsonreference v0.21.2 h1:Wxjda4M/BBQllegefXrY/9aq1fxBA8sI5M/lFU6tSWU= +github.com/go-openapi/jsonreference v0.21.2/go.mod h1:pp3PEjIsJ9CZDGCNOyXIQxsNuroxm8FAJ/+quA0yKzQ= +github.com/go-openapi/loads v0.23.1 h1:H8A0dX2KDHxDzc797h0+uiCZ5kwE2+VojaQVaTlXvS0= +github.com/go-openapi/loads v0.23.1/go.mod h1:hZSXkyACCWzWPQqizAv/Ye0yhi2zzHwMmoXQ6YQml44= +github.com/go-openapi/spec v0.22.0 h1:xT/EsX4frL3U09QviRIZXvkh80yibxQmtoEvyqug0Tw= +github.com/go-openapi/spec v0.22.0/go.mod h1:K0FhKxkez8YNS94XzF8YKEMULbFrRw4m15i2YUht4L0= +github.com/go-openapi/strfmt v0.24.0 h1:dDsopqbI3wrrlIzeXRbqMihRNnjzGC+ez4NQaAAJLuc= +github.com/go-openapi/strfmt v0.24.0/go.mod h1:Lnn1Bk9rZjXxU9VMADbEEOo7D7CDyKGLsSKekhFr7s4= +github.com/go-openapi/swag/conv v0.25.1 h1:+9o8YUg6QuqqBM5X6rYL/p1dpWeZRhoIt9x7CCP+he0= +github.com/go-openapi/swag/conv v0.25.1/go.mod h1:Z1mFEGPfyIKPu0806khI3zF+/EUXde+fdeksUl2NiDs= +github.com/go-openapi/swag/fileutils v0.25.1 h1:rSRXapjQequt7kqalKXdcpIegIShhTPXx7yw0kek2uU= +github.com/go-openapi/swag/fileutils v0.25.1/go.mod h1:+NXtt5xNZZqmpIpjqcujqojGFek9/w55b3ecmOdtg8M= +github.com/go-openapi/swag/jsonname v0.25.1 h1:Sgx+qbwa4ej6AomWC6pEfXrA6uP2RkaNjA9BR8a1RJU= +github.com/go-openapi/swag/jsonname v0.25.1/go.mod h1:71Tekow6UOLBD3wS7XhdT98g5J5GR13NOTQ9/6Q11Zo= +github.com/go-openapi/swag/jsonutils v0.25.1 h1:AihLHaD0brrkJoMqEZOBNzTLnk81Kg9cWr+SPtxtgl8= +github.com/go-openapi/swag/jsonutils v0.25.1/go.mod h1:JpEkAjxQXpiaHmRO04N1zE4qbUEg3b7Udll7AMGTNOo= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.1 h1:DSQGcdB6G0N9c/KhtpYc71PzzGEIc/fZ1no35x4/XBY= +github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.1/go.mod h1:kjmweouyPwRUEYMSrbAidoLMGeJ5p6zdHi9BgZiqmsg= +github.com/go-openapi/swag/loading v0.25.1 h1:6OruqzjWoJyanZOim58iG2vj934TysYVptyaoXS24kw= +github.com/go-openapi/swag/loading v0.25.1/go.mod h1:xoIe2EG32NOYYbqxvXgPzne989bWvSNoWoyQVWEZicc= +github.com/go-openapi/swag/mangling v0.25.1 h1:XzILnLzhZPZNtmxKaz/2xIGPQsBsvmCjrJOWGNz/ync= +github.com/go-openapi/swag/mangling v0.25.1/go.mod h1:CdiMQ6pnfAgyQGSOIYnZkXvqhnnwOn997uXZMAd/7mQ= +github.com/go-openapi/swag/stringutils v0.25.1 h1:Xasqgjvk30eUe8VKdmyzKtjkVjeiXx1Iz0zDfMNpPbw= +github.com/go-openapi/swag/stringutils v0.25.1/go.mod h1:JLdSAq5169HaiDUbTvArA2yQxmgn4D6h4A+4HqVvAYg= +github.com/go-openapi/swag/typeutils v0.25.1 h1:rD/9HsEQieewNt6/k+JBwkxuAHktFtH3I3ysiFZqukA= +github.com/go-openapi/swag/typeutils v0.25.1/go.mod h1:9McMC/oCdS4BKwk2shEB7x17P6HmMmA6dQRtAkSnNb8= +github.com/go-openapi/swag/yamlutils v0.25.1 h1:mry5ez8joJwzvMbaTGLhw8pXUnhDK91oSJLDPF1bmGk= +github.com/go-openapi/swag/yamlutils v0.25.1/go.mod h1:cm9ywbzncy3y6uPm/97ysW8+wZ09qsks+9RS8fLWKqg= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -50,8 +46,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -64,6 +58,10 @@ go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFX go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I= +golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= +golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= +golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/messages_test.go b/messages_test.go index 63a9ee5..78dcba6 100644 --- a/messages_test.go +++ b/messages_test.go @@ -27,7 +27,7 @@ import ( "github.com/go-openapi/strfmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" + yaml "go.yaml.in/yaml/v3" ) var ( diff --git a/pools_test.go b/pools_test.go index 27d4725..d7398de 100644 --- a/pools_test.go +++ b/pools_test.go @@ -16,7 +16,7 @@ func Test_ParallelPool(t *testing.T) { fixture3 := filepath.Join("fixtures", "bugs", "43", "fixture-43.yaml") t.Run("should validate in parallel", func(t *testing.T) { - for i := 0; i < 20; i++ { + for range 20 { t.Run("validating fixture 1", func(t *testing.T) { t.Parallel() diff --git a/post/defaulter_test.go b/post/defaulter_test.go index 47981e1..c90599d 100644 --- a/post/defaulter_test.go +++ b/post/defaulter_test.go @@ -42,7 +42,7 @@ func TestDefaulter(t *testing.T) { ApplyDefaults(r) t.Logf("After: %v", x) - var expected interface{} + var expected any err = json.Unmarshal([]byte(`{ "existing": 100, "int": 42, @@ -75,14 +75,14 @@ func TestDefaulterSimple(t *testing.T) { }, } validator := validate.NewSchemaValidator(&schema, nil, "", strfmt.Default) - x := map[string]interface{}{} + x := make(map[string]any) t.Logf("Before: %v", x) r := validator.Validate(x) assert.Falsef(t, r.HasErrors(), "unexpected validation error: %v", r.AsError()) ApplyDefaults(r) t.Logf("After: %v", x) - var expected interface{} + var expected any err := json.Unmarshal([]byte(`{ "int": 42, "str": "Hello" @@ -97,7 +97,7 @@ func BenchmarkDefaulting(b *testing.B) { schema, err := defaulterFixture() require.NoError(b, err) - for n := 0; n < b.N; n++ { + for b.Loop() { validator := validate.NewSchemaValidator(schema, nil, "", strfmt.Default) x := defaulterFixtureInput() r := validator.Validate(x) @@ -106,13 +106,13 @@ func BenchmarkDefaulting(b *testing.B) { } } -func defaulterFixtureInput() map[string]interface{} { - return map[string]interface{}{ +func defaulterFixtureInput() map[string]any { + return map[string]any{ "existing": float64(100), - "nested": map[string]interface{}{}, - "all": map[string]interface{}{}, - "any": map[string]interface{}{}, - "one": map[string]interface{}{}, + "nested": map[string]any{}, + "all": map[string]any{}, + "any": map[string]any{}, + "one": map[string]any{}, } } diff --git a/result.go b/result.go index cf7c421..1955cff 100644 --- a/result.go +++ b/result.go @@ -518,7 +518,7 @@ func (s *schemata) Slice() []*spec.Schema { return s.multiple } -// appendSchemata appends the schemata in other to s. It mutates s in-place. +// Append appends the schemata in other to s. It mutates s in-place. func (s *schemata) Append(other schemata) { if other.one == nil && len(other.multiple) == 0 { return @@ -560,7 +560,7 @@ func (s schemata) Clone() schemata { if len(s.multiple) > 0 { clone.multiple = make([]*spec.Schema, len(s.multiple)) - for idx := 0; idx < len(s.multiple); idx++ { + for idx := range len(s.multiple) { sp := new(spec.Schema) *sp = *s.multiple[idx] clone.multiple[idx] = sp diff --git a/rexp_test.go b/rexp_test.go index 7009c7f..dc8b6ff 100644 --- a/rexp_test.go +++ b/rexp_test.go @@ -75,7 +75,7 @@ func TestRace_compileRegexp(t *testing.T) { assert.IsType(t, vrex, rex) } - for i := 0; i < 20; i++ { + for i := range 20 { ii := i t.Run(patterns[ii%3], func(t *testing.T) { t.Parallel() @@ -99,7 +99,7 @@ func TestRace_mustCompileRegexp(t *testing.T) { assert.IsType(t, vrex, rex) } - for i := 0; i < 20; i++ { + for i := range 20 { ii := i t.Run(patterns[ii%3], func(t *testing.T) { t.Parallel() diff --git a/slice_validator.go b/slice_validator.go index 13bb020..7b0dede 100644 --- a/slice_validator.go +++ b/slice_validator.go @@ -94,7 +94,7 @@ func (s *schemaSliceValidator) Validate(data interface{}) *Result { size := val.Len() if s.Items != nil && s.Items.Schema != nil { - for i := 0; i < size; i++ { + for i := range size { validator := newSchemaValidator(s.Items.Schema, s.Root, s.Path, s.KnownFormats, s.Options) validator.SetPath(fmt.Sprintf("%s.%d", s.Path, i)) value := val.Index(i) @@ -105,7 +105,7 @@ func (s *schemaSliceValidator) Validate(data interface{}) *Result { itemsSize := 0 if s.Items != nil && len(s.Items.Schemas) > 0 { itemsSize = len(s.Items.Schemas) - for i := 0; i < itemsSize; i++ { + for i := range itemsSize { if size <= i { break } diff --git a/spec_messages.go b/spec_messages.go index 6d1f0f8..8da22cf 100644 --- a/spec_messages.go +++ b/spec_messages.go @@ -34,7 +34,7 @@ const ( // BothFormDataAndBodyError indicates that an operation specifies both a body and a formData parameter, which is forbidden BothFormDataAndBodyError = "operation %q has both formData and body parameters. Only one such In: type may be used for a given operation" - // CannotResolveRefError when a $ref could not be resolved + // CannotResolveReferenceError when a $ref could not be resolved CannotResolveReferenceError = "could not resolve reference in %s to $ref %s: %v" // CircularAncestryDefinitionError ... @@ -135,7 +135,7 @@ const ( // PathParamNotUniqueError ... PathParamNotUniqueError = "params in path %q must be unique: %q conflicts with %q" - // PathParamNotRequiredError ... + // PathParamRequiredError ... PathParamRequiredError = "in operation %q,path param %q must be declared as required" // RefNotAllowedInHeaderError indicates a $ref was found in a header definition, which is not allowed by Swagger diff --git a/spec_test.go b/spec_test.go index 1de27ba..4dded45 100644 --- a/spec_test.go +++ b/spec_test.go @@ -22,7 +22,6 @@ import ( "strings" "testing" - "github.com/davecgh/go-spew/spew" "github.com/go-openapi/analysis" "github.com/go-openapi/loads" "github.com/go-openapi/loads/fmts" @@ -925,7 +924,7 @@ func Test_Examples(t *testing.T) { res, _ := validator.Validate(doc) if !assert.Truef(t, res.IsValid(), "expected spec to be valid") { - spew.Dump(res.Errors) + t.Logf("%#v", res.Errors) } } diff --git a/validator.go b/validator.go index c083aec..b76b863 100644 --- a/validator.go +++ b/validator.go @@ -769,7 +769,7 @@ func (s *basicSliceValidator) Validate(data interface{}) *Result { return nil } - for i := 0; i < int(size); i++ { + for i := range int(size) { itemsValidator := newItemsValidator(s.Path, s.In, s.Items, s.Source, s.KnownFormats, s.Options) ele := val.Index(i) if err := itemsValidator.Validate(i, ele.Interface()); err != nil { diff --git a/values.go b/values.go index 9df4a95..1bfa6f3 100644 --- a/values.go +++ b/values.go @@ -36,20 +36,20 @@ func (e valueError) Error() string { const ErrValue valueError = "value validation error" // Enum validates if the data is a member of the enum -func Enum(path, in string, data interface{}, enum interface{}) *errors.Validation { +func Enum(path, in string, data any, enum any) *errors.Validation { return EnumCase(path, in, data, enum, true) } // EnumCase validates if the data is a member of the enum and may respect case-sensitivity for strings -func EnumCase(path, in string, data interface{}, enum interface{}, caseSensitive bool) *errors.Validation { +func EnumCase(path, in string, data any, enum any, caseSensitive bool) *errors.Validation { val := reflect.ValueOf(enum) if val.Kind() != reflect.Slice { return nil } dataString := convertEnumCaseStringKind(data, caseSensitive) - var values []interface{} - for i := 0; i < val.Len(); i++ { + values := make([]any, 0, val.Len()) + for i := range val.Len() { ele := val.Index(i) enumValue := ele.Interface() if data != nil { @@ -78,7 +78,7 @@ func EnumCase(path, in string, data interface{}, enum interface{}, caseSensitive } // convertEnumCaseStringKind converts interface if it is kind of string and case insensitivity is set -func convertEnumCaseStringKind(value interface{}, caseSensitive bool) *string { +func convertEnumCaseStringKind(value any, caseSensitive bool) *string { if caseSensitive { return nil } @@ -109,13 +109,13 @@ func MaxItems(path, in string, size, maximum int64) *errors.Validation { } // UniqueItems validates that the provided slice has unique elements -func UniqueItems(path, in string, data interface{}) *errors.Validation { +func UniqueItems(path, in string, data any) *errors.Validation { val := reflect.ValueOf(data) if val.Kind() != reflect.Slice { return nil } - var unique []interface{} - for i := 0; i < val.Len(); i++ { + unique := make([]any, 0, val.Len()) + for i := range val.Len() { v := val.Index(i).Interface() for _, u := range unique { if reflect.DeepEqual(v, u) { @@ -146,7 +146,7 @@ func MaxLength(path, in, data string, maxLength int64) *errors.Validation { } // ReadOnly validates an interface for readonly -func ReadOnly(ctx context.Context, path, in string, data interface{}) *errors.Validation { +func ReadOnly(ctx context.Context, path, in string, data any) *errors.Validation { // read only is only validated when operationType is request if op := extractOperationType(ctx); op != request { @@ -167,7 +167,7 @@ func ReadOnly(ctx context.Context, path, in string, data interface{}) *errors.Va } // Required validates an interface for requiredness -func Required(path, in string, data interface{}) *errors.Validation { +func Required(path, in string, data any) *errors.Validation { val := reflect.ValueOf(data) if val.IsValid() { if reflect.DeepEqual(reflect.Zero(val.Type()).Interface(), val.Interface()) { @@ -322,7 +322,7 @@ func FormatOf(path, in, format, data string, registry strfmt.Registry) *errors.V // which means there may be a loss during conversions (e.g. for very large integers) // // TODO: Normally, a JSON MAX_SAFE_INTEGER check would ensure conversion remains loss-free -func MaximumNativeType(path, in string, val interface{}, maximum float64, exclusive bool) *errors.Validation { +func MaximumNativeType(path, in string, val any, maximum float64, exclusive bool) *errors.Validation { kind := reflect.ValueOf(val).Type().Kind() switch kind { //nolint:exhaustive case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -352,7 +352,7 @@ func MaximumNativeType(path, in string, val interface{}, maximum float64, exclus // which means there may be a loss during conversions (e.g. for very large integers) // // TODO: Normally, a JSON MAX_SAFE_INTEGER check would ensure conversion remains loss-free -func MinimumNativeType(path, in string, val interface{}, minimum float64, exclusive bool) *errors.Validation { +func MinimumNativeType(path, in string, val any, minimum float64, exclusive bool) *errors.Validation { kind := reflect.ValueOf(val).Type().Kind() switch kind { //nolint:exhaustive case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -382,7 +382,7 @@ func MinimumNativeType(path, in string, val interface{}, minimum float64, exclus // which means there may be a loss during conversions (e.g. for very large integers) // // TODO: Normally, a JSON MAX_SAFE_INTEGER check would ensure conversion remains loss-free -func MultipleOfNativeType(path, in string, val interface{}, multipleOf float64) *errors.Validation { +func MultipleOfNativeType(path, in string, val any, multipleOf float64) *errors.Validation { kind := reflect.ValueOf(val).Type().Kind() switch kind { //nolint:exhaustive case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: @@ -403,7 +403,7 @@ func MultipleOfNativeType(path, in string, val interface{}, multipleOf float64) // the range defined by Type and Format, that is, may be converted without loss. // // NOTE: this check is about type capacity and not formal verification such as: 1.0 != 1L -func IsValueValidAgainstRange(val interface{}, typeName, format, prefix, path string) error { +func IsValueValidAgainstRange(val any, typeName, format, prefix, path string) error { kind := reflect.ValueOf(val).Type().Kind() // What is the string representation of val