diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index b4009db..9420058 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -8,11 +8,11 @@ permissions: jobs: dependabot: runs-on: ubuntu-latest - if: github.actor == 'dependabot[bot]' + if: github.event.pull_request.user.login == 'dependabot[bot]' steps: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1 + uses: dependabot/fetch-metadata@v2 - name: Auto-approve all dependabot PRs run: gh pr review --approve "$PR_URL" diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index e1c413e..20b3d31 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -21,7 +21,7 @@ jobs: check-latest: true cache: true - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: version: latest only-new-issues: true @@ -37,22 +37,21 @@ jobs: go_version: ['oldstable', 'stable' ] steps: - - name: Run unit tests - uses: actions/setup-go@v5 + - uses: actions/setup-go@v5 with: go-version: '${{ matrix.go_version }}' check-latest: true cache: true - uses: actions/checkout@v4 - - - run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic -coverpkg=$(go list)/... ./... + - name: Run unit tests + shell: bash + run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic -coverpkg=$(go list)/... ./... - name: Upload coverage to codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out' - flags: '${{ matrix.go_version }}' - os: '${{ matrix.os }}' + flags: '${{ matrix.go_version }}-${{ matrix.os }}' fail_ci_if_error: false verbose: true diff --git a/.golangci.yml b/.golangci.yml index cf88ead..ee8b9bd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,6 @@ linters-settings: - govet: - check-shadowing: true - golint: - min-confidence: 0 gocyclo: min-complexity: 45 - maligned: - suggest-new: true dupl: threshold: 200 goconst: @@ -16,8 +10,6 @@ linters-settings: linters: enable-all: true disable: - - errname # this repo doesn't follow the convention advised by this linter - - maligned - unparam - lll - gochecknoinits @@ -30,9 +22,6 @@ linters: - wrapcheck - testpackage - nlreturn - - gomnd - - exhaustivestruct - - goerr113 - errorlint - nestif - godot @@ -40,7 +29,6 @@ linters: - paralleltest - tparallel - thelper - - ifshort - exhaustruct - varnamelen - gci @@ -53,10 +41,15 @@ linters: - forcetypeassert - cyclop # deprecated linters - - deadcode - - interfacer - - scopelint - - varcheck - - structcheck - - golint - - nosnakecase + #- deadcode + #- interfacer + #- scopelint + #- varcheck + #- structcheck + #- golint + #- nosnakecase + #- maligned + #- goerr113 + #- ifshort + #- gomnd + #- exhaustivestruct diff --git a/api.go b/api.go index 5320cb9..d6f507f 100644 --- a/api.go +++ b/api.go @@ -185,7 +185,7 @@ func ServeError(rw http.ResponseWriter, r *http.Request, err error) { } func asHTTPCode(input int) int { - if input >= 600 { + if input >= maximumValidHTTPCode { return DefaultHTTPCode } return input diff --git a/api_test.go b/api_test.go index 0442ff6..94fb08b 100644 --- a/api_test.go +++ b/api_test.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//nolint:err113 package errors import ( @@ -31,120 +32,175 @@ type customError struct { } func TestServeError(t *testing.T) { - // method not allowed wins - // err abides by the Error interface - err := MethodNotAllowed("GET", []string{"POST", "PUT"}) - recorder := httptest.NewRecorder() - ServeError(recorder, nil, err) - assert.Equal(t, http.StatusMethodNotAllowed, recorder.Code) - assert.Equal(t, "POST,PUT", recorder.Header().Get("Allow")) - // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) - assert.Equal(t, `{"code":405,"message":"method GET is not allowed, but [POST,PUT] are"}`, recorder.Body.String()) - - // renders status code from error when present - err = NotFound("") - recorder = httptest.NewRecorder() - ServeError(recorder, nil, err) - assert.Equal(t, http.StatusNotFound, recorder.Code) - // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) - assert.Equal(t, `{"code":404,"message":"Not found"}`, recorder.Body.String()) - - // renders mapped status code from error when present - err = InvalidTypeName("someType") - recorder = httptest.NewRecorder() - ServeError(recorder, nil, err) - assert.Equal(t, http.StatusUnprocessableEntity, 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()) - - // same, but override DefaultHTTPCode - func() { - oldDefaultHTTPCode := DefaultHTTPCode - defer func() { DefaultHTTPCode = oldDefaultHTTPCode }() - DefaultHTTPCode = http.StatusBadRequest - - err = InvalidTypeName("someType") - recorder = httptest.NewRecorder() + t.Run("method not allowed wins", func(t *testing.T) { + // err abides by the Error interface + err := MethodNotAllowed("GET", []string{"POST", "PUT"}) + require.Error(t, err) + + recorder := httptest.NewRecorder() + ServeError(recorder, nil, err) + assert.Equal(t, http.StatusMethodNotAllowed, recorder.Code) + assert.Equal(t, "POST,PUT", recorder.Header().Get("Allow")) + // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) + assert.JSONEq(t, + `{"code":405,"message":"method GET is not allowed, but [POST,PUT] are"}`, + recorder.Body.String(), + ) + }) + + t.Run("renders status code from error", func(t *testing.T) { + err := NotFound("") + require.Error(t, err) + + recorder := httptest.NewRecorder() + ServeError(recorder, nil, err) + assert.Equal(t, http.StatusNotFound, recorder.Code) + // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) + assert.JSONEq(t, + `{"code":404,"message":"Not found"}`, + recorder.Body.String(), + ) + }) + + t.Run("renders mapped status code from error", func(t *testing.T) { + // renders mapped status code from error when present + err := InvalidTypeName("someType") + require.Error(t, err) + + recorder := httptest.NewRecorder() ServeError(recorder, nil, err) - assert.Equal(t, http.StatusBadRequest, recorder.Code) + assert.Equal(t, http.StatusUnprocessableEntity, 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 := errors.New("some error") - recorder = httptest.NewRecorder() - ServeError(recorder, nil, simpleErr) - assert.Equal(t, http.StatusInternalServerError, recorder.Code) - // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) - assert.Equal(t, `{"code":500,"message":"some error"}`, recorder.Body.String()) - - // composite errors - - // unrecognized: return internal error with first error only - the second error is ignored - compositeErr := &CompositeError{ - Errors: []error{ - errors.New("firstError"), - errors.New("anotherError"), - }, - } - recorder = httptest.NewRecorder() - ServeError(recorder, nil, compositeErr) - assert.Equal(t, http.StatusInternalServerError, recorder.Code) - assert.Equal(t, `{"code":500,"message":"firstError"}`, recorder.Body.String()) - - // recognized: return internal error with first error only - the second error is ignored - compositeErr = &CompositeError{ - Errors: []error{ - New(600, "myApiError"), - New(601, "myOtherApiError"), - }, - } - recorder = httptest.NewRecorder() - ServeError(recorder, nil, compositeErr) - assert.Equal(t, CompositeErrorCode, recorder.Code) - assert.Equal(t, `{"code":600,"message":"myApiError"}`, recorder.Body.String()) - - // recognized API Error, flattened - compositeErr = &CompositeError{ - Errors: []error{ - &CompositeError{ + assert.JSONEq(t, + `{"code":601,"message":"someType is an invalid type name"}`, + recorder.Body.String(), + ) + }) + + t.Run("overrides DefaultHTTPCode", func(t *testing.T) { + func() { + oldDefaultHTTPCode := DefaultHTTPCode + defer func() { DefaultHTTPCode = oldDefaultHTTPCode }() + DefaultHTTPCode = http.StatusBadRequest + + err := InvalidTypeName("someType") + require.Error(t, err) + + 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.JSONEq(t, + `{"code":601,"message":"someType is an invalid type name"}`, + recorder.Body.String(), + ) + }() + }) + + t.Run("defaults to internal server error", func(t *testing.T) { + simpleErr := errors.New("some error") + recorder := httptest.NewRecorder() + ServeError(recorder, nil, simpleErr) + assert.Equal(t, http.StatusInternalServerError, recorder.Code) + // assert.Equal(t, "application/json", recorder.Header().Get("content-type")) + assert.JSONEq(t, + `{"code":500,"message":"some error"}`, + recorder.Body.String(), + ) + }) + + t.Run("with composite erors", func(t *testing.T) { + t.Run("unrecognized - return internal error with first error only - the second error is ignored", func(t *testing.T) { + compositeErr := &CompositeError{ + Errors: []error{ + errors.New("firstError"), + errors.New("anotherError"), + }, + } + recorder := httptest.NewRecorder() + ServeError(recorder, nil, compositeErr) + assert.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.JSONEq(t, + `{"code":500,"message":"firstError"}`, + recorder.Body.String(), + ) + }) + + t.Run("recognized - return internal error with first error only - the second error is ignored", func(t *testing.T) { + compositeErr := &CompositeError{ Errors: []error{ New(600, "myApiError"), New(601, "myOtherApiError"), }, - }, - }, - } - recorder = httptest.NewRecorder() - ServeError(recorder, nil, compositeErr) - assert.Equal(t, CompositeErrorCode, recorder.Code) - assert.Equal(t, `{"code":600,"message":"myApiError"}`, recorder.Body.String()) - - // check guard against empty CompositeError (e.g. nil Error interface) - compositeErr = &CompositeError{ - Errors: []error{ - &CompositeError{ - Errors: []error{}, - }, - }, - } - recorder = httptest.NewRecorder() - ServeError(recorder, nil, compositeErr) - assert.Equal(t, http.StatusInternalServerError, recorder.Code) - assert.Equal(t, `{"code":500,"message":"Unknown error"}`, recorder.Body.String()) - - // check guard against nil type - recorder = httptest.NewRecorder() - 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()) + } + recorder := httptest.NewRecorder() + ServeError(recorder, nil, compositeErr) + assert.Equal(t, CompositeErrorCode, recorder.Code) + assert.JSONEq(t, + `{"code":600,"message":"myApiError"}`, + recorder.Body.String(), + ) + }) + + t.Run("recognized API Error, flattened", func(t *testing.T) { + compositeErr := &CompositeError{ + Errors: []error{ + &CompositeError{ + Errors: []error{ + New(600, "myApiError"), + New(601, "myOtherApiError"), + }, + }, + }, + } + recorder := httptest.NewRecorder() + ServeError(recorder, nil, compositeErr) + assert.Equal(t, CompositeErrorCode, recorder.Code) + assert.JSONEq(t, + `{"code":600,"message":"myApiError"}`, + recorder.Body.String(), + ) + }) + + // (e.g. nil Error interface) + t.Run("check guard against empty CompositeError", func(t *testing.T) { + compositeErr := &CompositeError{ + Errors: []error{ + &CompositeError{ + Errors: []error{}, + }, + }, + } + recorder := httptest.NewRecorder() + ServeError(recorder, nil, compositeErr) + assert.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.JSONEq(t, + `{"code":500,"message":"Unknown error"}`, + recorder.Body.String(), + ) + }) + + t.Run("check guard against nil type", func(t *testing.T) { + recorder := httptest.NewRecorder() + ServeError(recorder, nil, nil) + assert.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.JSONEq(t, + `{"code":500,"message":"Unknown error"}`, + recorder.Body.String(), + ) + }) + + t.Run("check guard against nil value", func(t *testing.T) { + recorder := httptest.NewRecorder() + var z *customError + ServeError(recorder, nil, z) + assert.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.JSONEq(t, + `{"code":500,"message":"Unknown error"}`, + recorder.Body.String(), + ) + }) + }) } func TestAPIErrors(t *testing.T) { diff --git a/go.mod b/go.mod index 51d80cb..347e5b5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/go-openapi/errors -require github.com/stretchr/testify v1.9.0 +require github.com/stretchr/testify v1.10.0 require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 8c3a72f..39a9715 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb 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/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 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= diff --git a/headers.go b/headers.go index dfebe8f..6ea1151 100644 --- a/headers.go +++ b/headers.go @@ -21,7 +21,7 @@ import ( ) // Validation represents a failure of a precondition -type Validation struct { +type Validation struct { //nolint: errname code int32 Name string In string diff --git a/middleware.go b/middleware.go index 963472d..67f8038 100644 --- a/middleware.go +++ b/middleware.go @@ -22,7 +22,7 @@ import ( // 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 { +type APIVerificationFailed struct { //nolint: errname Section string `json:"section,omitempty"` MissingSpecification []string `json:"missingSpecification,omitempty"` MissingRegistration []string `json:"missingRegistration,omitempty"` diff --git a/parsing.go b/parsing.go index 5096e1e..ce1ef9c 100644 --- a/parsing.go +++ b/parsing.go @@ -17,6 +17,7 @@ package errors import ( "encoding/json" "fmt" + "net/http" ) // ParseError represents a parsing error @@ -68,7 +69,7 @@ func NewParseError(name, in, value string, reason error) *ParseError { msg = fmt.Sprintf(parseErrorTemplContent, name, in, value, reason) } return &ParseError{ - code: 400, + code: http.StatusBadRequest, Name: name, In: in, Value: value, diff --git a/parsing_test.go b/parsing_test.go index a51f773..d8eef31 100644 --- a/parsing_test.go +++ b/parsing_test.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//nolint:err113 package errors import ( diff --git a/schema.go b/schema.go index cf7ac2e..8f3239d 100644 --- a/schema.go +++ b/schema.go @@ -17,6 +17,7 @@ package errors import ( "encoding/json" "fmt" + "net/http" "strings" ) @@ -32,12 +33,12 @@ const ( patternFail = "%s in %s should match '%s'" enumFail = "%s in %s should be one of %v" multipleOfFail = "%s in %s should be a multiple of %v" - maxIncFail = "%s in %s should be less than or equal to %v" - maxExcFail = "%s in %s should be less than %v" + maximumIncFail = "%s in %s should be less than or equal to %v" + maximumExcFail = "%s in %s should be less than %v" minIncFail = "%s in %s should be greater than or equal to %v" minExcFail = "%s in %s should be greater than %v" uniqueFail = "%s in %s shouldn't contain duplicates" - maxItemsFail = "%s in %s should have at most %d items" + maximumItemsFail = "%s in %s should have at most %d items" minItemsFail = "%s in %s should have at least %d items" typeFailNoIn = "%s must be of type %s" typeFailWithDataNoIn = "%s must be of type %s: %q" @@ -49,12 +50,12 @@ const ( patternFailNoIn = "%s should match '%s'" enumFailNoIn = "%s should be one of %v" multipleOfFailNoIn = "%s should be a multiple of %v" - maxIncFailNoIn = "%s should be less than or equal to %v" - maxExcFailNoIn = "%s should be less than %v" + maximumIncFailNoIn = "%s should be less than or equal to %v" + maximumExcFailNoIn = "%s should be less than %v" minIncFailNoIn = "%s should be greater than or equal to %v" minExcFailNoIn = "%s should be greater than %v" uniqueFailNoIn = "%s shouldn't contain duplicates" - maxItemsFailNoIn = "%s should have at most %d items" + maximumItemsFailNoIn = "%s should have at most %d items" minItemsFailNoIn = "%s should have at least %d items" noAdditionalItems = "%s in %s can't have additional items" noAdditionalItemsNoIn = "%s can't have additional items" @@ -69,14 +70,17 @@ const ( multipleOfMustBePositive = "factor MultipleOf declared for %s must be positive: %v" ) +const maximumValidHTTPCode = 600 + // All code responses can be used to differentiate errors for different handling // by the consuming program const ( // CompositeErrorCode remains 422 for backwards-compatibility // and to separate it from validation errors with cause - CompositeErrorCode = 422 + CompositeErrorCode = http.StatusUnprocessableEntity + // InvalidTypeCode is used for any subclass of invalid types - InvalidTypeCode = 600 + iota + InvalidTypeCode = maximumValidHTTPCode + iota RequiredFailCode TooLongFailCode TooShortFailCode @@ -298,10 +302,10 @@ func DuplicateItems(name, in string) *Validation { } // TooManyItems error for when an array contains too many items -func TooManyItems(name, in string, max int64, value interface{}) *Validation { - msg := fmt.Sprintf(maxItemsFail, name, in, max) +func TooManyItems(name, in string, maximum int64, value interface{}) *Validation { + msg := fmt.Sprintf(maximumItemsFail, name, in, maximum) if in == "" { - msg = fmt.Sprintf(maxItemsFailNoIn, name, max) + msg = fmt.Sprintf(maximumItemsFailNoIn, name, maximum) } return &Validation{ @@ -314,10 +318,10 @@ func TooManyItems(name, in string, max int64, value interface{}) *Validation { } // TooFewItems error for when an array contains too few items -func TooFewItems(name, in string, min int64, value interface{}) *Validation { - msg := fmt.Sprintf(minItemsFail, name, in, min) +func TooFewItems(name, in string, minimum int64, value interface{}) *Validation { + msg := fmt.Sprintf(minItemsFail, name, in, minimum) if in == "" { - msg = fmt.Sprintf(minItemsFailNoIn, name, min) + msg = fmt.Sprintf(minItemsFailNoIn, name, minimum) } return &Validation{ code: MinItemsFailCode, @@ -328,21 +332,21 @@ func TooFewItems(name, in string, min int64, value interface{}) *Validation { } } -// ExceedsMaximumInt error for when maximum validation fails -func ExceedsMaximumInt(name, in string, max int64, exclusive bool, value interface{}) *Validation { +// ExceedsMaximumInt error for when maximumimum validation fails +func ExceedsMaximumInt(name, in string, maximum int64, exclusive bool, value interface{}) *Validation { var message string if in == "" { - m := maxIncFailNoIn + m := maximumIncFailNoIn if exclusive { - m = maxExcFailNoIn + m = maximumExcFailNoIn } - message = fmt.Sprintf(m, name, max) + message = fmt.Sprintf(m, name, maximum) } else { - m := maxIncFail + m := maximumIncFail if exclusive { - m = maxExcFail + m = maximumExcFail } - message = fmt.Sprintf(m, name, in, max) + message = fmt.Sprintf(m, name, in, maximum) } return &Validation{ code: MaxFailCode, @@ -353,21 +357,21 @@ func ExceedsMaximumInt(name, in string, max int64, exclusive bool, value interfa } } -// ExceedsMaximumUint error for when maximum validation fails -func ExceedsMaximumUint(name, in string, max uint64, exclusive bool, value interface{}) *Validation { +// ExceedsMaximumUint error for when maximumimum validation fails +func ExceedsMaximumUint(name, in string, maximum uint64, exclusive bool, value interface{}) *Validation { var message string if in == "" { - m := maxIncFailNoIn + m := maximumIncFailNoIn if exclusive { - m = maxExcFailNoIn + m = maximumExcFailNoIn } - message = fmt.Sprintf(m, name, max) + message = fmt.Sprintf(m, name, maximum) } else { - m := maxIncFail + m := maximumIncFail if exclusive { - m = maxExcFail + m = maximumExcFail } - message = fmt.Sprintf(m, name, in, max) + message = fmt.Sprintf(m, name, in, maximum) } return &Validation{ code: MaxFailCode, @@ -378,21 +382,21 @@ func ExceedsMaximumUint(name, in string, max uint64, exclusive bool, value inter } } -// ExceedsMaximum error for when maximum validation fails -func ExceedsMaximum(name, in string, max float64, exclusive bool, value interface{}) *Validation { +// ExceedsMaximum error for when maximumimum validation fails +func ExceedsMaximum(name, in string, maximum float64, exclusive bool, value interface{}) *Validation { var message string if in == "" { - m := maxIncFailNoIn + m := maximumIncFailNoIn if exclusive { - m = maxExcFailNoIn + m = maximumExcFailNoIn } - message = fmt.Sprintf(m, name, max) + message = fmt.Sprintf(m, name, maximum) } else { - m := maxIncFail + m := maximumIncFail if exclusive { - m = maxExcFail + m = maximumExcFail } - message = fmt.Sprintf(m, name, in, max) + message = fmt.Sprintf(m, name, in, maximum) } return &Validation{ code: MaxFailCode, @@ -404,20 +408,20 @@ func ExceedsMaximum(name, in string, max float64, exclusive bool, value interfac } // ExceedsMinimumInt error for when minimum validation fails -func ExceedsMinimumInt(name, in string, min int64, exclusive bool, value interface{}) *Validation { +func ExceedsMinimumInt(name, in string, minimum int64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := minIncFailNoIn if exclusive { m = minExcFailNoIn } - message = fmt.Sprintf(m, name, min) + message = fmt.Sprintf(m, name, minimum) } else { m := minIncFail if exclusive { m = minExcFail } - message = fmt.Sprintf(m, name, in, min) + message = fmt.Sprintf(m, name, in, minimum) } return &Validation{ code: MinFailCode, @@ -429,20 +433,20 @@ func ExceedsMinimumInt(name, in string, min int64, exclusive bool, value interfa } // ExceedsMinimumUint error for when minimum validation fails -func ExceedsMinimumUint(name, in string, min uint64, exclusive bool, value interface{}) *Validation { +func ExceedsMinimumUint(name, in string, minimum uint64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := minIncFailNoIn if exclusive { m = minExcFailNoIn } - message = fmt.Sprintf(m, name, min) + message = fmt.Sprintf(m, name, minimum) } else { m := minIncFail if exclusive { m = minExcFail } - message = fmt.Sprintf(m, name, in, min) + message = fmt.Sprintf(m, name, in, minimum) } return &Validation{ code: MinFailCode, @@ -454,20 +458,20 @@ func ExceedsMinimumUint(name, in string, min uint64, exclusive bool, value inter } // ExceedsMinimum error for when minimum validation fails -func ExceedsMinimum(name, in string, min float64, exclusive bool, value interface{}) *Validation { +func ExceedsMinimum(name, in string, minimum float64, exclusive bool, value interface{}) *Validation { var message string if in == "" { m := minIncFailNoIn if exclusive { m = minExcFailNoIn } - message = fmt.Sprintf(m, name, min) + message = fmt.Sprintf(m, name, minimum) } else { m := minIncFail if exclusive { m = minExcFail } - message = fmt.Sprintf(m, name, in, min) + message = fmt.Sprintf(m, name, in, minimum) } return &Validation{ code: MinFailCode, @@ -549,12 +553,12 @@ func ReadOnly(name, in string, value interface{}) *Validation { } // TooLong error for when a string is too long -func TooLong(name, in string, max int64, value interface{}) *Validation { +func TooLong(name, in string, maximum int64, value interface{}) *Validation { var msg string if in == "" { - msg = fmt.Sprintf(tooLongMessageNoIn, name, max) + msg = fmt.Sprintf(tooLongMessageNoIn, name, maximum) } else { - msg = fmt.Sprintf(tooLongMessage, name, in, max) + msg = fmt.Sprintf(tooLongMessage, name, in, maximum) } return &Validation{ code: TooLongFailCode, @@ -566,12 +570,12 @@ func TooLong(name, in string, max int64, value interface{}) *Validation { } // TooShort error for when a string is too short -func TooShort(name, in string, min int64, value interface{}) *Validation { +func TooShort(name, in string, minimum int64, value interface{}) *Validation { var msg string if in == "" { - msg = fmt.Sprintf(tooShortMessageNoIn, name, min) + msg = fmt.Sprintf(tooShortMessageNoIn, name, minimum) } else { - msg = fmt.Sprintf(tooShortMessage, name, in, min) + msg = fmt.Sprintf(tooShortMessage, name, in, minimum) } return &Validation{ diff --git a/schema_test.go b/schema_test.go index 0d7e9c4..162c69e 100644 --- a/schema_test.go +++ b/schema_test.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//nolint:err113 package errors import (