diff -Nru golang-github-go-openapi-errors-0.15.0/api.go golang-github-go-openapi-errors-0.20.1/api.go --- golang-github-go-openapi-errors-0.15.0/api.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/api.go 2021-08-23 19:50:04.000000000 +0000 @@ -18,9 +18,13 @@ "encoding/json" "fmt" "net/http" + "reflect" "strings" ) +// DefaultHTTPCode is used when the error Code cannot be used as an HTTP code. +var DefaultHTTPCode = http.StatusUnprocessableEntity + // Error represents a error interface all swagger framework errors implement type Error interface { error @@ -40,6 +44,14 @@ return a.code } +// MarshalJSON implements the JSON encoding interface +func (a apiError) MarshalJSON() ([]byte, error) { + return json.Marshal(map[string]interface{}{ + "code": a.code, + "message": a.message, + }) +} + // New creates a new API error with a code and a message func New(code int32, message string, args ...interface{}) Error { if len(args) > 0 { @@ -77,6 +89,15 @@ return m.code } +// MarshalJSON implements the JSON encoding interface +func (m MethodNotAllowedError) MarshalJSON() ([]byte, error) { + return json.Marshal(map[string]interface{}{ + "code": m.code, + "message": m.message, + "allowed": m.Allowed, + }) +} + func errorAsJSON(err Error) []byte { b, _ := json.Marshal(struct { Code int32 `json:"code"` @@ -111,8 +132,6 @@ return &MethodNotAllowedError{code: http.StatusMethodNotAllowed, Allowed: allow, message: msg} } -const head = "HEAD" - // ServeError the error handler interface implementation func ServeError(rw http.ResponseWriter, r *http.Request, err error) { rw.Header().Set("Content-Type", "application/json") @@ -129,33 +148,34 @@ case *MethodNotAllowedError: rw.Header().Add("Allow", strings.Join(err.(*MethodNotAllowedError).Allowed, ",")) rw.WriteHeader(asHTTPCode(int(e.Code()))) - if r == nil || r.Method != head { - rw.Write(errorAsJSON(e)) + if r == nil || r.Method != http.MethodHead { + _, _ = rw.Write(errorAsJSON(e)) } case Error: - if e == nil { + value := reflect.ValueOf(e) + if value.Kind() == reflect.Ptr && value.IsNil() { rw.WriteHeader(http.StatusInternalServerError) - rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) + _, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) return } rw.WriteHeader(asHTTPCode(int(e.Code()))) - if r == nil || r.Method != head { - rw.Write(errorAsJSON(e)) + if r == nil || r.Method != http.MethodHead { + _, _ = rw.Write(errorAsJSON(e)) } case nil: rw.WriteHeader(http.StatusInternalServerError) - rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) + _, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) default: rw.WriteHeader(http.StatusInternalServerError) - if r == nil || r.Method != head { - rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error()))) + if r == nil || r.Method != http.MethodHead { + _, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error()))) } } } func asHTTPCode(input int) int { if input >= 600 { - return 422 + return DefaultHTTPCode } return input } diff -Nru golang-github-go-openapi-errors-0.15.0/api_test.go golang-github-go-openapi-errors-0.20.1/api_test.go --- golang-github-go-openapi-errors-0.15.0/api_test.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/api_test.go 2021-08-23 19:50:04.000000000 +0000 @@ -18,11 +18,17 @@ "fmt" "net/http" "net/http/httptest" + "strings" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +type customError struct { + apiError +} + func TestServeError(t *testing.T) { // method not allowed wins // err abides by the Error interface @@ -50,6 +56,20 @@ // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) assert.Equal(t, `{"code":601,"message":"someType is an invalid type name"}`, recorder.Body.String()) + // same, but override DefaultHTTPCode + func() { + oldDefaultHTTPCode := DefaultHTTPCode + defer func() { DefaultHTTPCode = oldDefaultHTTPCode }() + DefaultHTTPCode = http.StatusBadRequest + + err = InvalidTypeName("someType") + recorder = httptest.NewRecorder() + ServeError(recorder, nil, err) + assert.Equal(t, http.StatusBadRequest, recorder.Code) + // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) + assert.Equal(t, `{"code":601,"message":"someType is an invalid type name"}`, recorder.Body.String()) + }() + // defaults to internal server error simpleErr := fmt.Errorf("some error") recorder = httptest.NewRecorder() @@ -118,6 +138,12 @@ ServeError(recorder, nil, nil) assert.Equal(t, http.StatusInternalServerError, recorder.Code) assert.Equal(t, `{"code":500,"message":"Unknown error"}`, recorder.Body.String()) + + recorder = httptest.NewRecorder() + var z *customError + ServeError(recorder, nil, z) + assert.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.Equal(t, `{"code":500,"message":"Unknown error"}`, recorder.Body.String()) } func TestAPIErrors(t *testing.T) { @@ -182,3 +208,44 @@ assert.EqualValues(t, "myNewName", vv.Name) assert.EqualValues(t, "myNewNamemyMessage", vv.message) } + +func TestMarshalJSON(t *testing.T) { + const ( + expectedCode = http.StatusUnsupportedMediaType + value = "myValue" + ) + list := []string{"a", "b"} + + e := InvalidContentType(value, list) + + jazon, err := e.MarshalJSON() + require.NoError(t, err) + + expectedMessage := strings.ReplaceAll(fmt.Sprintf(contentTypeFail, value, list), `"`, `\"`) + + expectedJSON := fmt.Sprintf( + `{"code":%d,"message":"%s","name":"Content-Type","in":"header","value":"%s","values":["a","b"]}`, + expectedCode, expectedMessage, value, + ) + assert.JSONEq(t, expectedJSON, string(jazon)) + + a := apiError{code: 1, message: "a"} + jazon, err = a.MarshalJSON() + require.NoError(t, err) + assert.JSONEq(t, `{"code":1,"message":"a"}`, string(jazon)) + + m := MethodNotAllowedError{code: 1, message: "a", Allowed: []string{"POST"}} + jazon, err = m.MarshalJSON() + require.NoError(t, err) + assert.JSONEq(t, `{"code":1,"message":"a","allowed":["POST"]}`, string(jazon)) + + c := CompositeError{Errors: []error{e}, code: 1, message: "a"} + jazon, err = c.MarshalJSON() + require.NoError(t, err) + assert.JSONEq(t, fmt.Sprintf(`{"code":1,"message":"a","errors":[%s]}`, expectedJSON), string(jazon)) + + p := ParseError{code: 1, message: "x", Name: "a", In: "b", Value: "c", Reason: fmt.Errorf("d")} + jazon, err = p.MarshalJSON() + require.NoError(t, err) + assert.JSONEq(t, `{"code":1,"message":"x","name":"a","in":"b","value":"c","reason":"d"}`, string(jazon)) +} diff -Nru golang-github-go-openapi-errors-0.15.0/auth.go golang-github-go-openapi-errors-0.20.1/auth.go --- golang-github-go-openapi-errors-0.15.0/auth.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/auth.go 2021-08-23 19:50:04.000000000 +0000 @@ -14,7 +14,9 @@ package errors +import "net/http" + // Unauthenticated returns an unauthenticated error func Unauthenticated(scheme string) Error { - return New(401, "unauthenticated for %s", scheme) + return New(http.StatusUnauthorized, "unauthenticated for %s", scheme) } diff -Nru golang-github-go-openapi-errors-0.15.0/debian/changelog golang-github-go-openapi-errors-0.20.1/debian/changelog --- golang-github-go-openapi-errors-0.15.0/debian/changelog 2019-10-29 08:36:28.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/changelog 2021-12-01 13:29:05.000000000 +0000 @@ -1,3 +1,47 @@ +golang-github-go-openapi-errors (0.20.1-3) unstable; urgency=medium + + * Team upload. + * Add Breaks on prometheus-alertmanager (<< 0.22.0~). + * Update debian/watch file. + + -- Guillem Jover Wed, 01 Dec 2021 14:29:05 +0100 + +golang-github-go-openapi-errors (0.20.1-2) unstable; urgency=medium + + * Team upload. + * Set Multi-Arch:foreign for -dev package. + * Lower case first word in package synopsis. + * Update copyright claims. + * Add a Breaks on old golang-github-go-openapi-runtime-dev. + + -- Guillem Jover Mon, 29 Nov 2021 22:56:45 +0100 + +golang-github-go-openapi-errors (0.20.1-1) unstable; urgency=medium + + * Team upload. + + [ Debian Janitor ] + * Set upstream metadata fields: Bug-Database, Bug-Submit, Repository, + Repository-Browse. + + [ Guillem Jover ] + * New upstream release. + * Update Go Team Maintainer address. + * Fix debian/watch syntax. + * Switch to debian/watch format 4. + * Use dh-sequence-golang instead of dh-golang and --with=golang. + * Switch to debhelper-compat level 13. + * Switch Section to golang. + * Switch to Standards-Version 4.6.0 (no changes needed). + * Update gitlab-ci.yml from its canonical source. + * Use _build as build directory. + * Remove unused ${slibs:Depends} from Depends. + * Fix ValidateName tests. + * Update .gitignore files. + * Set Rules-Requires-Root to no. + + -- Guillem Jover Fri, 19 Nov 2021 18:38:23 +0100 + golang-github-go-openapi-errors (0.15.0-1) unstable; urgency=medium * Team upload. diff -Nru golang-github-go-openapi-errors-0.15.0/debian/control golang-github-go-openapi-errors-0.20.1/debian/control --- golang-github-go-openapi-errors-0.15.0/debian/control 2019-10-29 08:36:28.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/control 2021-12-01 13:27:07.000000000 +0000 @@ -1,14 +1,15 @@ Source: golang-github-go-openapi-errors -Maintainer: Debian Go Packaging Team +Maintainer: Debian Go Packaging Team Uploaders: Tim Potter , -Section: devel +Section: golang Testsuite: autopkgtest-pkg-go Priority: optional -Build-Depends: debhelper-compat (= 12), - dh-golang, +Rules-Requires-Root: no +Build-Depends: debhelper-compat (= 13), + dh-sequence-golang, golang-any, golang-github-stretchr-testify-dev, -Standards-Version: 4.4.1 +Standards-Version: 4.6.0 Vcs-Browser: https://salsa.debian.org/go-team/packages/golang-github-go-openapi-errors Vcs-Git: https://salsa.debian.org/go-team/packages/golang-github-go-openapi-errors.git Homepage: https://github.com/go-openapi/errors @@ -16,10 +17,12 @@ Package: golang-github-go-openapi-errors-dev Architecture: all +Multi-Arch: foreign Depends: golang-github-stretchr-testify-dev, ${misc:Depends}, - ${shlibs:Depends}, -Description: Common error handling code for OpenAPI +Breaks: golang-github-go-openapi-runtime-dev (<< 0.19.6~), + prometheus-alertmanager (<< 0.22.0~), +Description: common error handling code for OpenAPI This library implements shared error handling code used throughout the various libraries for the OpenAPI Specification. . diff -Nru golang-github-go-openapi-errors-0.15.0/debian/copyright golang-github-go-openapi-errors-0.20.1/debian/copyright --- golang-github-go-openapi-errors-0.15.0/debian/copyright 2019-10-29 08:36:28.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/copyright 2021-11-23 21:58:02.000000000 +0000 @@ -8,6 +8,7 @@ Files: debian/* Copyright: 2017 Tim Potter + 2021 Sipwise GmbH, Austria License: Apache-2.0 Comment: Debian packaging is licensed under the same terms as upstream diff -Nru golang-github-go-openapi-errors-0.15.0/debian/gitlab-ci.yml golang-github-go-openapi-errors-0.20.1/debian/gitlab-ci.yml --- golang-github-go-openapi-errors-0.15.0/debian/gitlab-ci.yml 2019-10-29 08:36:28.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/gitlab-ci.yml 2021-11-29 17:25:00.000000000 +0000 @@ -1,28 +1,6 @@ - # auto-generated, DO NOT MODIFY. # The authoritative copy of this file lives at: -# https://salsa.debian.org/go-team/ci/blob/master/cmd/ci/gitlabciyml.go - -# TODO: publish under debian-go-team/ci -image: stapelberg/ci2 - -test_the_archive: - artifacts: - paths: - - before-applying-commit.json - - after-applying-commit.json - script: - # Create an overlay to discard writes to /srv/gopath/src after the build: - - "rm -rf /cache/overlay/{upper,work}" - - "mkdir -p /cache/overlay/{upper,work}" - - "mount -t overlay overlay -o lowerdir=/srv/gopath/src,upperdir=/cache/overlay/upper,workdir=/cache/overlay/work /srv/gopath/src" - - "export GOPATH=/srv/gopath" - - "export GOCACHE=/cache/go" - # Build the world as-is: - - "ci-build -exemptions=/var/lib/ci-build/exemptions.json > before-applying-commit.json" - # Copy this package into the overlay: - - "GBP_CONF_FILES=:debian/gbp.conf gbp buildpackage --git-no-pristine-tar --git-ignore-branch --git-ignore-new --git-export-dir=/tmp/export --git-no-overlay --git-tarball-dir=/nonexistant --git-cleaner=/bin/true --git-builder='dpkg-buildpackage -S -d --no-sign'" - - "pgt-gopath -dsc /tmp/export/*.dsc" - # Rebuild the world: - - "ci-build -exemptions=/var/lib/ci-build/exemptions.json > after-applying-commit.json" - - "ci-diff before-applying-commit.json after-applying-commit.json" +# https://salsa.debian.org/go-team/infra/pkg-go-tools/blob/master/config/gitlabciyml.go +--- +include: + - https://salsa.debian.org/go-team/infra/pkg-go-tools/-/raw/master/pipeline/test-archive.yml diff -Nru golang-github-go-openapi-errors-0.15.0/debian/patches/0001-Fix-ValidateName-tests.patch golang-github-go-openapi-errors-0.20.1/debian/patches/0001-Fix-ValidateName-tests.patch --- golang-github-go-openapi-errors-0.15.0/debian/patches/0001-Fix-ValidateName-tests.patch 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/patches/0001-Fix-ValidateName-tests.patch 2021-11-19 19:25:01.000000000 +0000 @@ -0,0 +1,38 @@ +From b45e39dc92fa5448ebf1564c0f4e680f2067cdf5 Mon Sep 17 00:00:00 2001 +From: Guillem Jover +Date: Fri, 19 Nov 2021 19:58:46 +0100 +Subject: [PATCH] Fix ValidateName tests +Forwarded: https://github.com/go-openapi/errors/pull/33 + +This fixes the tests for the #32 PR, which did not update them to match +the implementation changes. + +Signed-off-by: Guillem Jover +--- + api_test.go | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/api_test.go b/api_test.go +index 0e01302..814524c 100644 +--- a/api_test.go ++++ b/api_test.go +@@ -191,12 +191,13 @@ func TestValidateName(t *testing.T) { + assert.EqualValues(t, "myValidation", vv.Name) + assert.EqualValues(t, "myMessage", vv.message) + +- // unchanged ++ // forced + vv = v.ValidateName("myNewName") +- assert.EqualValues(t, "myValidation", vv.Name) +- assert.EqualValues(t, "myMessage", vv.message) ++ assert.EqualValues(t, "myNewName.myValidation", vv.Name) ++ assert.EqualValues(t, "myNewName.myMessage", vv.message) + + v.Name = "" ++ v.message = "myMessage" + + // unchanged + vv = v.ValidateName("") +-- +2.33.1 + diff -Nru golang-github-go-openapi-errors-0.15.0/debian/patches/series golang-github-go-openapi-errors-0.20.1/debian/patches/series --- golang-github-go-openapi-errors-0.15.0/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/patches/series 2021-11-19 19:25:01.000000000 +0000 @@ -0,0 +1 @@ +0001-Fix-ValidateName-tests.patch diff -Nru golang-github-go-openapi-errors-0.15.0/debian/rules golang-github-go-openapi-errors-0.20.1/debian/rules --- golang-github-go-openapi-errors-0.15.0/debian/rules 2019-10-29 08:36:28.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/rules 2021-11-19 19:10:06.000000000 +0000 @@ -1,4 +1,4 @@ #!/usr/bin/make -f %: - dh $@ --buildsystem=golang --with=golang + dh $@ --buildsystem=golang --builddirectory=_build diff -Nru golang-github-go-openapi-errors-0.15.0/debian/upstream/metadata golang-github-go-openapi-errors-0.20.1/debian/upstream/metadata --- golang-github-go-openapi-errors-0.15.0/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/upstream/metadata 2021-11-19 19:10:06.000000000 +0000 @@ -0,0 +1,4 @@ +Bug-Database: https://github.com/go-openapi/errors/issues +Bug-Submit: https://github.com/go-openapi/errors/issues/new +Repository: https://github.com/go-openapi/errors.git +Repository-Browse: https://github.com/go-openapi/errors diff -Nru golang-github-go-openapi-errors-0.15.0/debian/watch golang-github-go-openapi-errors-0.20.1/debian/watch --- golang-github-go-openapi-errors-0.15.0/debian/watch 2019-10-29 08:36:28.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/debian/watch 2021-12-01 13:27:07.000000000 +0000 @@ -1,4 +1,5 @@ -version=3 -opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/golang-github-go-openapi-errors-\$1\.tar\.gz/,\\ -uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/ \\ +version=4 +opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%@PACKAGE@-$1.tar.gz%,\ + uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/$1~$2$3/,\ + dversionmangle=s/\+ds\d*$//,repacksuffix=+ds1" \ https://github.com/go-openapi/errors/tags .*/v?(\d\S*)\.tar\.gz diff -Nru golang-github-go-openapi-errors-0.15.0/.golangci.yml golang-github-go-openapi-errors-0.20.1/.golangci.yml --- golang-github-go-openapi-errors-0.15.0/.golangci.yml 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/.golangci.yml 2021-08-23 19:50:04.000000000 +0000 @@ -0,0 +1,43 @@ +linters-settings: + govet: + check-shadowing: true + golint: + min-confidence: 0 + gocyclo: + min-complexity: 30 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 4 +linters: + enable-all: true + disable: + - maligned + - lll + - gochecknoglobals + - godox + - gocognit + - whitespace + - wsl + - funlen + - gochecknoglobals + - gochecknoinits + - scopelint + - wrapcheck + - exhaustivestruct + - exhaustive + - nlreturn + - testpackage + - gci + - gofumpt + - goerr113 + - gomnd + - tparallel + - nestif + - godot + - errorlint + - paralleltest + - tparallel diff -Nru golang-github-go-openapi-errors-0.15.0/go.mod golang-github-go-openapi-errors-0.20.1/go.mod --- golang-github-go-openapi-errors-0.15.0/go.mod 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/go.mod 2021-08-23 19:50:04.000000000 +0000 @@ -0,0 +1,12 @@ +module github.com/go-openapi/errors + +go 1.14 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/stretchr/testify v1.6.1 + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c // indirect +) diff -Nru golang-github-go-openapi-errors-0.15.0/go.sum golang-github-go-openapi-errors-0.20.1/go.sum --- golang-github-go-openapi-errors-0.15.0/go.sum 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/go.sum 2021-08-23 19:50:04.000000000 +0000 @@ -0,0 +1,26 @@ +github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +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/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= +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/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +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-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo= +gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff -Nru golang-github-go-openapi-errors-0.15.0/headers.go golang-github-go-openapi-errors-0.20.1/headers.go --- golang-github-go-openapi-errors-0.15.0/headers.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/headers.go 2021-08-23 19:50:04.000000000 +0000 @@ -15,6 +15,7 @@ package errors import ( + "encoding/json" "fmt" "net/http" ) @@ -38,11 +39,28 @@ return e.code } -// ValidateName produces an error message name for an aliased property +// MarshalJSON implements the JSON encoding interface +func (e Validation) MarshalJSON() ([]byte, error) { + return json.Marshal(map[string]interface{}{ + "code": e.code, + "message": e.message, + "in": e.In, + "name": e.Name, + "value": e.Value, + "values": e.Values, + }) +} + +// ValidateName sets the name for a validation or updates it for a nested property func (e *Validation) ValidateName(name string) *Validation { - if e.Name == "" && name != "" { - e.Name = name - e.message = name + e.message + if name != "" { + if e.Name == "" { + e.Name = name + e.message = name + e.message + } else { + e.Name = name + "." + e.Name + e.message = name + "." + e.message + } } return e } @@ -54,7 +72,7 @@ // InvalidContentType error for an invalid content type func InvalidContentType(value string, allowed []string) *Validation { - var values []interface{} + values := make([]interface{}, 0, len(allowed)) for _, v := range allowed { values = append(values, v) } @@ -70,7 +88,7 @@ // InvalidResponseFormat error for an unacceptable response format request func InvalidResponseFormat(value string, allowed []string) *Validation { - var values []interface{} + values := make([]interface{}, 0, len(allowed)) for _, v := range allowed { values = append(values, v) } diff -Nru golang-github-go-openapi-errors-0.15.0/middleware.go golang-github-go-openapi-errors-0.20.1/middleware.go --- golang-github-go-openapi-errors-0.15.0/middleware.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/middleware.go 2021-08-23 19:50:04.000000000 +0000 @@ -23,9 +23,9 @@ // APIVerificationFailed is an error that contains all the missing info for a mismatched section // between the api registrations and the api spec type APIVerificationFailed struct { - Section string - MissingSpecification []string - MissingRegistration []string + Section string `json:"section,omitempty"` + MissingSpecification []string `json:"missingSpecification,omitempty"` + MissingRegistration []string `json:"missingRegistration,omitempty"` } // diff -Nru golang-github-go-openapi-errors-0.15.0/parsing.go golang-github-go-openapi-errors-0.20.1/parsing.go --- golang-github-go-openapi-errors-0.15.0/parsing.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/parsing.go 2021-08-23 19:50:04.000000000 +0000 @@ -14,9 +14,12 @@ package errors -import "fmt" +import ( + "encoding/json" + "fmt" +) -// ParseError respresents a parsing error +// ParseError represents a parsing error type ParseError struct { code int32 Name string @@ -35,6 +38,22 @@ return e.code } +// MarshalJSON implements the JSON encoding interface +func (e ParseError) MarshalJSON() ([]byte, error) { + var reason string + if e.Reason != nil { + reason = e.Reason.Error() + } + return json.Marshal(map[string]interface{}{ + "code": e.code, + "message": e.message, + "in": e.In, + "name": e.Name, + "value": e.Value, + "reason": reason, + }) +} + const ( parseErrorTemplContent = `parsing %s %s from %q failed, because %s` parseErrorTemplContentNoIn = `parsing %s from %q failed, because %s` diff -Nru golang-github-go-openapi-errors-0.15.0/README.md golang-github-go-openapi-errors-0.20.1/README.md --- golang-github-go-openapi-errors-0.15.0/README.md 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/README.md 2021-08-23 19:50:04.000000000 +0000 @@ -1,5 +1,11 @@ -# OpenAPI errors [![Build Status](https://travis-ci.org/go-openapi/errors.svg?branch=master)](https://travis-ci.org/go-openapi/errors) [![codecov](https://codecov.io/gh/go-openapi/errors/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/errors) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) +# OpenAPI errors -[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/errors/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/errors?status.svg)](http://godoc.org/github.com/go-openapi/errors) +[![Build Status](https://travis-ci.org/go-openapi/errors.svg?branch=master)](https://travis-ci.org/go-openapi/errors) +[![codecov](https://codecov.io/gh/go-openapi/errors/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/errors) +[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io) +[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/errors/master/LICENSE) +[![Go Reference](https://pkg.go.dev/badge/github.com/go-openapi/errors.svg)](https://pkg.go.dev/github.com/go-openapi/errors) +[![GolangCI](https://golangci.com/badges/github.com/go-openapi/errors.svg)](https://golangci.com) +[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/errors)](https://goreportcard.com/report/github.com/go-openapi/errors) -Shared errors used throughout the various libraries for the go-openapi toolkit \ No newline at end of file +Shared errors and error interface used throughout the various libraries found in the go-openapi toolkit. diff -Nru golang-github-go-openapi-errors-0.15.0/schema.go golang-github-go-openapi-errors-0.20.1/schema.go --- golang-github-go-openapi-errors-0.15.0/schema.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/schema.go 2021-08-23 19:50:04.000000000 +0000 @@ -15,6 +15,7 @@ package errors import ( + "encoding/json" "fmt" "strings" ) @@ -25,6 +26,7 @@ typeFailWithData = "%s in %s must be of type %s: %q" typeFailWithError = "%s in %s must be of type %s, because: %s" requiredFail = "%s in %s is required" + readOnlyFail = "%s in %s is readOnly" tooLongMessage = "%s in %s should be at most %d chars long" tooShortMessage = "%s in %s should be at least %d chars long" patternFail = "%s in %s should match '%s'" @@ -41,6 +43,7 @@ typeFailWithDataNoIn = "%s must be of type %s: %q" typeFailWithErrorNoIn = "%s must be of type %s, because: %s" requiredFailNoIn = "%s is required" + readOnlyFailNoIn = "%s is readOnly" tooLongMessageNoIn = "%s should be at most %d chars long" tooShortMessageNoIn = "%s should be at least %d chars long" patternFailNoIn = "%s should match '%s'" @@ -91,6 +94,7 @@ UnallowedPropertyCode FailedAllPatternPropsCode MultipleOfMustBePositiveCode + ReadOnlyFailCode ) // CompositeError is an error that groups several errors together @@ -116,6 +120,15 @@ return c.message } +// MarshalJSON implements the JSON encoding interface +func (c CompositeError) MarshalJSON() ([]byte, error) { + return json.Marshal(map[string]interface{}{ + "code": c.code, + "message": c.message, + "errors": c.Errors, + }) +} + // CompositeValidationError an error to wrap a bunch of other errors func CompositeValidationError(errors ...error) *CompositeError { return &CompositeError{ @@ -125,6 +138,19 @@ } } +// ValidateName recursively sets the name for all validations or updates them for nested properties +func (c *CompositeError) ValidateName(name string) *CompositeError { + for i, e := range c.Errors { + if ve, ok := e.(*Validation); ok { + c.Errors[i] = ve.ValidateName(name) + } else if ce, ok := e.(*CompositeError); ok { + c.Errors[i] = ce.ValidateName(name) + } + } + + return c +} + // FailedAllPatternProperties an error for when the property doesn't match a pattern func FailedAllPatternProperties(name, in, key string) *Validation { msg := fmt.Sprintf(failedAllPatternProps, name, key, in) @@ -268,7 +294,7 @@ } // TooManyItems error for when an array contains too many items -func TooManyItems(name, in string, max int64) *Validation { +func TooManyItems(name, in string, max int64, value interface{}) *Validation { msg := fmt.Sprintf(maxItemsFail, name, in, max) if in == "" { msg = fmt.Sprintf(maxItemsFailNoIn, name, max) @@ -278,12 +304,13 @@ code: MaxItemsFailCode, Name: name, In: in, + Value: value, message: msg, } } // TooFewItems error for when an array contains too few items -func TooFewItems(name, in string, min int64) *Validation { +func TooFewItems(name, in string, min int64, value interface{}) *Validation { msg := fmt.Sprintf(minItemsFail, name, in, min) if in == "" { msg = fmt.Sprintf(minItemsFailNoIn, name, min) @@ -292,12 +319,13 @@ code: MinItemsFailCode, Name: name, In: in, + Value: value, message: msg, } } -// ExceedsMaximumInt error for when maxinum validation fails -func ExceedsMaximumInt(name, in string, max int64, exclusive bool) *Validation { +// ExceedsMaximumInt error for when maximum validation fails +func ExceedsMaximumInt(name, in string, max int64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := maxIncFailNoIn @@ -316,13 +344,13 @@ code: MaxFailCode, Name: name, In: in, - Value: max, + Value: value, message: message, } } -// ExceedsMaximumUint error for when maxinum validation fails -func ExceedsMaximumUint(name, in string, max uint64, exclusive bool) *Validation { +// ExceedsMaximumUint error for when maximum validation fails +func ExceedsMaximumUint(name, in string, max uint64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := maxIncFailNoIn @@ -341,13 +369,13 @@ code: MaxFailCode, Name: name, In: in, - Value: max, + Value: value, message: message, } } -// ExceedsMaximum error for when maxinum validation fails -func ExceedsMaximum(name, in string, max float64, exclusive bool) *Validation { +// ExceedsMaximum error for when maximum validation fails +func ExceedsMaximum(name, in string, max float64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := maxIncFailNoIn @@ -366,13 +394,13 @@ code: MaxFailCode, Name: name, In: in, - Value: max, + Value: value, message: message, } } -// ExceedsMinimumInt error for when maxinum validation fails -func ExceedsMinimumInt(name, in string, min int64, exclusive bool) *Validation { +// ExceedsMinimumInt error for when minimum validation fails +func ExceedsMinimumInt(name, in string, min int64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := minIncFailNoIn @@ -391,13 +419,13 @@ code: MinFailCode, Name: name, In: in, - Value: min, + Value: value, message: message, } } -// ExceedsMinimumUint error for when maxinum validation fails -func ExceedsMinimumUint(name, in string, min uint64, exclusive bool) *Validation { +// ExceedsMinimumUint error for when minimum validation fails +func ExceedsMinimumUint(name, in string, min uint64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := minIncFailNoIn @@ -416,13 +444,13 @@ code: MinFailCode, Name: name, In: in, - Value: min, + Value: value, message: message, } } -// ExceedsMinimum error for when maxinum validation fails -func ExceedsMinimum(name, in string, min float64, exclusive bool) *Validation { +// ExceedsMinimum error for when minimum validation fails +func ExceedsMinimum(name, in string, min float64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := minIncFailNoIn @@ -441,13 +469,13 @@ code: MinFailCode, Name: name, In: in, - Value: min, + Value: value, message: message, } } // NotMultipleOf error for when multiple of validation fails -func NotMultipleOf(name, in string, multiple interface{}) *Validation { +func NotMultipleOf(name, in string, multiple, value interface{}) *Validation { var msg string if in == "" { msg = fmt.Sprintf(multipleOfFailNoIn, name, multiple) @@ -458,7 +486,7 @@ code: MultipleOfFailCode, Name: name, In: in, - Value: multiple, + Value: value, message: msg, } } @@ -483,7 +511,7 @@ } // Required error for when a value is missing -func Required(name, in string) *Validation { +func Required(name, in string, value interface{}) *Validation { var msg string if in == "" { msg = fmt.Sprintf(requiredFailNoIn, name) @@ -494,12 +522,30 @@ code: RequiredFailCode, Name: name, In: in, + Value: value, + message: msg, + } +} + +// ReadOnly error for when a value is present in request +func ReadOnly(name, in string, value interface{}) *Validation { + var msg string + if in == "" { + msg = fmt.Sprintf(readOnlyFailNoIn, name) + } else { + msg = fmt.Sprintf(readOnlyFail, name, in) + } + return &Validation{ + code: ReadOnlyFailCode, + Name: name, + In: in, + Value: value, message: msg, } } // TooLong error for when a string is too long -func TooLong(name, in string, max int64) *Validation { +func TooLong(name, in string, max int64, value interface{}) *Validation { var msg string if in == "" { msg = fmt.Sprintf(tooLongMessageNoIn, name, max) @@ -510,12 +556,13 @@ code: TooLongFailCode, Name: name, In: in, + Value: value, message: msg, } } // TooShort error for when a string is too short -func TooShort(name, in string, min int64) *Validation { +func TooShort(name, in string, min int64, value interface{}) *Validation { var msg string if in == "" { msg = fmt.Sprintf(tooShortMessageNoIn, name, min) @@ -527,13 +574,14 @@ code: TooShortFailCode, Name: name, In: in, + Value: value, message: msg, } } // FailedPattern error for when a string fails a regex pattern match // the pattern that is returned is the ECMA syntax version of the pattern not the golang version. -func FailedPattern(name, in, pattern string) *Validation { +func FailedPattern(name, in, pattern string, value interface{}) *Validation { var msg string if in == "" { msg = fmt.Sprintf(patternFailNoIn, name, pattern) @@ -545,6 +593,7 @@ code: PatternFailCode, Name: name, In: in, + Value: value, message: msg, } } diff -Nru golang-github-go-openapi-errors-0.15.0/schema_test.go golang-github-go-openapi-errors-0.20.1/schema_test.go --- golang-github-go-openapi-errors-0.15.0/schema_test.go 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/schema_test.go 2021-08-23 19:50:04.000000000 +0000 @@ -63,210 +63,263 @@ assert.EqualValues(t, UniqueFailCode, err.Code()) assert.Equal(t, "uniques shouldn't contain duplicates", err.Error()) - err = TooManyItems("something", "query", 5) + err = TooManyItems("something", "query", 5, 6) assert.Error(t, err) assert.EqualValues(t, MaxItemsFailCode, err.Code()) assert.Equal(t, "something in query should have at most 5 items", err.Error()) + assert.Equal(t, 6, err.Value) - err = TooManyItems("something", "", 5) + err = TooManyItems("something", "", 5, 6) assert.Error(t, err) assert.EqualValues(t, MaxItemsFailCode, err.Code()) assert.Equal(t, "something should have at most 5 items", err.Error()) + assert.Equal(t, 6, err.Value) - err = TooFewItems("something", "", 5) + err = TooFewItems("something", "", 5, 4) assert.Error(t, err) assert.EqualValues(t, MinItemsFailCode, err.Code()) assert.Equal(t, "something should have at least 5 items", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMaximumInt("something", "query", 5, false) + err = ExceedsMaximumInt("something", "query", 5, false, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something in query should be less than or equal to 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximumInt("something", "", 5, false) + err = ExceedsMaximumInt("something", "", 5, false, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something should be less than or equal to 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximumInt("something", "query", 5, true) + err = ExceedsMaximumInt("something", "query", 5, true, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something in query should be less than 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximumInt("something", "", 5, true) + err = ExceedsMaximumInt("something", "", 5, true, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something should be less than 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximumUint("something", "query", 5, false) + err = ExceedsMaximumUint("something", "query", 5, false, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something in query should be less than or equal to 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximumUint("something", "", 5, false) + err = ExceedsMaximumUint("something", "", 5, false, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something should be less than or equal to 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximumUint("something", "query", 5, true) + err = ExceedsMaximumUint("something", "query", 5, true, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something in query should be less than 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximumUint("something", "", 5, true) + err = ExceedsMaximumUint("something", "", 5, true, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something should be less than 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximum("something", "query", 5, false) + err = ExceedsMaximum("something", "query", 5, false, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something in query should be less than or equal to 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximum("something", "", 5, false) + err = ExceedsMaximum("something", "", 5, false, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something should be less than or equal to 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximum("something", "query", 5, true) + err = ExceedsMaximum("something", "query", 5, true, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something in query should be less than 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMaximum("something", "", 5, true) + err = ExceedsMaximum("something", "", 5, true, 6) assert.Error(t, err) assert.EqualValues(t, MaxFailCode, err.Code()) assert.Equal(t, "something should be less than 5", err.Error()) + assert.Equal(t, 6, err.Value) - err = ExceedsMinimumInt("something", "query", 5, false) + err = ExceedsMinimumInt("something", "query", 5, false, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something in query should be greater than or equal to 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimumInt("something", "", 5, false) + err = ExceedsMinimumInt("something", "", 5, false, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something should be greater than or equal to 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimumInt("something", "query", 5, true) + err = ExceedsMinimumInt("something", "query", 5, true, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something in query should be greater than 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimumInt("something", "", 5, true) + err = ExceedsMinimumInt("something", "", 5, true, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something should be greater than 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimumUint("something", "query", 5, false) + err = ExceedsMinimumUint("something", "query", 5, false, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something in query should be greater than or equal to 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimumUint("something", "", 5, false) + err = ExceedsMinimumUint("something", "", 5, false, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something should be greater than or equal to 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimumUint("something", "query", 5, true) + err = ExceedsMinimumUint("something", "query", 5, true, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something in query should be greater than 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimumUint("something", "", 5, true) + err = ExceedsMinimumUint("something", "", 5, true, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something should be greater than 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimum("something", "query", 5, false) + err = ExceedsMinimum("something", "query", 5, false, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something in query should be greater than or equal to 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimum("something", "", 5, false) + err = ExceedsMinimum("something", "", 5, false, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something should be greater than or equal to 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimum("something", "query", 5, true) + err = ExceedsMinimum("something", "query", 5, true, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something in query should be greater than 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = ExceedsMinimum("something", "", 5, true) + err = ExceedsMinimum("something", "", 5, true, 4) assert.Error(t, err) assert.EqualValues(t, MinFailCode, err.Code()) assert.Equal(t, "something should be greater than 5", err.Error()) + assert.Equal(t, 4, err.Value) - err = NotMultipleOf("something", "query", 5) + err = NotMultipleOf("something", "query", 5, 1) assert.Error(t, err) assert.EqualValues(t, MultipleOfFailCode, err.Code()) assert.Equal(t, "something in query should be a multiple of 5", err.Error()) + assert.Equal(t, 1, err.Value) - err = NotMultipleOf("something", "query", float64(5)) + err = NotMultipleOf("something", "query", float64(5), float64(1)) assert.Error(t, err) assert.EqualValues(t, MultipleOfFailCode, err.Code()) assert.Equal(t, "something in query should be a multiple of 5", err.Error()) + assert.Equal(t, float64(1), err.Value) - err = NotMultipleOf("something", "query", uint64(5)) + err = NotMultipleOf("something", "query", uint64(5), uint64(1)) assert.Error(t, err) assert.EqualValues(t, MultipleOfFailCode, err.Code()) assert.Equal(t, "something in query should be a multiple of 5", err.Error()) + assert.Equal(t, uint64(1), err.Value) - err = NotMultipleOf("something", "", 5) + err = NotMultipleOf("something", "", 5, 1) assert.Error(t, err) assert.EqualValues(t, MultipleOfFailCode, err.Code()) assert.Equal(t, "something should be a multiple of 5", err.Error()) + assert.Equal(t, 1, err.Value) err = EnumFail("something", "query", "yada", []interface{}{"hello", "world"}) assert.Error(t, err) assert.EqualValues(t, EnumFailCode, err.Code()) assert.Equal(t, "something in query should be one of [hello world]", err.Error()) + assert.Equal(t, "yada", err.Value) err = EnumFail("something", "", "yada", []interface{}{"hello", "world"}) assert.Error(t, err) assert.EqualValues(t, EnumFailCode, err.Code()) assert.Equal(t, "something should be one of [hello world]", err.Error()) + assert.Equal(t, "yada", err.Value) - err = Required("something", "query") + err = Required("something", "query", nil) assert.Error(t, err) assert.EqualValues(t, RequiredFailCode, err.Code()) assert.Equal(t, "something in query is required", err.Error()) + assert.Equal(t, nil, err.Value) - err = Required("something", "") + err = Required("something", "", nil) assert.Error(t, err) assert.EqualValues(t, RequiredFailCode, err.Code()) assert.Equal(t, "something is required", err.Error()) + assert.Equal(t, nil, err.Value) - err = TooLong("something", "query", 5) + err = ReadOnly("something", "query", nil) + assert.Error(t, err) + assert.EqualValues(t, ReadOnlyFailCode, err.Code()) + assert.Equal(t, "something in query is readOnly", err.Error()) + assert.Equal(t, nil, err.Value) + + err = ReadOnly("something", "", nil) + assert.Error(t, err) + assert.EqualValues(t, ReadOnlyFailCode, err.Code()) + assert.Equal(t, "something is readOnly", err.Error()) + assert.Equal(t, nil, err.Value) + + err = TooLong("something", "query", 5, "abcdef") assert.Error(t, err) assert.EqualValues(t, TooLongFailCode, err.Code()) assert.Equal(t, "something in query should be at most 5 chars long", err.Error()) + assert.Equal(t, "abcdef", err.Value) - err = TooLong("something", "", 5) + err = TooLong("something", "", 5, "abcdef") assert.Error(t, err) assert.EqualValues(t, TooLongFailCode, err.Code()) assert.Equal(t, "something should be at most 5 chars long", err.Error()) + assert.Equal(t, "abcdef", err.Value) - err = TooShort("something", "query", 5) + err = TooShort("something", "query", 5, "a") assert.Error(t, err) assert.EqualValues(t, TooShortFailCode, err.Code()) assert.Equal(t, "something in query should be at least 5 chars long", err.Error()) + assert.Equal(t, "a", err.Value) - err = TooShort("something", "", 5) + err = TooShort("something", "", 5, "a") assert.Error(t, err) assert.EqualValues(t, TooShortFailCode, err.Code()) assert.Equal(t, "something should be at least 5 chars long", err.Error()) + assert.Equal(t, "a", err.Value) - err = FailedPattern("something", "query", "\\d+") + err = FailedPattern("something", "query", "\\d+", "a") assert.Error(t, err) assert.EqualValues(t, PatternFailCode, err.Code()) assert.Equal(t, "something in query should match '\\d+'", err.Error()) + assert.Equal(t, "a", err.Value) - err = FailedPattern("something", "", "\\d+") + err = FailedPattern("something", "", "\\d+", "a") assert.Error(t, err) assert.EqualValues(t, PatternFailCode, err.Code()) assert.Equal(t, "something should match '\\d+'", err.Error()) + assert.Equal(t, "a", err.Value) err = InvalidTypeName("something") assert.Error(t, err) @@ -293,72 +346,74 @@ assert.EqualValues(t, CompositeErrorCode, err2.Code()) assert.Equal(t, "validation failure list", err2.Error()) - err2 = CompositeValidationError(fmt.Errorf("First error"), fmt.Errorf("Second error")) + err2 = CompositeValidationError(fmt.Errorf("first error"), fmt.Errorf("second error")) assert.Error(t, err2) assert.EqualValues(t, CompositeErrorCode, err2.Code()) - assert.Equal(t, "validation failure list:\nFirst error\nSecond error", err2.Error()) + assert.Equal(t, "validation failure list:\nfirst error\nsecond error", err2.Error()) - //func MultipleOfMustBePositive(name, in string, factor interface{}) *Validation { + // func MultipleOfMustBePositive(name, in string, factor interface{}) *Validation { err = MultipleOfMustBePositive("path", "body", float64(-10)) assert.Error(t, err) assert.EqualValues(t, MultipleOfMustBePositiveCode, err.Code()) assert.Equal(t, `factor MultipleOf declared for path must be positive: -10`, err.Error()) + assert.Equal(t, float64(-10), err.Value) err = MultipleOfMustBePositive("path", "body", int64(-10)) assert.Error(t, err) assert.EqualValues(t, MultipleOfMustBePositiveCode, err.Code()) assert.Equal(t, `factor MultipleOf declared for path must be positive: -10`, err.Error()) + assert.Equal(t, int64(-10), err.Value) // func PropertyNotAllowed(name, in, key string) *Validation { err = PropertyNotAllowed("path", "body", "key") assert.Error(t, err) assert.EqualValues(t, UnallowedPropertyCode, err.Code()) - //unallowedProperty = "%s.%s in %s is a forbidden property" + // unallowedProperty = "%s.%s in %s is a forbidden property" assert.Equal(t, "path.key in body is a forbidden property", err.Error()) err = PropertyNotAllowed("path", "", "key") assert.Error(t, err) assert.EqualValues(t, UnallowedPropertyCode, err.Code()) - //unallowedPropertyNoIn = "%s.%s is a forbidden property" + // unallowedPropertyNoIn = "%s.%s is a forbidden property" assert.Equal(t, "path.key is a forbidden property", err.Error()) - //func TooManyProperties(name, in string, n int64) *Validation { + // func TooManyProperties(name, in string, n int64) *Validation { err = TooManyProperties("path", "body", 10) assert.Error(t, err) assert.EqualValues(t, TooManyPropertiesCode, err.Code()) - //tooManyProperties = "%s in %s should have at most %d properties" + // tooManyProperties = "%s in %s should have at most %d properties" assert.Equal(t, "path in body should have at most 10 properties", err.Error()) err = TooManyProperties("path", "", 10) assert.Error(t, err) assert.EqualValues(t, TooManyPropertiesCode, err.Code()) - //tooManyPropertiesNoIn = "%s should have at most %d properties" + // tooManyPropertiesNoIn = "%s should have at most %d properties" assert.Equal(t, "path should have at most 10 properties", err.Error()) err = TooFewProperties("path", "body", 10) // func TooFewProperties(name, in string, n int64) *Validation { assert.Error(t, err) assert.EqualValues(t, TooFewPropertiesCode, err.Code()) - //tooFewProperties = "%s in %s should have at least %d properties" + // tooFewProperties = "%s in %s should have at least %d properties" assert.Equal(t, "path in body should have at least 10 properties", err.Error()) err = TooFewProperties("path", "", 10) // func TooFewProperties(name, in string, n int64) *Validation { assert.Error(t, err) assert.EqualValues(t, TooFewPropertiesCode, err.Code()) - //tooFewPropertiesNoIn = "%s should have at least %d properties" + // tooFewPropertiesNoIn = "%s should have at least %d properties" assert.Equal(t, "path should have at least 10 properties", err.Error()) - //func FailedAllPatternProperties(name, in, key string) *Validation { + // func FailedAllPatternProperties(name, in, key string) *Validation { err = FailedAllPatternProperties("path", "body", "key") assert.Error(t, err) assert.EqualValues(t, FailedAllPatternPropsCode, err.Code()) - //failedAllPatternProps = "%s.%s in %s failed all pattern properties" + // failedAllPatternProps = "%s.%s in %s failed all pattern properties" assert.Equal(t, "path.key in body failed all pattern properties", err.Error()) err = FailedAllPatternProperties("path", "", "key") assert.Error(t, err) assert.EqualValues(t, FailedAllPatternPropsCode, err.Code()) - //failedAllPatternPropsNoIn = "%s.%s failed all pattern properties" + // failedAllPatternPropsNoIn = "%s.%s failed all pattern properties" assert.Equal(t, "path.key failed all pattern properties", err.Error()) } diff -Nru golang-github-go-openapi-errors-0.15.0/.travis.yml golang-github-go-openapi-errors-0.20.1/.travis.yml --- golang-github-go-openapi-errors-0.15.0/.travis.yml 2018-05-15 15:55:15.000000000 +0000 +++ golang-github-go-openapi-errors-0.20.1/.travis.yml 2021-08-23 19:50:04.000000000 +0000 @@ -1,12 +1,30 @@ -language: go -go: -- 1.7 -install: -- go get -u github.com/stretchr/testify/assert -script: -- go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic ./... after_success: - bash <(curl -s https://codecov.io/bash) +go: +- 1.14.x +- 1.x +arch: + - amd64 +jobs: + include: + # only run fast tests on ppc64le + - go: 1.x + arch: ppc64le + script: + - gotestsum -f short-verbose -- ./... + + # include linting job, but only for latest go version and amd64 arch + - go: 1.x + arch: amd64 + install: + go get github.com/golangci/golangci-lint/cmd/golangci-lint + script: + - golangci-lint run --new-from-rev master +install: +- GO111MODULE=off go get -u gotest.tools/gotestsum +language: go notifications: slack: secure: gZGp9NaHxi7zawlXJXKY92BGeDR1x0tbIcTyU5nMKLq0fhIaiEBJEeALwZ4VgqsSv3DytSSF5mLH8fevAM3ixE6hxjKQ+lQuf7V/w3btCN1CSWgoua5LOh1kTnqZQtJuRvO4pzoJcT3bJWBsVZ07VGNVzzJEy/zAKCHFqBUCXShw7QemlLBcYWFNqveTlvDIfCzvouoLnPoXwxEpkjxe9uz/ZKZgAnup/fXjC8RFctmgCnkCyvJTk0Y/fZCsufixJrJhshBWTnlrFCzRmgNkz2d+i1Ls3+MJ5EJJ2Tx/A5S63dL49J1f9Kr0AKHADmulSy8JNzIckKwbyFMYUecrsW+Lsu9DhnVMy1jj5pKsJDLRi2iIU3fXTMWbcyQbXjbbnBO2mPdP3Tzme75y4D9fc8hUPeyqVv2BU26NEbQ7EF2pKJ93OXvci7HlwRBgdJa8j6mP2LEDClcPQW00g7N/OZe0cTOMa8L5AwiBlbArwqt9wv6YLJoTG0wpDhzWsFvbCg5bJxe28Yn3fIDD0Lk1I7iSnBbp/5gzF19jmxqvcT8tHRkDL4xfjbENFTZjA5uB4Z4pj4WSyWQILLV/Jwhe3fi9uQwdviFHfj5pnVrmNUiGSOQL672K5wl2c3E9mGwejvsu2dfEz28n7Y/FUnOpY3/cBS0n27JJaerS0zMKNLE= +script: +- gotestsum -f short-verbose -- -race -coverprofile=coverage.txt -covermode=atomic ./...