From 59ad25652c3165f668af2ec2736b67100bf287c4 Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Sun, 9 Nov 2025 15:03:48 +0100 Subject: [PATCH] chore: updated license marks in source files Signed-off-by: Frederic BIDON --- .golangci.yml | 2 +- README.md | 4 +++ benchmark_test.go | 3 ++ context.go | 3 ++ context_test.go | 3 ++ debug.go | 17 ++------- debug_test.go | 15 ++------ default_validator.go | 15 ++------ default_validator_test.go | 15 ++------ doc.go | 15 ++------ doc_test.go | 21 +++-------- example_validator.go | 15 ++------ example_validator_test.go | 15 ++------ formats.go | 19 +++------- formats_test.go | 5 ++- helpers.go | 25 ++++---------- helpers_test.go | 19 +++------- items_validator_test.go | 37 +++++++------------- jsonschema_test.go | 21 +++-------- messages_test.go | 15 ++------ object_validator.go | 15 ++------ object_validator_test.go | 59 ++++++++++++++++--------------- options.go | 15 ++------ options_test.go | 3 ++ parameter_validator_test.go | 37 +++++++------------- pools.go | 3 ++ pools_debug.go | 3 ++ pools_debug_test.go | 3 ++ pools_test.go | 3 ++ post/defaulter.go | 3 ++ post/defaulter_test.go | 15 ++------ post/prune.go | 11 +++--- post/prune_test.go | 51 +++++++++++---------------- result.go | 15 ++------ result_test.go | 15 ++------ rexp.go | 20 +++-------- rexp_test.go | 3 ++ schema.go | 27 +++++---------- schema_messages.go | 15 ++------ schema_option.go | 15 ++------ schema_option_test.go | 15 ++------ schema_props.go | 35 +++++++------------ schema_props_test.go | 15 ++------ schema_test.go | 25 ++++---------- slice_validator.go | 23 ++++--------- slice_validator_test.go | 15 ++------ spec.go | 23 +++---------- spec_messages.go | 23 ++++--------- spec_test.go | 15 ++------ swagger_test.go | 15 ++------ type.go | 21 +++-------- type_test.go | 17 ++------- validator.go | 69 ++++++++++++++++--------------------- validator_test.go | 33 ++++++------------ values.go | 15 ++------ values_test.go | 33 ++++++------------ 56 files changed, 298 insertions(+), 709 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 43e2576..10c5133 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ linters: - gomoddirectives - gosmopolitan - inamedparam - #- intrange # disabled while < go1.22 + - intrange - ireturn - lll - musttag diff --git a/README.md b/README.md index e8e1bb2..73d87ce 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ Reference can be found here: https://github.com/OAI/OpenAPI-Specification/blob/m [Documentation](https://pkg.go.dev/github.com/go-openapi/validate) +## Licensing + +This library ships under the [SPDX-License-Identifier: Apache-2.0](./LICENSE). + ## FAQ * Does this library support OpenAPI 3? diff --git a/benchmark_test.go b/benchmark_test.go index ff58813..6277c2d 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package validate import ( diff --git a/context.go b/context.go index d54791c..b4587dc 100644 --- a/context.go +++ b/context.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package validate import ( diff --git a/context_test.go b/context_test.go index 70140aa..a692ad1 100644 --- a/context_test.go +++ b/context_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package validate import ( diff --git a/debug.go b/debug.go index 8815fd9..79145a4 100644 --- a/debug.go +++ b/debug.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -38,7 +27,7 @@ func debugOptions() { validateLogger = log.New(os.Stdout, "validate:", log.LstdFlags) } -func debugLog(msg string, args ...interface{}) { +func debugLog(msg string, args ...any) { // A private, trivial trace logger, based on go-openapi/spec/expander.go:debugLog() if Debug { _, file1, pos1, _ := runtime.Caller(1) diff --git a/debug_test.go b/debug_test.go index 3ed24f4..ae766f4 100644 --- a/debug_test.go +++ b/debug_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/default_validator.go b/default_validator.go index e82bb30..79a4316 100644 --- a/default_validator.go +++ b/default_validator.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/default_validator_test.go b/default_validator_test.go index fc56a23..fc16137 100644 --- a/default_validator_test.go +++ b/default_validator_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/doc.go b/doc.go index d2b901e..a99893e 100644 --- a/doc.go +++ b/doc.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 /* Package validate provides methods to validate a swagger specification, diff --git a/doc_test.go b/doc_test.go index 525376b..7f89783 100644 --- a/doc_test.go +++ b/doc_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate_test @@ -150,7 +139,7 @@ func ExampleAgainstSchema() { schema := new(spec.Schema) _ = json.Unmarshal([]byte(schemaJSON), schema) - input := map[string]interface{}{} + input := map[string]any{} // JSON data to validate inputJSON := `{"name": "Ivan","address-1": "sesame street"}` @@ -169,13 +158,13 @@ func ExampleAgainstSchema() { func TestValidate_Issue112(t *testing.T) { t.Run("returns no error on body includes `items` key", func(t *testing.T) { - body := map[string]interface{}{"items1": nil} + body := map[string]any{"items1": nil} err := validate.AgainstSchema(getSimpleSchema(), body, strfmt.Default) require.NoError(t, err) }) t.Run("returns no error when body includes `items` key", func(t *testing.T) { - body := map[string]interface{}{"items": nil} + body := map[string]any{"items": nil} err := validate.AgainstSchema(getSimpleSchema(), body, strfmt.Default) require.NoError(t, err) }) diff --git a/example_validator.go b/example_validator.go index 0663b21..e4ef52c 100644 --- a/example_validator.go +++ b/example_validator.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/example_validator_test.go b/example_validator_test.go index f3a7a41..7ed5f0e 100644 --- a/example_validator_test.go +++ b/example_validator_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/formats.go b/formats.go index f4e3552..85ee634 100644 --- a/formats.go +++ b/formats.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -54,7 +43,7 @@ func (f *formatValidator) SetPath(path string) { f.Path = path } -func (f *formatValidator) Applies(source interface{}, kind reflect.Kind) bool { +func (f *formatValidator) Applies(source any, kind reflect.Kind) bool { if source == nil || f.KnownFormats == nil { return false } @@ -73,7 +62,7 @@ func (f *formatValidator) Applies(source interface{}, kind reflect.Kind) bool { } } -func (f *formatValidator) Validate(val interface{}) *Result { +func (f *formatValidator) Validate(val any) *Result { if f.Options.recycleValidators { defer func() { f.redeem() diff --git a/formats_test.go b/formats_test.go index 751efb3..f86cbb8 100644 --- a/formats_test.go +++ b/formats_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package validate import ( @@ -27,7 +30,7 @@ func TestFormatValidator_EdgeCases(t *testing.T) { i := spec.Items{} i.Typed(stringType, "datetime") - sources := []interface{}{&p, &s, &i} + sources := []any{&p, &s, &i} for _, source := range sources { // Default formats for strings diff --git a/helpers.go b/helpers.go index 16840da..49b1304 100644 --- a/helpers.go +++ b/helpers.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -139,7 +128,7 @@ func (h *pathHelper) stripParametersInPath(path string) string { rexParsePathParam := mustCompileRegexp(`{[^{}]+?}`) strippedSegments := []string{} - for _, segment := range strings.Split(path, "/") { + for segment := range strings.SplitSeq(path, "/") { strippedSegments = append(strippedSegments, rexParsePathParam.ReplaceAllString(segment, "X")) } return strings.Join(strippedSegments, "/") @@ -149,7 +138,7 @@ func (h *pathHelper) extractPathParams(path string) (params []string) { // Extracts all params from a path, with surrounding "{}" rexParsePathParam := mustCompileRegexp(`{[^{}]+?}`) - for _, segment := range strings.Split(path, "/") { + for segment := range strings.SplitSeq(path, "/") { for _, v := range rexParsePathParam.FindAllStringSubmatch(segment, -1) { params = append(params, v...) } @@ -161,7 +150,7 @@ type valueHelper struct { // A collection of unexported helpers for value validation } -func (h *valueHelper) asInt64(val interface{}) int64 { +func (h *valueHelper) asInt64(val any) int64 { // Number conversion function for int64, without error checking // (implements an implicit type upgrade). v := reflect.ValueOf(val) @@ -178,7 +167,7 @@ func (h *valueHelper) asInt64(val interface{}) int64 { } } -func (h *valueHelper) asUint64(val interface{}) uint64 { +func (h *valueHelper) asUint64(val any) uint64 { // Number conversion function for uint64, without error checking // (implements an implicit type upgrade). v := reflect.ValueOf(val) @@ -196,7 +185,7 @@ func (h *valueHelper) asUint64(val interface{}) uint64 { } // Same for unsigned floats -func (h *valueHelper) asFloat64(val interface{}) float64 { +func (h *valueHelper) asFloat64(val any) float64 { // Number conversion function for float64, without error checking // (implements an implicit type upgrade). v := reflect.ValueOf(val) diff --git a/helpers_test.go b/helpers_test.go index efab594..05f5d9f 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -33,8 +22,8 @@ func TestHelpers_addPointerError(t *testing.T) { } //nolint:gosec -func integerFactory(base int) []interface{} { - return []interface{}{ +func integerFactory(base int) []any { + return []any{ base, int8(base), int16(base), diff --git a/items_validator_test.go b/items_validator_test.go index 654331d..8f5e382 100644 --- a/items_validator_test.go +++ b/items_validator_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -51,19 +40,19 @@ func stringItems() *spec.Items { return spec.NewItems().Typed(stringType, "") } -func requiredError(param *spec.Parameter, data interface{}) *errors.Validation { +func requiredError(param *spec.Parameter, data any) *errors.Validation { return errors.Required(param.Name, param.In, data) } -func maxErrorItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func maxErrorItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.ExceedsMaximum(path, in, *items.Maximum, items.ExclusiveMaximum, data) } -func minErrorItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func minErrorItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.ExceedsMinimum(path, in, *items.Minimum, items.ExclusiveMinimum, data) } -func multipleOfErrorItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func multipleOfErrorItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.NotMultipleOf(path, in, *items.MultipleOf, data) } @@ -73,27 +62,27 @@ func requiredErrorItems(path, in string) *errors.Validation { } */ -func maxLengthErrorItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func maxLengthErrorItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.TooLong(path, in, *items.MaxLength, data) } -func minLengthErrorItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func minLengthErrorItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.TooShort(path, in, *items.MinLength, data) } -func patternFailItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func patternFailItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.FailedPattern(path, in, items.Pattern, data) } -func enumFailItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func enumFailItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.EnumFail(path, in, data, items.Enum) } -func minItemsErrorItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func minItemsErrorItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.TooFewItems(path, in, *items.MinItems, data) } -func maxItemsErrorItems(path, in string, items *spec.Items, data interface{}) *errors.Validation { +func maxItemsErrorItems(path, in string, items *spec.Items, data any) *errors.Validation { return errors.TooManyItems(path, in, *items.MaxItems, data) } @@ -103,7 +92,7 @@ func duplicatesErrorItems(path, in string) *errors.Validation { func TestNumberItemsValidation(t *testing.T) { - values := [][]interface{}{ + values := [][]any{ {23, 49, 56, 21, 14, 35, 28, 7, 42}, {uint(23), uint(49), uint(56), uint(21), uint(14), uint(35), uint(28), uint(7), uint(42)}, {float64(23), float64(49), float64(56), float64(21), float64(14), float64(35), float64(28), float64(7), float64(42)}, diff --git a/jsonschema_test.go b/jsonschema_test.go index 5658816..0ad6288 100644 --- a/jsonschema_test.go +++ b/jsonschema_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -35,9 +24,9 @@ type schemaTestT struct { Description string `json:"description"` Schema *spec.Schema `json:"schema"` Tests []struct { - Description string `json:"description"` - Data interface{} `json:"data"` - Valid bool `json:"valid"` + Description string `json:"description"` + Data any `json:"data"` + Valid bool `json:"valid"` } } diff --git a/messages_test.go b/messages_test.go index 78dcba6..7467498 100644 --- a/messages_test.go +++ b/messages_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/object_validator.go b/object_validator.go index 76301d0..cf98ed3 100644 --- a/object_validator.go +++ b/object_validator.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/object_validator_test.go b/object_validator_test.go index 3e393be..cbe5603 100644 --- a/object_validator_test.go +++ b/object_validator_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Copyright 2017 go-swagger maintainers // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,14 +27,14 @@ import ( "github.com/stretchr/testify/require" ) -func itemsFixture() map[string]interface{} { - return map[string]interface{}{ +func itemsFixture() map[string]any { + return map[string]any{ "type": "array", "items": "dummy", } } -func expectAllValid(t *testing.T, ov EntityValidator, dataValid, dataInvalid map[string]interface{}) { +func expectAllValid(t *testing.T, ov EntityValidator, dataValid, dataInvalid map[string]any) { res := ov.Validate(dataValid) assert.Empty(t, res.Errors) @@ -39,7 +42,7 @@ func expectAllValid(t *testing.T, ov EntityValidator, dataValid, dataInvalid map assert.Empty(t, res.Errors) } -func expectOnlyInvalid(t *testing.T, ov EntityValidator, dataValid, dataInvalid map[string]interface{}) { +func expectOnlyInvalid(t *testing.T, ov EntityValidator, dataValid, dataInvalid map[string]any) { res := ov.Validate(dataValid) assert.Empty(t, res.Errors) @@ -50,7 +53,7 @@ func expectOnlyInvalid(t *testing.T, ov EntityValidator, dataValid, dataInvalid func TestItemsMustBeTypeArray(t *testing.T) { ov := newObjectValidator("", "", nil, nil, nil, nil, nil, nil, nil, nil, nil) dataValid := itemsFixture() - dataInvalid := map[string]interface{}{ + dataInvalid := map[string]any{ "type": "object", "items": "dummy", } @@ -63,7 +66,7 @@ func TestItemsMustBeTypeArray(t *testing.T) { func TestItemsMustHaveType(t *testing.T) { ov := newObjectValidator("", "", nil, nil, nil, nil, nil, nil, nil, nil, nil) dataValid := itemsFixture() - dataInvalid := map[string]interface{}{ + dataInvalid := map[string]any{ "items": "dummy", } expectAllValid(t, ov, dataValid, dataInvalid) @@ -75,7 +78,7 @@ func TestItemsMustHaveType(t *testing.T) { func TestTypeArrayMustHaveItems(t *testing.T) { ov := newObjectValidator("", "", nil, nil, nil, nil, nil, nil, nil, nil, nil) dataValid := itemsFixture() - dataInvalid := map[string]interface{}{ + dataInvalid := map[string]any{ "type": "array", "key": "dummy", } @@ -126,7 +129,7 @@ func TestObjectValidatorPatternProperties(t *testing.T) { t.Run("should ignore invalid regexp in pattern properties", func(t *testing.T) { s := newObjectValidator("test", "body", nil, nil, nil, nil, nil, patternWithValid, nil, nil, nil) - res := s.Validate(map[string]interface{}{"valid": "test_string"}) + res := s.Validate(map[string]any{"valid": "test_string"}) require.NotNil(t, res) require.Empty(t, res.Errors) }) @@ -134,7 +137,7 @@ func TestObjectValidatorPatternProperties(t *testing.T) { t.Run("should report forbidden property when invalid regexp in pattern properties", func(t *testing.T) { s := newObjectValidator("test", "body", nil, nil, nil, nil, nil, patternGarbled, nil, nil, nil) - res := s.Validate(map[string]interface{}{"valid": "test_string"}) + res := s.Validate(map[string]any{"valid": "test_string"}) require.NotNil(t, res) require.Empty(t, res.Errors) }) @@ -145,7 +148,7 @@ func TestObjectValidatorPatternProperties(t *testing.T) { Allows: false, }, patternWithValid, nil, nil, nil) - res := s.Validate(map[string]interface{}{"valid": "test_string"}) + res := s.Validate(map[string]any{"valid": "test_string"}) require.NotNil(t, res) require.Empty(t, res.Errors) }) @@ -156,7 +159,7 @@ func TestObjectValidatorPatternProperties(t *testing.T) { Allows: false, }, patternGarbled, nil, nil, nil) - res := s.Validate(map[string]interface{}{"valid": "test_string"}) + res := s.Validate(map[string]any{"valid": "test_string"}) require.NotNil(t, res) require.Len(t, res.Errors, 1) require.ErrorContains(t, res.Errors[0], "forbidden property") @@ -209,9 +212,9 @@ func TestObjectValidatorWithHeaderProperty(t *testing.T) { Allows: false, }, nil, nil, nil, nil) - res := s.Validate(map[string]interface{}{ - "headers": map[string]interface{}{ - "X-Custom": map[string]interface{}{ + res := s.Validate(map[string]any{ + "headers": map[string]any{ + "X-Custom": map[string]any{ "$ref": "#/definitions/myHeader", }, }, @@ -237,9 +240,9 @@ func TestObjectValidatorWithHeaderProperty(t *testing.T) { }, nil, nil, nil, nil) t.Run("when key is not headers", func(t *testing.T) { - res := s.Validate(map[string]interface{}{ - "Headers": map[string]interface{}{ - "X-Custom": map[string]interface{}{ + res := s.Validate(map[string]any{ + "Headers": map[string]any{ + "X-Custom": map[string]any{ "$ref": "#/definitions/myHeader", }, }, @@ -249,7 +252,7 @@ func TestObjectValidatorWithHeaderProperty(t *testing.T) { }) t.Run("when key is not the expected map", func(t *testing.T) { - res := s.Validate(map[string]interface{}{ + res := s.Validate(map[string]any{ "headers": map[string]string{ "X-Custom": "#/definitions/myHeader", }, @@ -259,8 +262,8 @@ func TestObjectValidatorWithHeaderProperty(t *testing.T) { }) t.Run("when key content not the expected map", func(t *testing.T) { - res := s.Validate(map[string]interface{}{ - "headers": map[string]interface{}{ + res := s.Validate(map[string]any{ + "headers": map[string]any{ "X-Custom": 1, }, }) @@ -269,8 +272,8 @@ func TestObjectValidatorWithHeaderProperty(t *testing.T) { }) t.Run("when key content not the expected map", func(t *testing.T) { - res := s.Validate(map[string]interface{}{ - "headers": map[string]interface{}{ + res := s.Validate(map[string]any{ + "headers": map[string]any{ "X-Custom": nil, }, }) @@ -279,9 +282,9 @@ func TestObjectValidatorWithHeaderProperty(t *testing.T) { }) t.Run("when header is not a valid $ref", func(t *testing.T) { - res := s.Validate(map[string]interface{}{ - "headers": map[string]interface{}{ - "X-Custom": map[string]interface{}{ + res := s.Validate(map[string]any{ + "headers": map[string]any{ + "X-Custom": map[string]any{ "$ref": 1, }, }, @@ -291,9 +294,9 @@ func TestObjectValidatorWithHeaderProperty(t *testing.T) { }) t.Run("when header is not a $ref", func(t *testing.T) { - res := s.Validate(map[string]interface{}{ - "headers": map[string]interface{}{ - "X-Custom": map[string]interface{}{ + res := s.Validate(map[string]any{ + "headers": map[string]any{ + "X-Custom": map[string]any{ "ref": "#/definitions/myHeader", }, }, diff --git a/options.go b/options.go index cfe9b06..f5e7f71 100644 --- a/options.go +++ b/options.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/options_test.go b/options_test.go index 84611ba..3117ace 100644 --- a/options_test.go +++ b/options_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package validate import ( diff --git a/parameter_validator_test.go b/parameter_validator_test.go index 6eeaeff..18b5628 100644 --- a/parameter_validator_test.go +++ b/parameter_validator_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -27,19 +16,19 @@ import ( // common validations: enum, allOf, anyOf, oneOf, not, definitions -func maxError(param *spec.Parameter, data interface{}) *errors.Validation { +func maxError(param *spec.Parameter, data any) *errors.Validation { return errors.ExceedsMaximum(param.Name, param.In, *param.Maximum, param.ExclusiveMaximum, data) } -func minError(param *spec.Parameter, data interface{}) *errors.Validation { +func minError(param *spec.Parameter, data any) *errors.Validation { return errors.ExceedsMinimum(param.Name, param.In, *param.Minimum, param.ExclusiveMinimum, data) } -func multipleOfError(param *spec.Parameter, data interface{}) *errors.Validation { +func multipleOfError(param *spec.Parameter, data any) *errors.Validation { return errors.NotMultipleOf(param.Name, param.In, *param.MultipleOf, data) } -func makeFloat(data interface{}) float64 { +func makeFloat(data any) float64 { val := reflect.ValueOf(data) knd := val.Kind() switch { @@ -54,7 +43,7 @@ func makeFloat(data interface{}) float64 { func TestNumberParameterValidation(t *testing.T) { - values := [][]interface{}{ + values := [][]any{ {23, 49, 56, 21, 14, 35, 28, 7, 42}, {uint(23), uint(49), uint(56), uint(21), uint(14), uint(35), uint(28), uint(7), uint(42)}, {float64(23), float64(49), float64(56), float64(21), float64(14), float64(35), float64(28), float64(7), float64(42)}, @@ -130,19 +119,19 @@ func TestNumberParameterValidation(t *testing.T) { // Definitions } -func maxLengthError(param *spec.Parameter, data interface{}) *errors.Validation { +func maxLengthError(param *spec.Parameter, data any) *errors.Validation { return errors.TooLong(param.Name, param.In, *param.MaxLength, data) } -func minLengthError(param *spec.Parameter, data interface{}) *errors.Validation { +func minLengthError(param *spec.Parameter, data any) *errors.Validation { return errors.TooShort(param.Name, param.In, *param.MinLength, data) } -func patternFail(param *spec.Parameter, data interface{}) *errors.Validation { +func patternFail(param *spec.Parameter, data any) *errors.Validation { return errors.FailedPattern(param.Name, param.In, param.Pattern, data) } -func enumFail(param *spec.Parameter, data interface{}) *errors.Validation { +func enumFail(param *spec.Parameter, data any) *errors.Validation { return errors.EnumFail(param.Name, param.In, data, param.Enum) } @@ -195,10 +184,10 @@ func TestStringParameterValidation(t *testing.T) { // Definitions } -func minItemsError(param *spec.Parameter, data interface{}) *errors.Validation { +func minItemsError(param *spec.Parameter, data any) *errors.Validation { return errors.TooFewItems(param.Name, param.In, *param.MinItems, data) } -func maxItemsError(param *spec.Parameter, data interface{}) *errors.Validation { +func maxItemsError(param *spec.Parameter, data any) *errors.Validation { return errors.TooManyItems(param.Name, param.In, *param.MaxItems, data) } func duplicatesError(param *spec.Parameter) *errors.Validation { diff --git a/pools.go b/pools.go index 3ddce4d..1e734be 100644 --- a/pools.go +++ b/pools.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + //go:build !validatedebug package validate diff --git a/pools_debug.go b/pools_debug.go index 12949f0..d123ed4 100644 --- a/pools_debug.go +++ b/pools_debug.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + //go:build validatedebug package validate diff --git a/pools_debug_test.go b/pools_debug_test.go index 6a4eee4..b8d2fb3 100644 --- a/pools_debug_test.go +++ b/pools_debug_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + //go:build validatedebug package validate diff --git a/pools_test.go b/pools_test.go index d7398de..efcf7a5 100644 --- a/pools_test.go +++ b/pools_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package validate_test import ( diff --git a/post/defaulter.go b/post/defaulter.go index ee17ec7..0fcebe8 100644 --- a/post/defaulter.go +++ b/post/defaulter.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Copyright 2018 go-swagger maintainers // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/post/defaulter_test.go b/post/defaulter_test.go index c90599d..33e52de 100644 --- a/post/defaulter_test.go +++ b/post/defaulter_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package post diff --git a/post/prune.go b/post/prune.go index d78881a..387780c 100644 --- a/post/prune.go +++ b/post/prune.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Copyright 2018 go-swagger maintainers // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,21 +27,21 @@ func Prune(r *validate.Result) { prune(r.Data(), r) } -func prune(data interface{}, result *validate.Result) { +func prune(data any, result *validate.Result) { switch obj := data.(type) { - case map[string]interface{}: + case map[string]any: pruneObject(obj, result) for _, val := range obj { prune(val, result) } - case []interface{}: + case []any: for _, item := range obj { prune(item, result) } } } -func pruneObject(obj map[string]interface{}, result *validate.Result) { +func pruneObject(obj map[string]any, result *validate.Result) { fieldSchemata := result.FieldSchemata() for field := range obj { if schemata, ok := fieldSchemata[validate.NewFieldKey(obj, field)]; !ok || len(schemata) == 0 { diff --git a/post/prune_test.go b/post/prune_test.go index cba06c0..78685ba 100644 --- a/post/prune_test.go +++ b/post/prune_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package post @@ -34,38 +23,38 @@ func TestPrune(t *testing.T) { schema, err := pruningFixture() require.NoError(t, err) - x := map[string]interface{}{ + x := map[string]any{ "foo": 42, "bar": 42, "x": 42, - "nested": map[string]interface{}{ + "nested": map[string]any{ "x": 42, - "inner": map[string]interface{}{ + "inner": map[string]any{ "foo": 42, "bar": 42, "x": 42, }, }, - "all": map[string]interface{}{ + "all": map[string]any{ "foo": 42, "bar": 42, "x": 42, }, - "any": map[string]interface{}{ + "any": map[string]any{ "foo": 42, "bar": 42, "x": 42, }, - "one": map[string]interface{}{ + "one": map[string]any{ "bar": 42, "x": 42, }, - "array": []interface{}{ - map[string]interface{}{ + "array": []any{ + map[string]any{ "foo": 42, "bar": 123, }, - map[string]interface{}{ + map[string]any{ "x": 42, "y": 123, }, @@ -79,31 +68,31 @@ func TestPrune(t *testing.T) { Prune(r) t.Logf("After: %v", x) - expected := map[string]interface{}{ + expected := map[string]any{ "foo": 42, "bar": 42, - "nested": map[string]interface{}{ - "inner": map[string]interface{}{ + "nested": map[string]any{ + "inner": map[string]any{ "foo": 42, "bar": 42, }, }, - "all": map[string]interface{}{ + "all": map[string]any{ "foo": 42, "bar": 42, }, - "any": map[string]interface{}{ + "any": map[string]any{ // intentionally only list one: the first matching "foo": 42, }, - "one": map[string]interface{}{ + "one": map[string]any{ "bar": 42, }, - "array": []interface{}{ - map[string]interface{}{ + "array": []any{ + map[string]any{ "foo": 42, }, - map[string]interface{}{}, + map[string]any{}, }, } assert.Equal(t, expected, x) diff --git a/result.go b/result.go index 1955cff..69219e9 100644 --- a/result.go +++ b/result.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/result_test.go b/result_test.go index 7360b8b..d8bcdd1 100644 --- a/result_test.go +++ b/result_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/rexp.go b/rexp.go index 76de03e..795f148 100644 --- a/rexp.go +++ b/rexp.go @@ -1,20 +1,10 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate import ( + "maps" re "regexp" "sync" "sync/atomic" @@ -62,9 +52,7 @@ func cacheRegexp(r *re.Regexp) { r.String(): r, } - for k, v := range cache { - newCache[k] = v - } + maps.Copy(newCache, cache) reDict.Store(newCache) } diff --git a/rexp_test.go b/rexp_test.go index dc8b6ff..c80ed1b 100644 --- a/rexp_test.go +++ b/rexp_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Copyright 2015 go-swagger maintainers // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/schema.go b/schema.go index 8c48899..375a987 100644 --- a/schema.go +++ b/schema.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -30,7 +19,7 @@ type SchemaValidator struct { in string Schema *spec.Schema validators [8]valueValidator - Root interface{} + Root any KnownFormats strfmt.Registry Options *SchemaValidatorOptions } @@ -38,7 +27,7 @@ type SchemaValidator struct { // AgainstSchema validates the specified data against the provided schema, using a registry of supported formats. // // When no pre-parsed *spec.Schema structure is provided, it uses a JSON schema as default. See example. -func AgainstSchema(schema *spec.Schema, data interface{}, formats strfmt.Registry, options ...Option) error { +func AgainstSchema(schema *spec.Schema, data any, formats strfmt.Registry, options ...Option) error { res := NewSchemaValidator(schema, nil, "", formats, append(options, WithRecycleValidators(true), withRecycleResults(true))..., ).Validate(data) @@ -56,7 +45,7 @@ func AgainstSchema(schema *spec.Schema, data interface{}, formats strfmt.Registr // NewSchemaValidator creates a new schema validator. // // Panics if the provided schema is invalid. -func NewSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string, formats strfmt.Registry, options ...Option) *SchemaValidator { +func NewSchemaValidator(schema *spec.Schema, rootSchema any, root string, formats strfmt.Registry, options ...Option) *SchemaValidator { opts := new(SchemaValidatorOptions) for _, o := range options { o(opts) @@ -65,7 +54,7 @@ func NewSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string return newSchemaValidator(schema, rootSchema, root, formats, opts) } -func newSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string, formats strfmt.Registry, opts *SchemaValidatorOptions) *SchemaValidator { +func newSchemaValidator(schema *spec.Schema, rootSchema any, root string, formats strfmt.Registry, opts *SchemaValidatorOptions) *SchemaValidator { if schema == nil { return nil } @@ -120,13 +109,13 @@ func (s *SchemaValidator) SetPath(path string) { } // Applies returns true when this schema validator applies -func (s *SchemaValidator) Applies(source interface{}, _ reflect.Kind) bool { +func (s *SchemaValidator) Applies(source any, _ reflect.Kind) bool { _, ok := source.(*spec.Schema) return ok } // Validate validates the data against the schema -func (s *SchemaValidator) Validate(data interface{}) *Result { +func (s *SchemaValidator) Validate(data any) *Result { if s == nil { return emptyResult } diff --git a/schema_messages.go b/schema_messages.go index 786e2e3..e8c7c48 100644 --- a/schema_messages.go +++ b/schema_messages.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/schema_option.go b/schema_option.go index 65eeebe..d9fd21a 100644 --- a/schema_option.go +++ b/schema_option.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/schema_option_test.go b/schema_option_test.go index eb46650..944eec8 100644 --- a/schema_option_test.go +++ b/schema_option_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/schema_props.go b/schema_props.go index b8bdee8..485f536 100644 --- a/schema_props.go +++ b/schema_props.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -34,7 +23,7 @@ type schemaPropsValidator struct { allOfValidators []*SchemaValidator oneOfValidators []*SchemaValidator notValidator *SchemaValidator - Root interface{} + Root any KnownFormats strfmt.Registry Options *SchemaValidatorOptions } @@ -44,7 +33,7 @@ func (s *schemaPropsValidator) SetPath(path string) { } func newSchemaPropsValidator( - path string, in string, allOf, oneOf, anyOf []spec.Schema, not *spec.Schema, deps spec.Dependencies, root interface{}, formats strfmt.Registry, + path string, in string, allOf, oneOf, anyOf []spec.Schema, not *spec.Schema, deps spec.Dependencies, root any, formats strfmt.Registry, opts *SchemaValidatorOptions) *schemaPropsValidator { if opts == nil { opts = new(SchemaValidatorOptions) @@ -93,12 +82,12 @@ func newSchemaPropsValidator( return s } -func (s *schemaPropsValidator) Applies(source interface{}, _ reflect.Kind) bool { +func (s *schemaPropsValidator) Applies(source any, _ reflect.Kind) bool { _, isSchema := source.(*spec.Schema) return isSchema } -func (s *schemaPropsValidator) Validate(data interface{}) *Result { +func (s *schemaPropsValidator) Validate(data any) *Result { var mainResult *Result if s.Options.recycleResult { mainResult = pools.poolOfResults.BorrowResult() @@ -150,7 +139,7 @@ func (s *schemaPropsValidator) Validate(data interface{}) *Result { return mainResult.Merge(keepResultAllOf, keepResultOneOf, keepResultAnyOf) } -func (s *schemaPropsValidator) validateAnyOf(data interface{}, mainResult, keepResultAnyOf *Result) { +func (s *schemaPropsValidator) validateAnyOf(data any, mainResult, keepResultAnyOf *Result) { // Validates at least one in anyOf schemas var bestFailures *Result @@ -192,7 +181,7 @@ func (s *schemaPropsValidator) validateAnyOf(data interface{}, mainResult, keepR mainResult.Merge(bestFailures) } -func (s *schemaPropsValidator) validateOneOf(data interface{}, mainResult, keepResultOneOf *Result) { +func (s *schemaPropsValidator) validateOneOf(data any, mainResult, keepResultOneOf *Result) { // Validates exactly one in oneOf schemas var ( firstSuccess, bestFailures *Result @@ -251,7 +240,7 @@ func (s *schemaPropsValidator) validateOneOf(data interface{}, mainResult, keepR } } -func (s *schemaPropsValidator) validateAllOf(data interface{}, mainResult, keepResultAllOf *Result) { +func (s *schemaPropsValidator) validateAllOf(data any, mainResult, keepResultAllOf *Result) { // Validates all of allOf schemas var validated int @@ -277,7 +266,7 @@ func (s *schemaPropsValidator) validateAllOf(data interface{}, mainResult, keepR } } -func (s *schemaPropsValidator) validateNot(data interface{}, mainResult *Result) { +func (s *schemaPropsValidator) validateNot(data any, mainResult *Result) { result := s.notValidator.Validate(data) if s.Options.recycleValidators { s.notValidator = nil @@ -291,8 +280,8 @@ func (s *schemaPropsValidator) validateNot(data interface{}, mainResult *Result) } } -func (s *schemaPropsValidator) validateDependencies(data interface{}, mainResult *Result) { - val := data.(map[string]interface{}) +func (s *schemaPropsValidator) validateDependencies(data any, mainResult *Result) { + val := data.(map[string]any) for key := range val { dep, ok := s.Dependencies[key] if !ok { diff --git a/schema_props_test.go b/schema_props_test.go index 760113e..028b4ba 100644 --- a/schema_props_test.go +++ b/schema_props_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/schema_test.go b/schema_test.go index e4cd848..7c6fa48 100644 --- a/schema_test.go +++ b/schema_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -51,7 +40,7 @@ func TestSchemaValidator_Validate_Pattern(t *testing.T) { schema := new(spec.Schema) require.NoError(t, json.Unmarshal([]byte(schemaJSON), schema)) - var input map[string]interface{} + var input map[string]any var inputJSON = `{"name": "Ivan"}` require.NoError(t, json.Unmarshal([]byte(inputJSON), &input)) @@ -88,7 +77,7 @@ func TestSchemaValidator_PatternProperties(t *testing.T) { schema := new(spec.Schema) require.NoError(t, json.Unmarshal([]byte(schemaJSON), schema)) - var input map[string]interface{} + var input map[string]any // ok var inputJSON = `{"name": "Ivan","address-1": "sesame street"}` @@ -119,7 +108,7 @@ func schemaValidatorPanicker() { schema := new(spec.Schema) _ = json.Unmarshal([]byte(schemaJSON), schema) - var input map[string]interface{} + var input map[string]any // ok var inputJSON = `{"name": "Ivan","address-1": "sesame street"}` @@ -201,7 +190,7 @@ func TestSchemaValidator_SchemaOptions(t *testing.T) { schema := new(spec.Schema) require.NoError(t, json.Unmarshal([]byte(schemaJSON), schema)) - var input map[string]interface{} + var input map[string]any var inputJSON = `{"spec": {"items": ["foo", "bar"], "replicas": 1}}` require.NoError(t, json.Unmarshal([]byte(inputJSON), &input)) @@ -225,7 +214,7 @@ func TestSchemaValidator_TypeArray_Issue83(t *testing.T) { schema := new(spec.Schema) require.NoError(t, json.Unmarshal([]byte(schemaJSON), schema)) - var input map[string]interface{} + var input map[string]any var inputJSON = `{"type": "array"}` require.NoError(t, json.Unmarshal([]byte(inputJSON), &input)) diff --git a/slice_validator.go b/slice_validator.go index 7b0dede..4a5a208 100644 --- a/slice_validator.go +++ b/slice_validator.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -30,7 +19,7 @@ type schemaSliceValidator struct { UniqueItems bool AdditionalItems *spec.SchemaOrBool Items *spec.SchemaOrArray - Root interface{} + Root any KnownFormats strfmt.Registry Options *SchemaValidatorOptions } @@ -38,7 +27,7 @@ type schemaSliceValidator struct { func newSliceValidator(path, in string, maxItems, minItems *int64, uniqueItems bool, additionalItems *spec.SchemaOrBool, items *spec.SchemaOrArray, - root interface{}, formats strfmt.Registry, opts *SchemaValidatorOptions) *schemaSliceValidator { + root any, formats strfmt.Registry, opts *SchemaValidatorOptions) *schemaSliceValidator { if opts == nil { opts = new(SchemaValidatorOptions) } @@ -68,13 +57,13 @@ func (s *schemaSliceValidator) SetPath(path string) { s.Path = path } -func (s *schemaSliceValidator) Applies(source interface{}, kind reflect.Kind) bool { +func (s *schemaSliceValidator) Applies(source any, kind reflect.Kind) bool { _, ok := source.(*spec.Schema) r := ok && kind == reflect.Slice return r } -func (s *schemaSliceValidator) Validate(data interface{}) *Result { +func (s *schemaSliceValidator) Validate(data any) *Result { if s.Options.recycleValidators { defer func() { s.redeem() diff --git a/slice_validator_test.go b/slice_validator_test.go index 671b9ca..9df5ad4 100644 --- a/slice_validator_test.go +++ b/slice_validator_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/spec.go b/spec.go index aef0cc3..8616a86 100644 --- a/spec.go +++ b/spec.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -19,6 +8,7 @@ import ( "encoding/gob" "encoding/json" "fmt" + "slices" "sort" "strings" @@ -458,11 +448,8 @@ func (s *SpecValidator) validatePathParamPresence(path string, fromPath, fromOpe for _, p := range fromOperation { var matched bool - for _, r := range fromPath { - if "{"+p+"}" == r { - matched = true - break - } + if slices.Contains(fromPath, "{"+p+"}") { + matched = true } if !matched { res.AddErrors(pathParamNotInPathMsg(path, p)) diff --git a/spec_messages.go b/spec_messages.go index 8da22cf..9b079af 100644 --- a/spec_messages.go +++ b/spec_messages.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -217,10 +206,10 @@ func emptyPathParameterMsg(path string) errors.Error { func nonUniqueOperationIDMsg(path string, i int) errors.Error { return errors.New(errors.CompositeErrorCode, NonUniqueOperationIDError, path, i) } -func circularAncestryDefinitionMsg(path string, args interface{}) errors.Error { +func circularAncestryDefinitionMsg(path string, args any) errors.Error { return errors.New(errors.CompositeErrorCode, CircularAncestryDefinitionError, path, args) } -func duplicatePropertiesMsg(path string, args interface{}) errors.Error { +func duplicatePropertiesMsg(path string, args any) errors.Error { return errors.New(errors.CompositeErrorCode, DuplicatePropertiesError, path, args) } func pathParamNotInPathMsg(path, param string) errors.Error { @@ -262,7 +251,7 @@ func pathParamRequiredMsg(operation, param string) errors.Error { func bothFormDataAndBodyMsg(operation string) errors.Error { return errors.New(errors.CompositeErrorCode, BothFormDataAndBodyError, operation) } -func multipleBodyParamMsg(operation string, args interface{}) errors.Error { +func multipleBodyParamMsg(operation string, args any) errors.Error { return errors.New(errors.CompositeErrorCode, MultipleBodyParamError, operation, args) } func pathParamNotUniqueMsg(path, param, arg string) errors.Error { @@ -304,7 +293,7 @@ func defaultValueHeaderDoesNotValidateMsg(operation, header, path string) errors func defaultValueHeaderItemsDoesNotValidateMsg(operation, header, path string) errors.Error { return errors.New(errors.CompositeErrorCode, DefaultValueHeaderItemsDoesNotValidateError, operation, header, path) } -func invalidPatternInHeaderMsg(operation, header, path, pattern string, args interface{}) errors.Error { +func invalidPatternInHeaderMsg(operation, header, path, pattern string, args any) errors.Error { return errors.New(errors.CompositeErrorCode, InvalidPatternInHeaderError, operation, header, path, pattern, args) } func invalidPatternInMsg(path, in, pattern string) errors.Error { diff --git a/spec_test.go b/spec_test.go index 4dded45..e51e575 100644 --- a/spec_test.go +++ b/spec_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/swagger_test.go b/swagger_test.go index 7bbe61c..797fec4 100644 --- a/swagger_test.go +++ b/swagger_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/type.go b/type.go index 91ae341..9b9ab8d 100644 --- a/type.go +++ b/type.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -60,7 +49,7 @@ func (t *typeValidator) SetPath(path string) { t.Path = path } -func (t *typeValidator) Applies(source interface{}, _ reflect.Kind) bool { +func (t *typeValidator) Applies(source any, _ reflect.Kind) bool { // typeValidator applies to Schema, Parameter and Header objects switch source.(type) { case *spec.Schema: @@ -73,7 +62,7 @@ func (t *typeValidator) Applies(source interface{}, _ reflect.Kind) bool { return (len(t.Type) > 0 || t.Format != "") } -func (t *typeValidator) Validate(data interface{}) *Result { +func (t *typeValidator) Validate(data any) *Result { if t.Options.recycleValidators { defer func() { t.redeem() @@ -120,7 +109,7 @@ func (t *typeValidator) Validate(data interface{}) *Result { return emptyResult } -func (t *typeValidator) schemaInfoForType(data interface{}) (string, string) { +func (t *typeValidator) schemaInfoForType(data any) (string, string) { // internal type to JSON type with swagger 2.0 format (with go-openapi/strfmt extensions), // see https://github.com/go-openapi/strfmt/blob/master/README.md // TODO: this switch really is some sort of reverse lookup for formats. It should be provided by strfmt. diff --git a/type_test.go b/type_test.go index fccf9a8..6a7b777 100644 --- a/type_test.go +++ b/type_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -28,7 +17,7 @@ import ( ) type expectedJSONType struct { - value interface{} + value any expectedJSONType string expectedSwaggerFormat string } diff --git a/validator.go b/validator.go index b76b863..289a847 100644 --- a/validator.go +++ b/validator.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -25,18 +14,18 @@ import ( // An EntityValidator is an interface for things that can validate entities type EntityValidator interface { - Validate(interface{}) *Result + Validate(any) *Result } type valueValidator interface { SetPath(path string) - Applies(interface{}, reflect.Kind) bool - Validate(interface{}) *Result + Applies(any, reflect.Kind) bool + Validate(any) *Result } type itemsValidator struct { items *spec.Items - root interface{} + root any path string in string validators [6]valueValidator @@ -44,7 +33,7 @@ type itemsValidator struct { Options *SchemaValidatorOptions } -func newItemsValidator(path, in string, items *spec.Items, root interface{}, formats strfmt.Registry, opts *SchemaValidatorOptions) *itemsValidator { +func newItemsValidator(path, in string, items *spec.Items, root any, formats strfmt.Registry, opts *SchemaValidatorOptions) *itemsValidator { if opts == nil { opts = new(SchemaValidatorOptions) } @@ -73,7 +62,7 @@ func newItemsValidator(path, in string, items *spec.Items, root interface{}, for return iv } -func (i *itemsValidator) Validate(index int, data interface{}) *Result { +func (i *itemsValidator) Validate(index int, data any) *Result { if i.Options.recycleValidators { defer func() { i.redeemChildren() @@ -226,12 +215,12 @@ func (i *itemsValidator) redeemChildren() { type basicCommonValidator struct { Path string In string - Default interface{} - Enum []interface{} + Default any + Enum []any Options *SchemaValidatorOptions } -func newBasicCommonValidator(path, in string, def interface{}, enum []interface{}, opts *SchemaValidatorOptions) *basicCommonValidator { +func newBasicCommonValidator(path, in string, def any, enum []any, opts *SchemaValidatorOptions) *basicCommonValidator { if opts == nil { opts = new(SchemaValidatorOptions) } @@ -256,7 +245,7 @@ func (b *basicCommonValidator) SetPath(path string) { b.Path = path } -func (b *basicCommonValidator) Applies(source interface{}, _ reflect.Kind) bool { +func (b *basicCommonValidator) Applies(source any, _ reflect.Kind) bool { switch source.(type) { case *spec.Parameter, *spec.Schema, *spec.Header: return true @@ -265,7 +254,7 @@ func (b *basicCommonValidator) Applies(source interface{}, _ reflect.Kind) bool } } -func (b *basicCommonValidator) Validate(data interface{}) (res *Result) { +func (b *basicCommonValidator) Validate(data any) (res *Result) { if b.Options.recycleValidators { defer func() { b.redeem() @@ -352,7 +341,7 @@ func newHeaderValidator(name string, header *spec.Header, formats strfmt.Registr } // Validate the value of the header against its schema -func (p *HeaderValidator) Validate(data interface{}) *Result { +func (p *HeaderValidator) Validate(data any) *Result { if p.Options.recycleValidators { defer func() { p.redeemChildren() @@ -543,7 +532,7 @@ func newParamValidator(param *spec.Parameter, formats strfmt.Registry, opts *Sch } // Validate the data against the description of the parameter -func (p *ParamValidator) Validate(data interface{}) *Result { +func (p *ParamValidator) Validate(data any) *Result { if data == nil { return nil } @@ -685,20 +674,20 @@ func (p *ParamValidator) redeemChildren() { type basicSliceValidator struct { Path string In string - Default interface{} + Default any MaxItems *int64 MinItems *int64 UniqueItems bool Items *spec.Items - Source interface{} + Source any KnownFormats strfmt.Registry Options *SchemaValidatorOptions } func newBasicSliceValidator( path, in string, - def interface{}, maxItems, minItems *int64, uniqueItems bool, items *spec.Items, - source interface{}, formats strfmt.Registry, + def any, maxItems, minItems *int64, uniqueItems bool, items *spec.Items, + source any, formats strfmt.Registry, opts *SchemaValidatorOptions) *basicSliceValidator { if opts == nil { opts = new(SchemaValidatorOptions) @@ -729,7 +718,7 @@ func (s *basicSliceValidator) SetPath(path string) { s.Path = path } -func (s *basicSliceValidator) Applies(source interface{}, kind reflect.Kind) bool { +func (s *basicSliceValidator) Applies(source any, kind reflect.Kind) bool { switch source.(type) { case *spec.Parameter, *spec.Items, *spec.Header: return kind == reflect.Slice @@ -738,7 +727,7 @@ func (s *basicSliceValidator) Applies(source interface{}, kind reflect.Kind) boo } } -func (s *basicSliceValidator) Validate(data interface{}) *Result { +func (s *basicSliceValidator) Validate(data any) *Result { if s.Options.recycleValidators { defer func() { s.redeem() @@ -792,7 +781,7 @@ func (s *basicSliceValidator) redeem() { type numberValidator struct { Path string In string - Default interface{} + Default any MultipleOf *float64 Maximum *float64 ExclusiveMaximum bool @@ -805,7 +794,7 @@ type numberValidator struct { } func newNumberValidator( - path, in string, def interface{}, + path, in string, def any, multipleOf, maximum *float64, exclusiveMaximum bool, minimum *float64, exclusiveMinimum bool, typ, format string, opts *SchemaValidatorOptions) *numberValidator { @@ -839,7 +828,7 @@ func (n *numberValidator) SetPath(path string) { n.Path = path } -func (n *numberValidator) Applies(source interface{}, kind reflect.Kind) bool { +func (n *numberValidator) Applies(source any, kind reflect.Kind) bool { switch source.(type) { case *spec.Parameter, *spec.Schema, *spec.Items, *spec.Header: isInt := kind >= reflect.Int && kind <= reflect.Uint64 @@ -871,7 +860,7 @@ func (n *numberValidator) Applies(source interface{}, kind reflect.Kind) bool { // TODO: consider replacing boundary check errors by simple warnings. // // TODO: default boundaries with MAX_SAFE_INTEGER are not checked (specific to json.Number?) -func (n *numberValidator) Validate(val interface{}) *Result { +func (n *numberValidator) Validate(val any) *Result { if n.Options.recycleValidators { defer func() { n.redeem() @@ -958,7 +947,7 @@ func (n *numberValidator) redeem() { type stringValidator struct { Path string In string - Default interface{} + Default any Required bool AllowEmptyValue bool MaxLength *int64 @@ -969,7 +958,7 @@ type stringValidator struct { func newStringValidator( path, in string, - def interface{}, required, allowEmpty bool, maxLength, minLength *int64, pattern string, + def any, required, allowEmpty bool, maxLength, minLength *int64, pattern string, opts *SchemaValidatorOptions) *stringValidator { if opts == nil { opts = new(SchemaValidatorOptions) @@ -999,7 +988,7 @@ func (s *stringValidator) SetPath(path string) { s.Path = path } -func (s *stringValidator) Applies(source interface{}, kind reflect.Kind) bool { +func (s *stringValidator) Applies(source any, kind reflect.Kind) bool { switch source.(type) { case *spec.Parameter, *spec.Schema, *spec.Items, *spec.Header: return kind == reflect.String @@ -1008,7 +997,7 @@ func (s *stringValidator) Applies(source interface{}, kind reflect.Kind) bool { } } -func (s *stringValidator) Validate(val interface{}) *Result { +func (s *stringValidator) Validate(val any) *Result { if s.Options.recycleValidators { defer func() { s.redeem() diff --git a/validator_test.go b/validator_test.go index f96d61e..29438e3 100644 --- a/validator_test.go +++ b/validator_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -93,7 +82,7 @@ func TestNumberValidator_EdgeCases(t *testing.T) { // numberValidator applies to: Parameter,Schema,Items,Header - sources := []interface{}{ + sources := []any{ new(spec.Parameter), new(spec.Schema), new(spec.Items), @@ -115,7 +104,7 @@ func TestNumberValidator_EdgeCases(t *testing.T) { assert.True(t, res.HasErrors()) } -func testNumberApply(t *testing.T, v *numberValidator, sources []interface{}) { +func testNumberApply(t *testing.T, v *numberValidator, sources []any) { for _, source := range sources { // numberValidator does not applies to: assert.False(t, v.Applies(source, reflect.String)) @@ -145,7 +134,7 @@ func TestStringValidator_EdgeCases(t *testing.T) { // stringValidator applies to: Parameter,Schema,Items,Header - sources := []interface{}{ + sources := []any{ new(spec.Parameter), new(spec.Schema), new(spec.Items), @@ -157,7 +146,7 @@ func TestStringValidator_EdgeCases(t *testing.T) { assert.False(t, v.Applies("A string", reflect.String)) } -func testStringApply(t *testing.T, v *stringValidator, sources []interface{}) { +func testStringApply(t *testing.T, v *stringValidator, sources []any) { for _, source := range sources { // numberValidator does not applies to: assert.False(t, v.Applies(source, reflect.Struct)) @@ -172,12 +161,12 @@ func TestBasicCommonValidator_EdgeCases(t *testing.T) { v := newBasicCommonValidator( "", "", - nil, []interface{}{"a", nil, 3}, nil, + nil, []any{"a", nil, 3}, nil, ) // basicCommonValidator applies to: Parameter,Schema,Header - sources := []interface{}{ + sources := []any{ new(spec.Parameter), new(spec.Schema), new(spec.Header), @@ -215,7 +204,7 @@ func TestBasicCommonValidator_EdgeCases(t *testing.T) { }) } -func testCommonApply(t *testing.T, v *basicCommonValidator, sources []interface{}) { +func testCommonApply(t *testing.T, v *basicCommonValidator, sources []any) { for _, source := range sources { assert.True(t, v.Applies(source, reflect.String)) } @@ -230,7 +219,7 @@ func TestBasicSliceValidator_EdgeCases(t *testing.T) { // basicCommonValidator applies to: Parameter,Schema,Header - sources := []interface{}{ + sources := []any{ new(spec.Parameter), new(spec.Items), new(spec.Header), @@ -254,7 +243,7 @@ func TestBasicSliceValidator_EdgeCases(t *testing.T) { }) } -func testSliceApply(t *testing.T, v *basicSliceValidator, sources []interface{}) { +func testSliceApply(t *testing.T, v *basicSliceValidator, sources []any) { for _, source := range sources { assert.True(t, v.Applies(source, reflect.Slice)) } diff --git a/values.go b/values.go index 1bfa6f3..e7dd5c8 100644 --- a/values.go +++ b/values.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate diff --git a/values_test.go b/values_test.go index d17e332..2b13e9f 100644 --- a/values_test.go +++ b/values_test.go @@ -1,16 +1,5 @@ -// Copyright 2015 go-swagger maintainers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 package validate @@ -26,7 +15,7 @@ import ( ) func TestValues_ValidateIntEnum(t *testing.T) { - enumValues := []interface{}{1, 2, 3} + enumValues := []any{1, 2, 3} require.Error(t, Enum("test", "body", int64(5), enumValues)) require.Nil(t, Enum("test", "body", int64(1), enumValues)) @@ -76,7 +65,7 @@ func TestValues_ValidateEnumCaseInsensitive(t *testing.T) { } func TestValues_ValidateUniqueItems(t *testing.T) { - itemsNonUnique := []interface{}{ + itemsNonUnique := []any{ []int32{1, 2, 3, 4, 4, 5}, []string{"aa", "bb", "cc", "cc", "dd"}, } @@ -84,7 +73,7 @@ func TestValues_ValidateUniqueItems(t *testing.T) { require.Error(t, UniqueItems("test", "body", v)) } - itemsUnique := []interface{}{ + itemsUnique := []any{ []int32{1, 2, 3}, "I'm a string", map[string]int{ @@ -117,18 +106,18 @@ func TestValues_ReadOnly(t *testing.T) { in = "body" ) - ReadOnlySuccess := []interface{}{ + ReadOnlySuccess := []any{ "", 0, nil, } // fail only when operation type is request - ReadOnlyFail := []interface{}{ + ReadOnlyFail := []any{ " ", "bla-bla-bla", 2, - []interface{}{21, []int{}, "testString"}, + []any{21, []int{}, "testString"}, } t.Run("No operation context", func(t *testing.T) { @@ -168,7 +157,7 @@ func TestValues_ValidateRequired(t *testing.T) { in = "body" ) - RequiredFail := []interface{}{ + RequiredFail := []any{ "", 0, nil, @@ -178,11 +167,11 @@ func TestValues_ValidateRequired(t *testing.T) { require.Error(t, Required(path, in, v)) } - RequiredSuccess := []interface{}{ + RequiredSuccess := []any{ " ", "bla-bla-bla", 2, - []interface{}{21, []int{}, "testString"}, + []any{21, []int{}, "testString"}, } for _, v := range RequiredSuccess {