Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ linters:
- gomoddirectives
- gosmopolitan
- inamedparam
#- intrange # disabled while < go1.22
- intrange
- ireturn
- lll
- musttag
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package validate

import (
Expand Down
3 changes: 3 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package validate

import (
Expand Down
3 changes: 3 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package validate

import (
Expand Down
17 changes: 3 additions & 14 deletions debug.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down
15 changes: 2 additions & 13 deletions debug_test.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 2 additions & 13 deletions default_validator.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 2 additions & 13 deletions default_validator_test.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 2 additions & 13 deletions doc.go
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 5 additions & 16 deletions doc_test.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"}`
Expand All @@ -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)
})
Expand Down
15 changes: 2 additions & 13 deletions example_validator.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
15 changes: 2 additions & 13 deletions example_validator_test.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 4 additions & 15 deletions formats.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
}
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion formats_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package validate

import (
Expand Down Expand Up @@ -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
Expand Down
25 changes: 7 additions & 18 deletions helpers.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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, "/")
Expand All @@ -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...)
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
19 changes: 4 additions & 15 deletions helpers_test.go
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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),
Expand Down
Loading
Loading