From 0fd873706a00640151b48cfda44a410d97197a40 Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Tue, 11 Mar 2025 21:06:19 +0100 Subject: [PATCH] Relint * updated linter config * fixed linting errors Signed-off-by: Frederic BIDON --- .golangci.yml | 31 +++++++--------- contact_info_test.go | 2 +- debug_test.go | 3 +- errors.go | 3 ++ expander.go | 10 +++--- header.go | 16 ++++----- header_test.go | 8 ++--- info_test.go | 34 +++++++++--------- items.go | 16 ++++----- items_test.go | 84 ++++++++++++++++++++++++-------------------- license_test.go | 31 ++++++++-------- parameter.go | 16 ++++----- paths.go | 2 +- ref.go | 3 +- ref_test.go | 2 +- responses.go | 2 +- schema.go | 36 +++++++++---------- swagger.go | 2 +- swagger_test.go | 2 +- validations.go | 12 ++++--- 20 files changed, 167 insertions(+), 148 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 22f8d21..d2fafb8 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,7 +10,7 @@ linters-settings: linters: enable-all: true disable: - - maligned + - recvcheck - unparam - lll - gochecknoinits @@ -29,9 +23,6 @@ linters: - wrapcheck - testpackage - nlreturn - - gomnd - - exhaustivestruct - - goerr113 - errorlint - nestif - godot @@ -39,7 +30,6 @@ linters: - paralleltest - tparallel - thelper - - ifshort - exhaustruct - varnamelen - gci @@ -52,10 +42,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/contact_info_test.go b/contact_info_test.go index fedd81a..4aaddd6 100644 --- a/contact_info_test.go +++ b/contact_info_test.go @@ -38,7 +38,7 @@ var contactInfo = ContactInfo{ContactInfoProps: ContactInfoProps{ func TestIntegrationContactInfo(t *testing.T) { b, err := json.MarshalIndent(contactInfo, "", "\t") require.NoError(t, err) - assert.Equal(t, contactInfoJSON, string(b)) + assert.JSONEq(t, contactInfoJSON, string(b)) actual := ContactInfo{} err = json.Unmarshal([]byte(contactInfoJSON), &actual) diff --git a/debug_test.go b/debug_test.go index c74fc28..50edb18 100644 --- a/debug_test.go +++ b/debug_test.go @@ -27,7 +27,8 @@ var ( ) func TestDebug(t *testing.T) { - tmpFile, _ := os.CreateTemp("", "debug-test") + // usetesting linter disabled until https://github.com/golang/go/issues/71544 is fixed for windows + tmpFile, _ := os.CreateTemp("", "debug-test") //nolint:usetesting tmpName := tmpFile.Name() defer func() { Debug = false diff --git a/errors.go b/errors.go index 6992c7b..718b4ae 100644 --- a/errors.go +++ b/errors.go @@ -16,4 +16,7 @@ var ( // ErrExpandUnsupportedType indicates that $ref expansion is attempted on some invalid type ErrExpandUnsupportedType = errors.New("expand: unsupported type. Input should be of type *Parameter or *Response") + + // ErrSpec is an error raised by the spec package + ErrSpec = errors.New("spec error") ) diff --git a/expander.go b/expander.go index b81a569..df936b3 100644 --- a/expander.go +++ b/expander.go @@ -19,6 +19,8 @@ import ( "fmt" ) +const smallPrealloc = 10 + // ExpandOptions provides options for the spec expander. // // RelativeBase is the path to the root document. This can be a remote URL or a path to a local file. @@ -56,7 +58,7 @@ func ExpandSpec(spec *Swagger, options *ExpandOptions) error { if !options.SkipSchemas { for key, definition := range spec.Definitions { - parentRefs := make([]string, 0, 10) + parentRefs := make([]string, 0, smallPrealloc) parentRefs = append(parentRefs, "#/definitions/"+key) def, err := expandSchema(definition, parentRefs, resolver, specBasePath) @@ -160,7 +162,7 @@ func ExpandSchemaWithBasePath(schema *Schema, cache ResolutionCache, opts *Expan resolver := defaultSchemaLoader(nil, opts, cache, nil) - parentRefs := make([]string, 0, 10) + parentRefs := make([]string, 0, smallPrealloc) s, err := expandSchema(*schema, parentRefs, resolver, opts.RelativeBase) if err != nil { return err @@ -386,7 +388,7 @@ func expandPathItem(pathItem *PathItem, resolver *schemaLoader, basePath string) return nil } - parentRefs := make([]string, 0, 10) + parentRefs := make([]string, 0, smallPrealloc) if err := resolver.deref(pathItem, parentRefs, basePath); resolver.shouldStopOnError(err) { return err } @@ -546,7 +548,7 @@ func expandParameterOrResponse(input interface{}, resolver *schemaLoader, basePa return nil } - parentRefs := make([]string, 0, 10) + parentRefs := make([]string, 0, smallPrealloc) if ref != nil { // dereference this $ref if err = resolver.deref(input, parentRefs, basePath); resolver.shouldStopOnError(err) { diff --git a/header.go b/header.go index 9dfd17b..5957fa2 100644 --- a/header.go +++ b/header.go @@ -74,14 +74,14 @@ func (h *Header) WithDefault(defaultValue interface{}) *Header { } // WithMaxLength sets a max length value -func (h *Header) WithMaxLength(max int64) *Header { - h.MaxLength = &max +func (h *Header) WithMaxLength(maximum int64) *Header { + h.MaxLength = &maximum return h } // WithMinLength sets a min length value -func (h *Header) WithMinLength(min int64) *Header { - h.MinLength = &min +func (h *Header) WithMinLength(minimum int64) *Header { + h.MinLength = &minimum return h } @@ -98,15 +98,15 @@ func (h *Header) WithMultipleOf(number float64) *Header { } // WithMaximum sets a maximum number value -func (h *Header) WithMaximum(max float64, exclusive bool) *Header { - h.Maximum = &max +func (h *Header) WithMaximum(maximum float64, exclusive bool) *Header { + h.Maximum = &maximum h.ExclusiveMaximum = exclusive return h } // WithMinimum sets a minimum number value -func (h *Header) WithMinimum(min float64, exclusive bool) *Header { - h.Minimum = &min +func (h *Header) WithMinimum(minimum float64, exclusive bool) *Header { + h.Minimum = &minimum h.ExclusiveMinimum = exclusive return h } diff --git a/header_test.go b/header_test.go index 67a893a..5259cd8 100644 --- a/header_test.go +++ b/header_test.go @@ -118,15 +118,15 @@ func TestJSONLookupHeader(t *testing.T) { require.Error(t, err) require.Nil(t, res) - var max *float64 + var maximum *float64 res, err = header.JSONLookup("maximum") require.NoError(t, err) require.NotNil(t, res) - require.IsType(t, max, res) + require.IsType(t, maximum, res) - max, ok = res.(*float64) + maximum, ok = res.(*float64) require.True(t, ok) - assert.InDelta(t, float64(100), *max, epsilon) + assert.InDelta(t, float64(100), *maximum, epsilon) } func TestResponseHeaueder(t *testing.T) { diff --git a/info_test.go b/info_test.go index a8e3fbe..3255cd1 100644 --- a/info_test.go +++ b/info_test.go @@ -39,7 +39,7 @@ const infoJSON = `{ "x-framework": "go-swagger" }` -var info = Info{ +var testInfo = Info{ InfoProps: InfoProps{ Version: "1.0.9-abcd", Title: "Swagger Sample API", @@ -56,21 +56,23 @@ var info = Info{ VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-framework": "go-swagger"}}, } -func TestIntegrationInfo_Serialize(t *testing.T) { - b, err := json.MarshalIndent(info, "", "\t") - require.NoError(t, err) - assert.Equal(t, infoJSON, string(b)) -} +func TestInfo(t *testing.T) { + t.Run("should marshal Info", func(t *testing.T) { + b, err := json.MarshalIndent(testInfo, "", "\t") + require.NoError(t, err) + assert.JSONEq(t, infoJSON, string(b)) + }) -func TestIntegrationInfo_Deserialize(t *testing.T) { - actual := Info{} - require.NoError(t, json.Unmarshal([]byte(infoJSON), &actual)) - assert.EqualValues(t, info, actual) -} + t.Run("should unmarshal Info", func(t *testing.T) { + actual := Info{} + require.NoError(t, json.Unmarshal([]byte(infoJSON), &actual)) + assert.EqualValues(t, testInfo, actual) + }) -func TestInfoGobEncoding(t *testing.T) { - var src, dst Info - require.NoError(t, json.Unmarshal([]byte(infoJSON), &src)) - assert.EqualValues(t, src, info) - doTestAnyGobEncoding(t, &src, &dst) + t.Run("should GobEncode Info", func(t *testing.T) { + var src, dst Info + require.NoError(t, json.Unmarshal([]byte(infoJSON), &src)) + assert.EqualValues(t, src, testInfo) + doTestAnyGobEncoding(t, &src, &dst) + }) } diff --git a/items.go b/items.go index e2afb21..7404bee 100644 --- a/items.go +++ b/items.go @@ -97,14 +97,14 @@ func (i *Items) WithDefault(defaultValue interface{}) *Items { } // WithMaxLength sets a max length value -func (i *Items) WithMaxLength(max int64) *Items { - i.MaxLength = &max +func (i *Items) WithMaxLength(maximum int64) *Items { + i.MaxLength = &maximum return i } // WithMinLength sets a min length value -func (i *Items) WithMinLength(min int64) *Items { - i.MinLength = &min +func (i *Items) WithMinLength(minimum int64) *Items { + i.MinLength = &minimum return i } @@ -121,15 +121,15 @@ func (i *Items) WithMultipleOf(number float64) *Items { } // WithMaximum sets a maximum number value -func (i *Items) WithMaximum(max float64, exclusive bool) *Items { - i.Maximum = &max +func (i *Items) WithMaximum(maximum float64, exclusive bool) *Items { + i.Maximum = &maximum i.ExclusiveMaximum = exclusive return i } // WithMinimum sets a minimum number value -func (i *Items) WithMinimum(min float64, exclusive bool) *Items { - i.Minimum = &min +func (i *Items) WithMinimum(minimum float64, exclusive bool) *Items { + i.Minimum = &minimum i.ExclusiveMinimum = exclusive return i } diff --git a/items_test.go b/items_test.go index 4d4e458..88cf12f 100644 --- a/items_test.go +++ b/items_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/require" ) -var items = Items{ +var testItems = Items{ Refable: Refable{Ref: MustCreateRef("Dog")}, CommonValidations: CommonValidations{ Maximum: float64Ptr(100), @@ -76,17 +76,17 @@ const itemsJSON = `{ func TestIntegrationItems(t *testing.T) { var actual Items require.NoError(t, json.Unmarshal([]byte(itemsJSON), &actual)) - assert.EqualValues(t, actual, items) + assert.EqualValues(t, actual, testItems) - assertParsesJSON(t, itemsJSON, items) + assertParsesJSON(t, itemsJSON, testItems) } func TestTypeNameItems(t *testing.T) { var nilItems Items assert.Equal(t, "", nilItems.TypeName()) - assert.Equal(t, "date", items.TypeName()) - assert.Equal(t, "", items.ItemsTypeName()) + assert.Equal(t, "date", testItems.TypeName()) + assert.Equal(t, "", testItems.ItemsTypeName()) nested := Items{ SimpleSchema: SimpleSchema{ @@ -151,39 +151,47 @@ func TestItemsBuilder(t *testing.T) { } func TestJSONLookupItems(t *testing.T) { - res, err := items.JSONLookup("$ref") - require.NoError(t, err) - require.NotNil(t, res) - require.IsType(t, &Ref{}, res) - - var ok bool - ref, ok := res.(*Ref) - require.True(t, ok) - assert.EqualValues(t, MustCreateRef("Dog"), *ref) - - var max *float64 - res, err = items.JSONLookup("maximum") - require.NoError(t, err) - require.NotNil(t, res) - require.IsType(t, max, res) - - max, ok = res.(*float64) - require.True(t, ok) - assert.InDelta(t, float64(100), *max, epsilon) - - var f string - res, err = items.JSONLookup("collectionFormat") - require.NoError(t, err) - require.NotNil(t, res) - require.IsType(t, f, res) - - f, ok = res.(string) - require.True(t, ok) - assert.Equal(t, "csv", f) - - res, err = items.JSONLookup("unknown") - require.Error(t, err) - require.Nil(t, res) + t.Run(`lookup should find "$ref"`, func(t *testing.T) { + res, err := testItems.JSONLookup("$ref") + require.NoError(t, err) + require.NotNil(t, res) + require.IsType(t, &Ref{}, res) + + ref, ok := res.(*Ref) + require.True(t, ok) + assert.EqualValues(t, MustCreateRef("Dog"), *ref) + }) + + t.Run(`lookup should find "maximum"`, func(t *testing.T) { + var maximum *float64 + res, err := testItems.JSONLookup("maximum") + require.NoError(t, err) + require.NotNil(t, res) + require.IsType(t, maximum, res) + + var ok bool + maximum, ok = res.(*float64) + require.True(t, ok) + assert.InDelta(t, float64(100), *maximum, epsilon) + }) + + t.Run(`lookup should find "collectionFormat"`, func(t *testing.T) { + var f string + res, err := testItems.JSONLookup("collectionFormat") + require.NoError(t, err) + require.NotNil(t, res) + require.IsType(t, f, res) + + f, ok := res.(string) + require.True(t, ok) + assert.Equal(t, "csv", f) + }) + + t.Run(`lookup should fail on "unknown"`, func(t *testing.T) { + res, err := testItems.JSONLookup("unknown") + require.Error(t, err) + require.Nil(t, res) + }) } func TestItemsWithValidation(t *testing.T) { diff --git a/license_test.go b/license_test.go index 398f0d8..67a75c0 100644 --- a/license_test.go +++ b/license_test.go @@ -22,26 +22,29 @@ import ( "github.com/stretchr/testify/require" ) -var license = License{ - LicenseProps: LicenseProps{Name: "the name", URL: "the url"}, - VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-license": "custom term"}}} - -const licenseJSON = `{ +func TestIntegrationLicense(t *testing.T) { + const licenseJSON = `{ "name": "the name", "url": "the url", "x-license": "custom term" }` -func TestIntegrationLicense(t *testing.T) { + var testLicense = License{ + LicenseProps: LicenseProps{Name: "the name", URL: "the url"}, + VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-license": "custom term"}}} // const licenseYAML = "name: the name\nurl: the url\n" - b, err := json.MarshalIndent(license, "", "\t") - require.NoError(t, err) - assert.Equal(t, licenseJSON, string(b)) - - actual := License{} - err = json.Unmarshal([]byte(licenseJSON), &actual) - require.NoError(t, err) - assert.EqualValues(t, license, actual) + t.Run("should marshal license", func(t *testing.T) { + b, err := json.MarshalIndent(testLicense, "", "\t") + require.NoError(t, err) + assert.JSONEq(t, licenseJSON, string(b)) + }) + + t.Run("should unmarshal empty license", func(t *testing.T) { + actual := License{} + err := json.Unmarshal([]byte(licenseJSON), &actual) + require.NoError(t, err) + assert.EqualValues(t, testLicense, actual) + }) } diff --git a/parameter.go b/parameter.go index bd4f1cd..1363a2d 100644 --- a/parameter.go +++ b/parameter.go @@ -210,14 +210,14 @@ func (p *Parameter) AsRequired() *Parameter { } // WithMaxLength sets a max length value -func (p *Parameter) WithMaxLength(max int64) *Parameter { - p.MaxLength = &max +func (p *Parameter) WithMaxLength(maximum int64) *Parameter { + p.MaxLength = &maximum return p } // WithMinLength sets a min length value -func (p *Parameter) WithMinLength(min int64) *Parameter { - p.MinLength = &min +func (p *Parameter) WithMinLength(minimum int64) *Parameter { + p.MinLength = &minimum return p } @@ -234,15 +234,15 @@ func (p *Parameter) WithMultipleOf(number float64) *Parameter { } // WithMaximum sets a maximum number value -func (p *Parameter) WithMaximum(max float64, exclusive bool) *Parameter { - p.Maximum = &max +func (p *Parameter) WithMaximum(maximum float64, exclusive bool) *Parameter { + p.Maximum = &maximum p.ExclusiveMaximum = exclusive return p } // WithMinimum sets a minimum number value -func (p *Parameter) WithMinimum(min float64, exclusive bool) *Parameter { - p.Minimum = &min +func (p *Parameter) WithMinimum(minimum float64, exclusive bool) *Parameter { + p.Minimum = &minimum p.ExclusiveMinimum = exclusive return p } diff --git a/paths.go b/paths.go index 9dc82a2..d4b62dd 100644 --- a/paths.go +++ b/paths.go @@ -41,7 +41,7 @@ func (p Paths) JSONLookup(token string) (interface{}, error) { if ex, ok := p.Extensions[token]; ok { return &ex, nil } - return nil, fmt.Errorf("object has no field %q", token) + return nil, fmt.Errorf("object has no field %q: %w", token, ErrSpec) } // UnmarshalJSON hydrates this items instance with the data from JSON diff --git a/ref.go b/ref.go index b0ef9bd..6c14a9f 100644 --- a/ref.go +++ b/ref.go @@ -75,7 +75,8 @@ func (r *Ref) IsValidURI(basepaths ...string) bool { } defer rr.Body.Close() - return rr.StatusCode/100 == 2 + // true if the response is >= 200 and < 300 + return rr.StatusCode/100 == 2 //nolint:mnd } if !(r.HasFileScheme || r.HasFullFilePath || r.HasURLPathOnly) { diff --git a/ref_test.go b/ref_test.go index 6f4c0de..3d233e0 100644 --- a/ref_test.go +++ b/ref_test.go @@ -40,5 +40,5 @@ func TestCloneRef(t *testing.T) { jazon, err := json.Marshal(dst) require.NoError(t, err) - assert.Equal(t, `{"$ref":"#/definitions/test"}`, string(jazon)) + assert.JSONEq(t, `{"$ref":"#/definitions/test"}`, string(jazon)) } diff --git a/responses.go b/responses.go index 16c3076..c133b17 100644 --- a/responses.go +++ b/responses.go @@ -55,7 +55,7 @@ func (r Responses) JSONLookup(token string) (interface{}, error) { return scr, nil } } - return nil, fmt.Errorf("object has no field %q", token) + return nil, fmt.Errorf("object has no field %q: %w", token, ErrSpec) } // UnmarshalJSON hydrates this items instance with the data from JSON diff --git a/schema.go b/schema.go index 4e9be85..8c929dd 100644 --- a/schema.go +++ b/schema.go @@ -275,14 +275,14 @@ func (s *Schema) WithAllOf(schemas ...Schema) *Schema { } // WithMaxProperties sets the max number of properties an object can have -func (s *Schema) WithMaxProperties(max int64) *Schema { - s.MaxProperties = &max +func (s *Schema) WithMaxProperties(maximum int64) *Schema { + s.MaxProperties = &maximum return s } // WithMinProperties sets the min number of properties an object must have -func (s *Schema) WithMinProperties(min int64) *Schema { - s.MinProperties = &min +func (s *Schema) WithMinProperties(minimum int64) *Schema { + s.MinProperties = &minimum return s } @@ -334,14 +334,14 @@ func (s *Schema) AddRequired(items ...string) *Schema { } // WithMaxLength sets a max length value -func (s *Schema) WithMaxLength(max int64) *Schema { - s.MaxLength = &max +func (s *Schema) WithMaxLength(maximum int64) *Schema { + s.MaxLength = &maximum return s } // WithMinLength sets a min length value -func (s *Schema) WithMinLength(min int64) *Schema { - s.MinLength = &min +func (s *Schema) WithMinLength(minimum int64) *Schema { + s.MinLength = &minimum return s } @@ -358,15 +358,15 @@ func (s *Schema) WithMultipleOf(number float64) *Schema { } // WithMaximum sets a maximum number value -func (s *Schema) WithMaximum(max float64, exclusive bool) *Schema { - s.Maximum = &max +func (s *Schema) WithMaximum(maximum float64, exclusive bool) *Schema { + s.Maximum = &maximum s.ExclusiveMaximum = exclusive return s } // WithMinimum sets a minimum number value -func (s *Schema) WithMinimum(min float64, exclusive bool) *Schema { - s.Minimum = &min +func (s *Schema) WithMinimum(minimum float64, exclusive bool) *Schema { + s.Minimum = &minimum s.ExclusiveMinimum = exclusive return s } @@ -566,29 +566,29 @@ func (s Schema) Validations() SchemaValidations { func (s Schema) MarshalJSON() ([]byte, error) { b1, err := json.Marshal(s.SchemaProps) if err != nil { - return nil, fmt.Errorf("schema props %v", err) + return nil, fmt.Errorf("schema props %v: %w", err, ErrSpec) } b2, err := json.Marshal(s.VendorExtensible) if err != nil { - return nil, fmt.Errorf("vendor props %v", err) + return nil, fmt.Errorf("vendor props %v: %w", err, ErrSpec) } b3, err := s.Ref.MarshalJSON() if err != nil { - return nil, fmt.Errorf("ref prop %v", err) + return nil, fmt.Errorf("ref prop %v: %w", err, ErrSpec) } b4, err := s.Schema.MarshalJSON() if err != nil { - return nil, fmt.Errorf("schema prop %v", err) + return nil, fmt.Errorf("schema prop %v: %w", err, ErrSpec) } b5, err := json.Marshal(s.SwaggerSchemaProps) if err != nil { - return nil, fmt.Errorf("common validations %v", err) + return nil, fmt.Errorf("common validations %v: %w", err, ErrSpec) } var b6 []byte if s.ExtraProps != nil { jj, err := json.Marshal(s.ExtraProps) if err != nil { - return nil, fmt.Errorf("extra props %v", err) + return nil, fmt.Errorf("extra props %v: %w", err, ErrSpec) } b6 = jj } diff --git a/swagger.go b/swagger.go index 1590fd1..977c2f0 100644 --- a/swagger.go +++ b/swagger.go @@ -379,7 +379,7 @@ func (s *StringOrArray) UnmarshalJSON(data []byte) error { *s = StringOrArray([]string{v}) return nil default: - return fmt.Errorf("only string or array is allowed, not %T", single) + return fmt.Errorf("only string or array is allowed, not %T: %w", single, ErrSpec) } } diff --git a/swagger_test.go b/swagger_test.go index 59e2403..e111bb6 100644 --- a/swagger_test.go +++ b/swagger_test.go @@ -29,7 +29,7 @@ var spec = Swagger{ Consumes: []string{"application/json", "application/x-yaml"}, Produces: []string{"application/json"}, Schemes: []string{"http", "https"}, - Info: &info, + Info: &testInfo, Host: "some.api.out.there", BasePath: "/", Paths: &paths, diff --git a/validations.go b/validations.go index 6360a8e..ae80a5d 100644 --- a/validations.go +++ b/validations.go @@ -54,7 +54,8 @@ func (c clearedValidations) apply(cbs []func(string, interface{})) { // // Some callbacks may be set by the caller to capture changed values. func (v *CommonValidations) ClearNumberValidations(cbs ...func(string, interface{})) { - done := make(clearedValidations, 0, 5) + const maxNumberValidations = 5 + done := make(clearedValidations, 0, maxNumberValidations) defer func() { done.apply(cbs) }() @@ -85,7 +86,8 @@ func (v *CommonValidations) ClearNumberValidations(cbs ...func(string, interface // // Some callbacks may be set by the caller to capture changed values. func (v *CommonValidations) ClearStringValidations(cbs ...func(string, interface{})) { - done := make(clearedValidations, 0, 3) + const maxStringValidations = 3 + done := make(clearedValidations, 0, maxStringValidations) defer func() { done.apply(cbs) }() @@ -108,7 +110,8 @@ func (v *CommonValidations) ClearStringValidations(cbs ...func(string, interface // // Some callbacks may be set by the caller to capture changed values. func (v *CommonValidations) ClearArrayValidations(cbs ...func(string, interface{})) { - done := make(clearedValidations, 0, 3) + const maxArrayValidations = 3 + done := make(clearedValidations, 0, maxArrayValidations) defer func() { done.apply(cbs) }() @@ -195,7 +198,8 @@ func (v SchemaValidations) Validations() SchemaValidations { // // Some callbacks may be set by the caller to capture changed values. func (v *SchemaValidations) ClearObjectValidations(cbs ...func(string, interface{})) { - done := make(clearedValidations, 0, 3) + const maxObjectValidations = 3 + done := make(clearedValidations, 0, maxObjectValidations) defer func() { done.apply(cbs) }()