From 025460618b1d001d945ccee6bde0de34afca694b Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Sun, 9 Nov 2025 15:44:16 +0100 Subject: [PATCH] chore: updated license marks in source files Signed-off-by: Frederic BIDON --- .golangci.yml | 1 - README.md | 4 ++ authinfo_test.go | 15 +--- bytestream.go | 19 ++--- bytestream_test.go | 11 +-- client-middleware/opentracing/opentracing.go | 3 + .../opentracing/opentracing_test.go | 3 + client-middleware/opentracing/runtime.go | 3 + client/auth_info.go | 15 +--- client/auth_info_test.go | 15 +--- client/keepalive.go | 3 + client/keepalive_test.go | 3 + client/mock_test.go | 3 + client/opentelemetry.go | 7 +- client/opentelemetry_test.go | 3 + client/request.go | 15 +--- client/request_test.go | 17 +---- client/response.go | 15 +--- client/response_test.go | 15 +--- client/runtime.go | 17 +---- client/runtime_test.go | 67 ++++++++---------- client/runtime_tls_test.go | 5 +- client_auth_info.go | 15 +--- client_operation.go | 17 +---- client_request.go | 25 ++----- client_request_test.go | 15 +--- client_response.go | 25 ++----- client_response_test.go | 21 ++---- constants.go | 15 +--- csv.go | 19 ++--- csv_options.go | 3 + csv_test.go | 15 +--- discard.go | 7 +- file.go | 15 +--- file_test.go | 3 + flagext/byte_size.go | 3 + flagext/byte_size_test.go | 3 + headers.go | 15 +--- headers_test.go | 15 +--- interfaces.go | 45 +++++------- internal/testing/data.go | 15 +--- internal/testing/data_test.go | 3 + internal/testing/petstore/api.go | 47 +++++-------- internal/testing/petstore/api_test.go | 3 + internal/testing/simplepetstore/api.go | 31 +++------ internal/testing/simplepetstore/api_test.go | 15 +--- json.go | 19 ++--- json_test.go | 15 +--- logger/logger.go | 7 +- logger/logger_test.go | 3 + logger/standard.go | 7 +- middleware/body_test.go | 7 +- middleware/context.go | 25 ++----- middleware/context_test.go | 27 +++----- middleware/debug_test.go | 5 +- middleware/denco/router.go | 15 ++-- middleware/denco/router_bench_test.go | 7 +- middleware/denco/router_test.go | 5 +- middleware/denco/server.go | 3 + middleware/denco/server_test.go | 3 + middleware/denco/util.go | 3 + middleware/denco/util_test.go | 5 +- middleware/doc.go | 15 +--- middleware/header/header.go | 8 ++- middleware/header/header_test.go | 3 + middleware/negotiate.go | 3 + middleware/negotiate_test.go | 3 + middleware/not_implemented.go | 19 ++--- middleware/not_implemented_test.go | 3 + middleware/operation.go | 15 +--- middleware/operation_test.go | 23 ++----- middleware/parameter.go | 49 +++++-------- middleware/parameter_test.go | 27 +++----- middleware/rapidoc.go | 3 + middleware/rapidoc_test.go | 3 + middleware/redoc.go | 3 + middleware/redoc_test.go | 3 + middleware/request.go | 21 ++---- middleware/request_test.go | 29 +++----- middleware/route_authenticator_test.go | 19 ++--- middleware/route_param_test.go | 15 +--- middleware/router.go | 21 ++---- middleware/router_test.go | 15 +--- middleware/security.go | 15 +--- middleware/security_test.go | 15 +--- middleware/spec.go | 15 +--- middleware/spec_test.go | 15 +--- middleware/string_conversion_test.go | 69 ++++++++----------- middleware/swaggerui.go | 3 + middleware/swaggerui_oauth2.go | 3 + middleware/swaggerui_oauth2_test.go | 3 + middleware/swaggerui_test.go | 3 + middleware/ui_options.go | 5 +- middleware/ui_options_test.go | 3 + middleware/untyped/api.go | 15 +--- middleware/untyped/api_test.go | 33 +++------ middleware/untyped_request_test.go | 39 ++++------- middleware/validation.go | 15 +--- middleware/validation_test.go | 15 +--- request.go | 15 +--- request_test.go | 15 +--- security/apikey_auth_test.go | 19 ++--- security/authenticator.go | 55 ++++++--------- security/authorizer.go | 17 +---- security/authorizer_test.go | 19 ++--- security/basic_auth_test.go | 19 ++--- security/bearer_auth_test.go | 7 +- statuses.go | 15 +--- text.go | 19 ++--- text_test.go | 15 +--- values.go | 3 + values_test.go | 3 + xml.go | 19 ++--- xml_test.go | 15 +--- yamlpc/yaml.go | 15 +--- yamlpc/yaml_test.go | 15 +--- 116 files changed, 538 insertions(+), 1118 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5a0faa2e..0087ed31 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,7 +18,6 @@ linters: - gomoddirectives # moved to mono-repo, multi-modules, so replace directives are needed - gosmopolitan - inamedparam - #- intrange # disabled while < go1.22 - ireturn - lll - musttag diff --git a/README.md b/README.md index 25c8c524..9e15b1ad 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,7 @@ Moving forward, we want to : independently from the main package (to avoid breaking changes, the existing API will remain maintained, but evolve at a slower pace than opentelemetry). * [ ] fix a few known issues with some file upload requests (e.g. #286) + +## Licensing + +This library ships under the [SPDX-License-Identifier: Apache-2.0](./LICENSE). diff --git a/authinfo_test.go b/authinfo_test.go index 5f111a97..d3d8b220 100644 --- a/authinfo_test.go +++ b/authinfo_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 runtime diff --git a/bytestream.go b/bytestream.go index 98e96187..eb649742 100644 --- a/bytestream.go +++ b/bytestream.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 runtime @@ -54,7 +43,7 @@ func ByteStreamConsumer(opts ...byteStreamOpt) Consumer { opt(&vals) } - return ConsumerFunc(func(reader io.Reader, data interface{}) error { + return ConsumerFunc(func(reader io.Reader, data any) error { if reader == nil { return errors.New("ByteStreamConsumer requires a reader") // early exit } @@ -148,7 +137,7 @@ func ByteStreamProducer(opts ...byteStreamOpt) Producer { opt(&vals) } - return ProducerFunc(func(writer io.Writer, data interface{}) error { + return ProducerFunc(func(writer io.Writer, data any) error { if writer == nil { return errors.New("ByteStreamProducer requires a writer") // early exit } diff --git a/bytestream_test.go b/bytestream_test.go index 4e5e1133..38b45e66 100644 --- a/bytestream_test.go +++ b/bytestream_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package runtime import ( @@ -62,7 +65,7 @@ func TestByteStreamConsumer(t *testing.T) { }) t.Run("can consume as an interface with underlying type []byte", func(t *testing.T) { - var dest interface{} = []byte{} + var dest any = []byte{} require.NoError(t, consumer.Consume(bytes.NewBufferString(expected), &dest)) asBytes, ok := dest.([]byte) require.True(t, ok) @@ -70,7 +73,7 @@ func TestByteStreamConsumer(t *testing.T) { }) t.Run("can consume as an interface with underlying type string", func(t *testing.T) { - var dest interface{} = "x" + var dest any = "x" require.NoError(t, consumer.Consume(bytes.NewBufferString(expected), &dest)) asString, ok := dest.(string) require.True(t, ok) @@ -274,7 +277,7 @@ func TestByteStreamProducer(t *testing.T) { t.Run("can produce from an interface with underlying type string", func(t *testing.T) { var w bytes.Buffer - var data interface{} = expected + var data any = expected require.NoError(t, producer.Produce(&w, data)) assert.Equal(t, expected, w.String()) }) @@ -289,7 +292,7 @@ func TestByteStreamProducer(t *testing.T) { t.Run("can produce from an interface with underling type []byte", func(t *testing.T) { var w bytes.Buffer - var data interface{} = []byte(expected) + var data any = []byte(expected) require.NoError(t, producer.Produce(&w, data)) assert.Equal(t, expected, w.String()) }) diff --git a/client-middleware/opentracing/opentracing.go b/client-middleware/opentracing/opentracing.go index 8c151b95..df50f799 100644 --- a/client-middleware/opentracing/opentracing.go +++ b/client-middleware/opentracing/opentracing.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package opentracing import ( diff --git a/client-middleware/opentracing/opentracing_test.go b/client-middleware/opentracing/opentracing_test.go index 30a8c114..aa2e911c 100644 --- a/client-middleware/opentracing/opentracing_test.go +++ b/client-middleware/opentracing/opentracing_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package opentracing import ( diff --git a/client-middleware/opentracing/runtime.go b/client-middleware/opentracing/runtime.go index ee334db5..727b671d 100644 --- a/client-middleware/opentracing/runtime.go +++ b/client-middleware/opentracing/runtime.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package opentracing import ( diff --git a/client/auth_info.go b/client/auth_info.go index 4f26e923..a98690c4 100644 --- a/client/auth_info.go +++ b/client/auth_info.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 client diff --git a/client/auth_info_test.go b/client/auth_info_test.go index 0816c71b..1efd5a75 100644 --- a/client/auth_info_test.go +++ b/client/auth_info_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 client diff --git a/client/keepalive.go b/client/keepalive.go index 7dd6b51c..831d23b5 100644 --- a/client/keepalive.go +++ b/client/keepalive.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package client import ( diff --git a/client/keepalive_test.go b/client/keepalive_test.go index b558e048..d97f4eb1 100644 --- a/client/keepalive_test.go +++ b/client/keepalive_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package client import ( diff --git a/client/mock_test.go b/client/mock_test.go index 5b0b9306..068c15dc 100644 --- a/client/mock_test.go +++ b/client/mock_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package client import ( diff --git a/client/opentelemetry.go b/client/opentelemetry.go index db246fc6..e7794129 100644 --- a/client/opentelemetry.go +++ b/client/opentelemetry.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package client import ( @@ -108,7 +111,7 @@ func newOpenTelemetryTransport(transport runtime.ClientTransport, host string, o return tr } -func (t *openTelemetryTransport) Submit(op *runtime.ClientOperation) (interface{}, error) { +func (t *openTelemetryTransport) Submit(op *runtime.ClientOperation) (any, error) { if op.Context == nil { return t.transport.Submit(op) } @@ -128,7 +131,7 @@ func (t *openTelemetryTransport) Submit(op *runtime.ClientOperation) (interface{ return params.WriteToRequest(req, reg) }) - op.Reader = runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + op.Reader = runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if span != nil { statusCode := response.Code() // NOTE: this is replaced by semconv.HTTPResponseStatusCode in semconv v1.21 diff --git a/client/opentelemetry_test.go b/client/opentelemetry_test.go index 0042c3b1..3c9a08a2 100644 --- a/client/opentelemetry_test.go +++ b/client/opentelemetry_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package client import ( diff --git a/client/request.go b/client/request.go index 8f8bab03..6d9b2591 100644 --- a/client/request.go +++ b/client/request.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 client diff --git a/client/request_test.go b/client/request_test.go index 742cc1e8..240fb486 100644 --- a/client/request_test.go +++ b/client/request_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 client @@ -736,7 +725,7 @@ func TestGetBodyCallsBeforeRoundTrip(t *testing.T) { PathPattern: "/", Params: rwrtr, Client: client, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusCreated { var res string if e := consumer.Consume(response.Body(), &res); e != nil { diff --git a/client/response.go b/client/response.go index 0bbd388b..59abc3b5 100644 --- a/client/response.go +++ b/client/response.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 client diff --git a/client/response_test.go b/client/response_test.go index 9368b4c2..c4b9a8b0 100644 --- a/client/response_test.go +++ b/client/response_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 client diff --git a/client/runtime.go b/client/runtime.go index 8dc50c15..203c74e4 100644 --- a/client/runtime.go +++ b/client/runtime.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 client @@ -363,7 +352,7 @@ func (r *Runtime) CreateHttpRequest(operation *runtime.ClientOperation) (req *ht // Submit a request and when there is a body on success it will turn that into the result // all other things are turned into an api error for swagger which retains the status code -func (r *Runtime) Submit(operation *runtime.ClientOperation) (interface{}, error) { +func (r *Runtime) Submit(operation *runtime.ClientOperation) (any, error) { _, readResponse, _ := operation.Params, operation.Reader, operation.AuthInfo request, req, err := r.createHttpRequest(operation) diff --git a/client/runtime_test.go b/client/runtime_test.go index 4835c7ae..6dab3004 100644 --- a/client/runtime_test.go +++ b/client/runtime_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 client @@ -81,17 +70,17 @@ func TestRuntime_Concurrent(t *testing.T) { require.NoError(t, err) rt := New(hu.Host, "/", []string{schemeHTTP}) - resCC := make(chan interface{}) + resCC := make(chan any) errCC := make(chan error) - var res interface{} + var res any for range 6 { go func() { - resC := make(chan interface{}) + resC := make(chan any) errC := make(chan error) go func() { - var resp interface{} + var resp any var errp error for range 3 { resp, errp = rt.Submit(&runtime.ClientOperation{ @@ -99,7 +88,7 @@ func TestRuntime_Concurrent(t *testing.T) { Method: http.MethodGet, PathPattern: "/", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -161,7 +150,7 @@ func TestRuntime_Canary(t *testing.T) { Method: http.MethodGet, PathPattern: "/", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -213,7 +202,7 @@ func TestRuntime_XMLCanary(t *testing.T) { Method: http.MethodGet, PathPattern: "/", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res tasks if e := consumer.Consume(response.Body(), &res); e != nil { @@ -255,7 +244,7 @@ func TestRuntime_TextCanary(t *testing.T) { Method: http.MethodGet, PathPattern: "/", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res string if e := consumer.Consume(response.Body(), &res); e != nil { @@ -300,7 +289,7 @@ func TestRuntime_CSVCanary(t *testing.T) { Method: http.MethodGet, PathPattern: "/", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res bytes.Buffer if e := consumer.Consume(response.Body(), &res); e != nil { @@ -358,7 +347,7 @@ func TestRuntime_CustomTransport(t *testing.T) { PathPattern: "/", Schemes: []string{"ws", "wss", schemeHTTPS}, Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -420,9 +409,9 @@ func TestRuntime_CustomCookieJar(t *testing.T) { PathPattern: "/", Params: rwrtr, AuthInfo: authInfo, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, _ runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, _ runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { - return map[string]interface{}{}, nil + return map[string]any{}, nil } return nil, errors.New("generic error") }), @@ -468,7 +457,7 @@ func TestRuntime_AuthCanary(t *testing.T) { res, err := rt.Submit(&runtime.ClientOperation{ ID: "getTasks", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -520,7 +509,7 @@ func TestRuntime_PickConsumer(t *testing.T) { Schemes: []string{schemeHTTP}, ConsumesMediaTypes: []string{"application/octet-stream"}, Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -573,7 +562,7 @@ func TestRuntime_ContentTypeCanary(t *testing.T) { PathPattern: "/", Schemes: []string{schemeHTTP}, Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -628,7 +617,7 @@ func TestRuntime_ChunkedResponse(t *testing.T) { PathPattern: "/", Schemes: []string{schemeHTTP}, Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -731,8 +720,8 @@ func TestRuntime_OverrideClientOperation(t *testing.T) { Params: runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error { return nil }), - Reader: runtime.ClientResponseReaderFunc(func(_ runtime.ClientResponse, _ runtime.Consumer) (interface{}, error) { - return map[string]interface{}{}, nil + Reader: runtime.ClientResponseReaderFunc(func(_ runtime.ClientResponse, _ runtime.Consumer) (any, error) { + return map[string]any{}, nil }), }) require.NoError(t, err) @@ -768,12 +757,12 @@ func TestRuntime_PreserveTrailingSlash(t *testing.T) { Method: http.MethodGet, PathPattern: "/api/tasks/", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, _ runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, _ runtime.Consumer) (any, error) { if redirected { return nil, errors.New("expected Submit to preserve trailing slashes - this caused a redirect") } if response.Code() == http.StatusOK { - return map[string]interface{}{}, nil + return map[string]any{}, nil } return nil, errors.New("generic error") }), @@ -806,7 +795,7 @@ func TestRuntime_FallbackConsumer(t *testing.T) { Schemes: []string{schemeHTTP}, ConsumesMediaTypes: []string{"application/octet-stream"}, Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []byte if e := consumer.Consume(response.Body(), &res); e != nil { @@ -829,7 +818,7 @@ func TestRuntime_FallbackConsumer(t *testing.T) { Schemes: []string{schemeHTTP}, ConsumesMediaTypes: []string{"application/octet-stream"}, Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []byte if e := consumer.Consume(response.Body(), &res); e != nil { @@ -879,7 +868,7 @@ func TestRuntime_AuthHeaderParamDetected(t *testing.T) { res, err := rt.Submit(&runtime.ClientOperation{ ID: "getTasks", Params: rwrtr, - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { var res []task if e := consumer.Consume(response.Body(), &res); e != nil { @@ -923,7 +912,7 @@ func TestRuntime_Timeout(t *testing.T) { //nolint:maintidx // linter evaluates t }) } - requestReader := runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + requestReader := runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() != http.StatusOK { return nil, errors.New("generic error") } @@ -1269,8 +1258,8 @@ func testDefaultsInTransport(t *testing.T, value string) http.RoundTripper { }) } -func assertResult(result []task) func(testing.TB, interface{}) { - return func(t testing.TB, res interface{}) { +func assertResult(result []task) func(testing.TB, any) { + return func(t testing.TB, res any) { assert.IsType(t, []task{}, res) actual, ok := res.([]task) require.True(t, ok) diff --git a/client/runtime_tls_test.go b/client/runtime_tls_test.go index 98f33b9d..3dd0cf14 100644 --- a/client/runtime_tls_test.go +++ b/client/runtime_tls_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package client import ( @@ -159,7 +162,7 @@ func TestRuntimeManualCertificateValidation(t *testing.T) { Params: runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error { return nil }), - Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) { if response.Code() == http.StatusOK { if e := consumer.Consume(response.Body(), &received); e != nil { return nil, e diff --git a/client_auth_info.go b/client_auth_info.go index c6c97d9a..581e6445 100644 --- a/client_auth_info.go +++ b/client_auth_info.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 runtime diff --git a/client_operation.go b/client_operation.go index 5a5d6356..b0bb0977 100644 --- a/client_operation.go +++ b/client_operation.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 runtime @@ -37,5 +26,5 @@ type ClientOperation struct { // A ClientTransport implementor knows how to submit Request objects to some destination type ClientTransport interface { // Submit(string, RequestWriter, ResponseReader, AuthInfoWriter) (interface{}, error) - Submit(*ClientOperation) (interface{}, error) + Submit(*ClientOperation) (any, error) } diff --git a/client_request.go b/client_request.go index 4ebb2dea..6e335b36 100644 --- a/client_request.go +++ b/client_request.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 runtime @@ -53,7 +42,7 @@ type ClientRequest interface { //nolint:interfacebloat // a swagger-capable requ SetFileParam(string, ...NamedReadCloser) error - SetBodyParam(interface{}) error + SetBodyParam(any) error SetTimeout(time.Duration) error @@ -63,7 +52,7 @@ type ClientRequest interface { //nolint:interfacebloat // a swagger-capable requ GetBody() []byte - GetBodyParam() interface{} + GetBodyParam() any GetFileParam() map[string][]NamedReadCloser } @@ -103,7 +92,7 @@ func (n *namedReadCloser) Name() string { type TestClientRequest struct { Headers http.Header - Body interface{} + Body any } func (t *TestClientRequest) SetHeaderParam(name string, values ...string) error { @@ -122,7 +111,7 @@ func (t *TestClientRequest) SetPathParam(_ string, _ string) error { return nil func (t *TestClientRequest) SetFileParam(_ string, _ ...NamedReadCloser) error { return nil } -func (t *TestClientRequest) SetBodyParam(body interface{}) error { +func (t *TestClientRequest) SetBodyParam(body any) error { t.Body = body return nil } @@ -139,7 +128,7 @@ func (t *TestClientRequest) GetPath() string { return "" } func (t *TestClientRequest) GetBody() []byte { return nil } -func (t *TestClientRequest) GetBodyParam() interface{} { +func (t *TestClientRequest) GetBodyParam() any { return t.Body } diff --git a/client_request_test.go b/client_request_test.go index c6df3e41..8d1e420a 100644 --- a/client_request_test.go +++ b/client_request_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 runtime diff --git a/client_response.go b/client_response.go index b9929946..2be38d23 100644 --- a/client_response.go +++ b/client_response.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 runtime @@ -32,28 +21,28 @@ type ClientResponse interface { } // A ClientResponseReaderFunc turns a function into a ClientResponseReader interface implementation -type ClientResponseReaderFunc func(ClientResponse, Consumer) (interface{}, error) +type ClientResponseReaderFunc func(ClientResponse, Consumer) (any, error) // ReadResponse reads the response -func (read ClientResponseReaderFunc) ReadResponse(resp ClientResponse, consumer Consumer) (interface{}, error) { +func (read ClientResponseReaderFunc) ReadResponse(resp ClientResponse, consumer Consumer) (any, error) { return read(resp, consumer) } // A ClientResponseReader is an interface for things want to read a response. // An application of this is to create structs from response values type ClientResponseReader interface { - ReadResponse(ClientResponse, Consumer) (interface{}, error) + ReadResponse(ClientResponse, Consumer) (any, error) } // APIError wraps an error model and captures the status code type APIError struct { OperationName string - Response interface{} + Response any Code int } // NewAPIError creates a new API error -func NewAPIError(opName string, payload interface{}, code int) *APIError { +func NewAPIError(opName string, payload any, code int) *APIError { return &APIError{ OperationName: opName, Response: payload, diff --git a/client_response_test.go b/client_response_test.go index c5b20a37..33a3929b 100644 --- a/client_response_test.go +++ b/client_response_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 runtime @@ -49,7 +38,7 @@ func TestResponseReaderFunc(t *testing.T) { Header, Message, Body string Code int } - reader := ClientResponseReaderFunc(func(r ClientResponse, _ Consumer) (interface{}, error) { + reader := ClientResponseReaderFunc(func(r ClientResponse, _ Consumer) (any, error) { b, _ := io.ReadAll(r.Body()) actual.Body = string(b) actual.Code = r.Code() @@ -65,7 +54,7 @@ func TestResponseReaderFunc(t *testing.T) { } func TestResponseReaderFuncError(t *testing.T) { - reader := ClientResponseReaderFunc(func(r ClientResponse, _ Consumer) (interface{}, error) { + reader := ClientResponseReaderFunc(func(r ClientResponse, _ Consumer) (any, error) { _, _ = io.ReadAll(r.Body()) return nil, NewAPIError("fake", errors.New("writer closed"), 490) }) @@ -73,7 +62,7 @@ func TestResponseReaderFuncError(t *testing.T) { require.Error(t, err) require.ErrorContains(t, err, "writer closed") - reader = func(r ClientResponse, _ Consumer) (interface{}, error) { + reader = func(r ClientResponse, _ Consumer) (any, error) { _, _ = io.ReadAll(r.Body()) err := &fs.PathError{ Op: "write", diff --git a/constants.go b/constants.go index 51596924..62ae9eec 100644 --- a/constants.go +++ b/constants.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 runtime diff --git a/csv.go b/csv.go index c9597bcd..567e3d9d 100644 --- a/csv.go +++ b/csv.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 runtime @@ -48,7 +37,7 @@ import ( func CSVConsumer(opts ...CSVOpt) Consumer { o := csvOptsWithDefaults(opts) - return ConsumerFunc(func(reader io.Reader, data interface{}) error { + return ConsumerFunc(func(reader io.Reader, data any) error { if reader == nil { return errors.New("CSVConsumer requires a reader") } @@ -181,7 +170,7 @@ func CSVConsumer(opts ...CSVOpt) Consumer { func CSVProducer(opts ...CSVOpt) Producer { o := csvOptsWithDefaults(opts) - return ProducerFunc(func(writer io.Writer, data interface{}) error { + return ProducerFunc(func(writer io.Writer, data any) error { if writer == nil { return errors.New("CSVProducer requires a writer") } diff --git a/csv_options.go b/csv_options.go index 89665788..4cc04390 100644 --- a/csv_options.go +++ b/csv_options.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package runtime import ( diff --git a/csv_test.go b/csv_test.go index ba08d1be..fc326419 100644 --- a/csv_test.go +++ b/csv_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 runtime diff --git a/discard.go b/discard.go index 0d390cfd..b05678be 100644 --- a/discard.go +++ b/discard.go @@ -1,9 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package runtime import "io" // DiscardConsumer does absolutely nothing, it's a black hole. -var DiscardConsumer = ConsumerFunc(func(_ io.Reader, _ interface{}) error { return nil }) +var DiscardConsumer = ConsumerFunc(func(_ io.Reader, _ any) error { return nil }) // DiscardProducer does absolutely nothing, it's a black hole. -var DiscardProducer = ProducerFunc(func(_ io.Writer, _ interface{}) error { return nil }) +var DiscardProducer = ProducerFunc(func(_ io.Writer, _ any) error { return nil }) diff --git a/file.go b/file.go index 1bc6aabf..2a85379a 100644 --- a/file.go +++ b/file.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 runtime diff --git a/file_test.go b/file_test.go index d17c6075..62137238 100644 --- a/file_test.go +++ b/file_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package runtime import ( diff --git a/flagext/byte_size.go b/flagext/byte_size.go index 0f3eeba1..4e514eae 100644 --- a/flagext/byte_size.go +++ b/flagext/byte_size.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package flagext import ( diff --git a/flagext/byte_size_test.go b/flagext/byte_size_test.go index f5853c11..79a4e9a8 100644 --- a/flagext/byte_size_test.go +++ b/flagext/byte_size_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package flagext import ( diff --git a/headers.go b/headers.go index 4d111db4..510e396c 100644 --- a/headers.go +++ b/headers.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 runtime diff --git a/headers_test.go b/headers_test.go index 2b9c46f8..3793b8f9 100644 --- a/headers_test.go +++ b/headers_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 runtime diff --git a/interfaces.go b/interfaces.go index e3341286..90046bf3 100644 --- a/interfaces.go +++ b/interfaces.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 runtime @@ -23,23 +12,23 @@ import ( ) // OperationHandlerFunc an adapter for a function to the OperationHandler interface -type OperationHandlerFunc func(interface{}) (interface{}, error) +type OperationHandlerFunc func(any) (any, error) // Handle implements the operation handler interface -func (s OperationHandlerFunc) Handle(data interface{}) (interface{}, error) { +func (s OperationHandlerFunc) Handle(data any) (any, error) { return s(data) } // OperationHandler a handler for a swagger operation type OperationHandler interface { - Handle(interface{}) (interface{}, error) + Handle(any) (any, error) } // ConsumerFunc represents a function that can be used as a consumer -type ConsumerFunc func(io.Reader, interface{}) error +type ConsumerFunc func(io.Reader, any) error // Consume consumes the reader into the data parameter -func (fn ConsumerFunc) Consume(reader io.Reader, data interface{}) error { +func (fn ConsumerFunc) Consume(reader io.Reader, data any) error { return fn(reader, data) } @@ -47,14 +36,14 @@ func (fn ConsumerFunc) Consume(reader io.Reader, data interface{}) error { // data provided by the request body type Consumer interface { // Consume performs the binding of request values - Consume(io.Reader, interface{}) error + Consume(io.Reader, any) error } // ProducerFunc represents a function that can be used as a producer -type ProducerFunc func(io.Writer, interface{}) error +type ProducerFunc func(io.Writer, any) error // Produce produces the response for the provided data -func (f ProducerFunc) Produce(writer io.Writer, data interface{}) error { +func (f ProducerFunc) Produce(writer io.Writer, data any) error { return f(writer, data) } @@ -62,14 +51,14 @@ func (f ProducerFunc) Produce(writer io.Writer, data interface{}) error { // HTTP response type Producer interface { // Produce writes to the http response - Produce(io.Writer, interface{}) error + Produce(io.Writer, any) error } // AuthenticatorFunc turns a function into an authenticator -type AuthenticatorFunc func(interface{}) (bool, interface{}, error) +type AuthenticatorFunc func(any) (bool, any, error) // Authenticate authenticates the request with the provided data -func (f AuthenticatorFunc) Authenticate(params interface{}) (bool, interface{}, error) { +func (f AuthenticatorFunc) Authenticate(params any) (bool, any, error) { return f(params) } @@ -77,14 +66,14 @@ func (f AuthenticatorFunc) Authenticate(params interface{}) (bool, interface{}, // implementations of Authenticator know how to authenticate the // request data and translate that into a valid principal object or an error type Authenticator interface { - Authenticate(interface{}) (bool, interface{}, error) + Authenticate(any) (bool, any, error) } // AuthorizerFunc turns a function into an authorizer -type AuthorizerFunc func(*http.Request, interface{}) error +type AuthorizerFunc func(*http.Request, any) error // Authorize authorizes the processing of the request for the principal -func (f AuthorizerFunc) Authorize(r *http.Request, principal interface{}) error { +func (f AuthorizerFunc) Authorize(r *http.Request, principal any) error { return f(r, principal) } @@ -92,7 +81,7 @@ func (f AuthorizerFunc) Authorize(r *http.Request, principal interface{}) error // implementations of Authorizer know how to authorize the principal object // using the request data and returns error if unauthorized type Authorizer interface { - Authorize(*http.Request, interface{}) error + Authorize(*http.Request, any) error } // Validatable types implementing this interface allow customizing their validation diff --git a/internal/testing/data.go b/internal/testing/data.go index ff7a7a49..47099af7 100644 --- a/internal/testing/data.go +++ b/internal/testing/data.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 testing diff --git a/internal/testing/data_test.go b/internal/testing/data_test.go index a2f887c7..b83fa989 100644 --- a/internal/testing/data_test.go +++ b/internal/testing/data_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package testing import ( diff --git a/internal/testing/petstore/api.go b/internal/testing/petstore/api.go index b9276b95..449eb6ad 100644 --- a/internal/testing/petstore/api.go +++ b/internal/testing/petstore/api.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 petstore @@ -52,7 +41,7 @@ func NewAPI(t gotest.TB) (*loads.Document, *untyped.API) { api.RegisterConsumer("application/x-yaml", yamlpc.YAMLConsumer()) api.RegisterProducer("application/x-yaml", yamlpc.YAMLProducer()) - api.RegisterAuth("basic", security.BasicAuth(func(username, password string) (interface{}, error) { + api.RegisterAuth("basic", security.BasicAuth(func(username, password string) (any, error) { switch { case username == apiPrincipal && password == apiPrincipal: return apiPrincipal, nil @@ -64,13 +53,13 @@ func NewAPI(t gotest.TB) (*loads.Document, *untyped.API) { return nil, errors.Unauthenticated("basic") } })) - api.RegisterAuth("apiKey", security.APIKeyAuth("X-API-KEY", "header", func(token string) (interface{}, error) { + api.RegisterAuth("apiKey", security.APIKeyAuth("X-API-KEY", "header", func(token string) (any, error) { if token == "token123" { return apiPrincipal, nil } return nil, errors.Unauthenticated("token") })) - api.RegisterAuthorizer(runtime.AuthorizerFunc(func(r *http.Request, user interface{}) error { + api.RegisterAuthorizer(runtime.AuthorizerFunc(func(r *http.Request, user any) error { if r.Method == http.MethodPost && strings.HasPrefix(r.URL.Path, "/api/pets") && user.(string) != apiPrincipal { if user.(string) == apiUser { return errors.CompositeValidationError(errors.New(errors.InvalidTypeCode, "unauthorized")) @@ -85,9 +74,9 @@ func NewAPI(t gotest.TB) (*loads.Document, *untyped.API) { api.RegisterOperation("delete", "/pets/{id}", new(stubOperationHandler)) api.RegisterOperation("get", "/pets/{id}", new(stubOperationHandler)) - api.Models["pet"] = func() interface{} { return new(Pet) } - api.Models["newPet"] = func() interface{} { return new(Pet) } - api.Models["tag"] = func() interface{} { return new(Tag) } + api.Models["pet"] = func() any { return new(Pet) } + api.Models["newPet"] = func() any { return new(Pet) } + api.Models["tag"] = func() any { return new(Tag) } return spec, api } @@ -107,13 +96,13 @@ func NewRootAPI(t gotest.TB) (*loads.Document, *untyped.API) { api.RegisterConsumer("application/x-yaml", yamlpc.YAMLConsumer()) api.RegisterProducer("application/x-yaml", yamlpc.YAMLProducer()) - api.RegisterAuth("basic", security.BasicAuth(func(username, password string) (interface{}, error) { + api.RegisterAuth("basic", security.BasicAuth(func(username, password string) (any, error) { if username == apiPrincipal && password == apiPrincipal { return apiPrincipal, nil } return nil, errors.Unauthenticated("basic") })) - api.RegisterAuth("apiKey", security.APIKeyAuth("X-API-KEY", "header", func(token string) (interface{}, error) { + api.RegisterAuth("apiKey", security.APIKeyAuth("X-API-KEY", "header", func(token string) (any, error) { if token == "token123" { return apiPrincipal, nil } @@ -125,9 +114,9 @@ func NewRootAPI(t gotest.TB) (*loads.Document, *untyped.API) { api.RegisterOperation("delete", "/pets/{id}", new(stubOperationHandler)) api.RegisterOperation("get", "/pets/{id}", new(stubOperationHandler)) - api.Models["pet"] = func() interface{} { return new(Pet) } - api.Models["newPet"] = func() interface{} { return new(Pet) } - api.Models["tag"] = func() interface{} { return new(Tag) } + api.Models["pet"] = func() any { return new(Pet) } + api.Models["newPet"] = func() any { return new(Pet) } + api.Models["tag"] = func() any { return new(Tag) } return spec, api } @@ -150,24 +139,24 @@ type Pet struct { type stubConsumer struct { } -func (s *stubConsumer) Consume(_ io.Reader, _ interface{}) error { +func (s *stubConsumer) Consume(_ io.Reader, _ any) error { return nil } type stubProducer struct { } -func (s *stubProducer) Produce(_ io.Writer, _ interface{}) error { +func (s *stubProducer) Produce(_ io.Writer, _ any) error { return nil } type stubOperationHandler struct { } -func (s *stubOperationHandler) ParameterModel() interface{} { +func (s *stubOperationHandler) ParameterModel() any { return nil } -func (s *stubOperationHandler) Handle(_ interface{}) (interface{}, error) { - return map[string]interface{}{}, nil +func (s *stubOperationHandler) Handle(_ any) (any, error) { + return map[string]any{}, nil } diff --git a/internal/testing/petstore/api_test.go b/internal/testing/petstore/api_test.go index 450b5610..6bfd15b8 100644 --- a/internal/testing/petstore/api_test.go +++ b/internal/testing/petstore/api_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package petstore import ( diff --git a/internal/testing/simplepetstore/api.go b/internal/testing/simplepetstore/api.go index b9194698..2cacfb39 100644 --- a/internal/testing/simplepetstore/api.go +++ b/internal/testing/simplepetstore/api.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 simplepetstore @@ -44,26 +33,26 @@ func NewPetstore() (http.Handler, error) { return middleware.Serve(spec, api), nil } -var getAllPets = runtime.OperationHandlerFunc(func(_ interface{}) (interface{}, error) { +var getAllPets = runtime.OperationHandlerFunc(func(_ any) (any, error) { return pets, nil }) -var createPet = runtime.OperationHandlerFunc(func(data interface{}) (interface{}, error) { - body := data.(map[string]interface{})["pet"].(map[string]interface{}) +var createPet = runtime.OperationHandlerFunc(func(data any) (any, error) { + body := data.(map[string]any)["pet"].(map[string]any) return addPet(Pet{ Name: body["name"].(string), Status: body["status"].(string), }), nil }) -var deletePet = runtime.OperationHandlerFunc(func(data interface{}) (interface{}, error) { - id := data.(map[string]interface{})["id"].(int64) +var deletePet = runtime.OperationHandlerFunc(func(data any) (any, error) { + id := data.(map[string]any)["id"].(int64) removePet(id) - return map[string]interface{}{}, nil + return map[string]any{}, nil }) -var getPetByID = runtime.OperationHandlerFunc(func(data interface{}) (interface{}, error) { - id := data.(map[string]interface{})["id"].(int64) +var getPetByID = runtime.OperationHandlerFunc(func(data any) (any, error) { + id := data.(map[string]any)["id"].(int64) return petByID(id) }) diff --git a/internal/testing/simplepetstore/api_test.go b/internal/testing/simplepetstore/api_test.go index dce37d83..fbaf5950 100644 --- a/internal/testing/simplepetstore/api_test.go +++ b/internal/testing/simplepetstore/api_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 simplepetstore diff --git a/json.go b/json.go index 5a690559..8f93eebf 100644 --- a/json.go +++ b/json.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 runtime @@ -21,7 +10,7 @@ import ( // JSONConsumer creates a new JSON consumer func JSONConsumer() Consumer { - return ConsumerFunc(func(reader io.Reader, data interface{}) error { + return ConsumerFunc(func(reader io.Reader, data any) error { dec := json.NewDecoder(reader) dec.UseNumber() // preserve number formats return dec.Decode(data) @@ -30,7 +19,7 @@ func JSONConsumer() Consumer { // JSONProducer creates a new JSON producer func JSONProducer() Producer { - return ProducerFunc(func(writer io.Writer, data interface{}) error { + return ProducerFunc(func(writer io.Writer, data any) error { enc := json.NewEncoder(writer) enc.SetEscapeHTML(false) return enc.Encode(data) diff --git a/json_test.go b/json_test.go index 82af4c87..6fc35e2f 100644 --- a/json_test.go +++ b/json_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 runtime diff --git a/logger/logger.go b/logger/logger.go index 6f4debcc..45484deb 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -1,10 +1,13 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package logger import "os" type Logger interface { - Printf(format string, args ...interface{}) - Debugf(format string, args ...interface{}) + Printf(format string, args ...any) + Debugf(format string, args ...any) } func DebugEnabled() bool { diff --git a/logger/logger_test.go b/logger/logger_test.go index 78e560d7..d0ba0245 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package logger import ( diff --git a/logger/standard.go b/logger/standard.go index 30035a77..48ba27f4 100644 --- a/logger/standard.go +++ b/logger/standard.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package logger import ( @@ -9,14 +12,14 @@ var _ Logger = StandardLogger{} type StandardLogger struct{} -func (StandardLogger) Printf(format string, args ...interface{}) { +func (StandardLogger) Printf(format string, args ...any) { if len(format) == 0 || format[len(format)-1] != '\n' { format += "\n" } fmt.Fprintf(os.Stderr, format, args...) } -func (StandardLogger) Debugf(format string, args ...interface{}) { +func (StandardLogger) Debugf(format string, args ...any) { if len(format) == 0 || format[len(format)-1] != '\n' { format += "\n" } diff --git a/middleware/body_test.go b/middleware/body_test.go index 5582ab75..6d88bc06 100644 --- a/middleware/body_test.go +++ b/middleware/body_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( @@ -46,7 +49,7 @@ func TestBindRequest_BodyValidation(t *testing.T) { err = ctx.BindValidRequest(req, ri, rbn(func(r *http.Request, _ *MatchedRoute) error { defer r.Body.Close() - var data interface{} + var data any e := runtime.JSONConsumer().Consume(r.Body, &data) _ = data return e @@ -87,7 +90,7 @@ func TestBindRequest_DeleteNoBody(t *testing.T) { err = ctx.BindValidRequest(req, ri, rbn(func(r *http.Request, _ *MatchedRoute) error { defer r.Body.Close() - var data interface{} + var data any e := runtime.JSONConsumer().Consume(r.Body, &data) _ = data return e diff --git a/middleware/context.go b/middleware/context.go index f2cade3c..bb00b93b 100644 --- a/middleware/context.go +++ b/middleware/context.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 middleware @@ -126,7 +115,7 @@ func newRoutableUntypedAPI(spec *loads.Document, api *untyped.API, context *Cont } // bind and validate the request using reflection - var bound interface{} + var bound any var validation error bound, r, validation = context.BindAndValidate(r, route) if validation != nil { @@ -287,7 +276,7 @@ func MatchedRouteFrom(req *http.Request) *MatchedRoute { } // SecurityPrincipalFrom request context value. -func SecurityPrincipalFrom(req *http.Request) interface{} { +func SecurityPrincipalFrom(req *http.Request) any { return req.Context().Value(ctxSecurityPrincipal) } @@ -466,7 +455,7 @@ func (c *Context) ResetAuth(request *http.Request) *http.Request { // Returns the principal object and a shallow copy of the request when its // context doesn't contain the principal, otherwise the same request or an error // (the last) if one of the authenticators returns one or an Unauthenticated error -func (c *Context) Authorize(request *http.Request, route *MatchedRoute) (interface{}, *http.Request, error) { +func (c *Context) Authorize(request *http.Request, route *MatchedRoute) (any, *http.Request, error) { if route == nil || !route.HasAuth() { return nil, nil, nil } @@ -504,7 +493,7 @@ func (c *Context) Authorize(request *http.Request, route *MatchedRoute) (interfa // Returns the validation map and a shallow copy of the request when its context // doesn't contain the validation, otherwise it returns the same request or an // CompositeValidationError error -func (c *Context) BindAndValidate(request *http.Request, matched *MatchedRoute) (interface{}, *http.Request, error) { +func (c *Context) BindAndValidate(request *http.Request, matched *MatchedRoute) (any, *http.Request, error) { var rCtx = request.Context() if v, ok := rCtx.Value(ctxBoundParams).(*validation); ok { @@ -530,7 +519,7 @@ func (c *Context) NotFound(rw http.ResponseWriter, r *http.Request) { } // Respond renders the response after doing some content negotiation -func (c *Context) Respond(rw http.ResponseWriter, r *http.Request, produces []string, route *MatchedRoute, data interface{}) { +func (c *Context) Respond(rw http.ResponseWriter, r *http.Request, produces []string, route *MatchedRoute, data any) { c.debugLogf("responding to %s %s with produces: %v", r.Method, r.URL.Path, produces) offers := []string{} for _, mt := range produces { diff --git a/middleware/context_test.go b/middleware/context_test.go index 33dcd38e..230c8714 100644 --- a/middleware/context_test.go +++ b/middleware/context_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 middleware @@ -43,12 +32,12 @@ func (s *stubBindRequester) BindRequest(*http.Request, *MatchedRoute) error { type stubOperationHandler struct { } -func (s *stubOperationHandler) ParameterModel() interface{} { +func (s *stubOperationHandler) ParameterModel() any { return nil } -func (s *stubOperationHandler) Handle(_ interface{}) (interface{}, error) { - return map[string]interface{}{}, nil +func (s *stubOperationHandler) Handle(_ any) (any, error) { + return map[string]any{}, nil } func init() { @@ -551,7 +540,7 @@ func TestContextRender(t *testing.T) { ri, request, _ := ctx.RouteInfo(request) recorder := httptest.NewRecorder() - ctx.Respond(recorder, request, []string{ct}, ri, map[string]interface{}{"name": "hello"}) + ctx.Respond(recorder, request, []string{ct}, ri, map[string]any{"name": "hello"}) assert.Equal(t, http.StatusOK, recorder.Code) assert.JSONEq(t, "{\"name\":\"hello\"}\n", recorder.Body.String()) @@ -567,7 +556,7 @@ func TestContextRender(t *testing.T) { request, err := http.NewRequestWithContext(stdcontext.Background(), http.MethodGet, "/api/pets", nil) require.NoError(t, err) request.Header.Set(runtime.HeaderAccept, "text/xml") - assert.Panics(t, func() { ctx.Respond(recorder, request, []string{}, nil, map[string]interface{}{"name": "hello"}) }) + assert.Panics(t, func() { ctx.Respond(recorder, request, []string{}, nil, map[string]any{"name": "hello"}) }) request, err = http.NewRequestWithContext(stdcontext.Background(), http.MethodGet, "/api/pets", nil) require.NoError(t, err) @@ -575,7 +564,7 @@ func TestContextRender(t *testing.T) { ri, request, _ = ctx.RouteInfo(request) recorder = httptest.NewRecorder() - ctx.Respond(recorder, request, []string{ct}, ri, map[string]interface{}{"name": "hello"}) + ctx.Respond(recorder, request, []string{ct}, ri, map[string]any{"name": "hello"}) assert.Equal(t, http.StatusOK, recorder.Code) assert.JSONEq(t, "{\"name\":\"hello\"}\n", recorder.Body.String()) diff --git a/middleware/debug_test.go b/middleware/debug_test.go index b89d3a60..e7d1ad46 100644 --- a/middleware/debug_test.go +++ b/middleware/debug_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( @@ -20,7 +23,7 @@ type customLogger struct { lg *log.Logger } -func (l customLogger) Debugf(format string, args ...interface{}) { +func (l customLogger) Debugf(format string, args ...any) { l.lg.Printf(format, args...) } diff --git a/middleware/denco/router.go b/middleware/denco/router.go index 21808ede..b371a2cf 100644 --- a/middleware/denco/router.go +++ b/middleware/denco/router.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Package denco provides fast URL router. package denco @@ -36,14 +39,14 @@ type Router struct { // By default, SizeHint will be determined from given records to Build. SizeHint int - static map[string]interface{} + static map[string]any } // New returns a new Router. func New() *Router { return &Router{ SizeHint: -1, - static: make(map[string]interface{}), + static: make(map[string]any), param: newDoubleArray(), } } @@ -51,7 +54,7 @@ func New() *Router { // Lookup returns data and path parameters that associated with path. // params is a slice of the Param that arranged in the order in which parameters appeared. // e.g. when built routing path is "/path/to/:id/:name" and given path is "/path/to/1/alice". params order is [{"id": "1"}, {"name": "alice"}], not [{"name": "alice"}, {"id": "1"}]. -func (rt *Router) Lookup(path string) (data interface{}, params Params, found bool) { +func (rt *Router) Lookup(path string) (data any, params Params, found bool) { if data, found = rt.static[path]; found { return data, nil, true } @@ -348,7 +351,7 @@ func (da *doubleArray) arrange(records []*record, idx, depth int, usedBase map[i // node represents a node of Double-Array. type node struct { - data interface{} + data any // Names of path parameters. paramNames []string @@ -422,11 +425,11 @@ type Record struct { Key string // Result value for Key. - Value interface{} + Value any } // NewRecord returns a new Record. -func NewRecord(key string, value interface{}) Record { +func NewRecord(key string, value any) Record { return Record{ Key: key, Value: value, diff --git a/middleware/denco/router_bench_test.go b/middleware/denco/router_bench_test.go index 3252e62c..12cfc48d 100644 --- a/middleware/denco/router_bench_test.go +++ b/middleware/denco/router_bench_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package denco_test import ( @@ -146,7 +149,7 @@ func makeTestStaticRecords(n int) []denco.Record { func makeTestSingleParamRecords(n int) []denco.Record { records := make([]denco.Record, n) - for i := 0; i < len(records); i++ { + for i := range records { records[i] = denco.NewRecord(fmt.Sprintf("/user%d/:name", i), fmt.Sprintf("testroute%d", i)) } return records @@ -154,7 +157,7 @@ func makeTestSingleParamRecords(n int) []denco.Record { func makeTestSingle2ParamRecords(n int) []denco.Record { records := make([]denco.Record, n) - for i := 0; i < len(records); i++ { + for i := range records { records[i] = denco.NewRecord(fmt.Sprintf("/user%d/:name/comment/:id", i), fmt.Sprintf("testroute%d", i)) } return records diff --git a/middleware/denco/router_test.go b/middleware/denco/router_test.go index 4b103ade..3ac5d565 100644 --- a/middleware/denco/router_test.go +++ b/middleware/denco/router_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package denco_test import ( @@ -178,7 +181,7 @@ var realURIs = []denco.Record{ type testcase struct { path string - value interface{} + value any params []denco.Param found bool } diff --git a/middleware/denco/server.go b/middleware/denco/server.go index 0886713c..8f04d93d 100644 --- a/middleware/denco/server.go +++ b/middleware/denco/server.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package denco import ( diff --git a/middleware/denco/server_test.go b/middleware/denco/server_test.go index fcc56db2..5fd32b1b 100644 --- a/middleware/denco/server_test.go +++ b/middleware/denco/server_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package denco_test import ( diff --git a/middleware/denco/util.go b/middleware/denco/util.go index edc1f6ab..f002bc46 100644 --- a/middleware/denco/util.go +++ b/middleware/denco/util.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package denco // NextSeparator returns an index of next separator in path. diff --git a/middleware/denco/util_test.go b/middleware/denco/util_test.go index c7241bec..4c94cabc 100644 --- a/middleware/denco/util_test.go +++ b/middleware/denco/util_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package denco_test import ( @@ -11,7 +14,7 @@ func TestNextSeparator(t *testing.T) { for _, testcase := range []struct { path string start int - expected interface{} + expected any }{ {"/path/to/route", 0, 0}, {"/path/to/route", 1, 5}, diff --git a/middleware/doc.go b/middleware/doc.go index 836a9885..04b83223 100644 --- a/middleware/doc.go +++ b/middleware/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 middleware provides the library with helper functions for serving swagger APIs. diff --git a/middleware/header/header.go b/middleware/header/header.go index 13d7dc31..6ce870d8 100644 --- a/middleware/header/header.go +++ b/middleware/header/header.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Copyright 2013 The Go Authors. All rights reserved. // // Use of this source code is governed by a BSD-style @@ -10,6 +13,7 @@ package header import ( + "maps" "net/http" "strings" "time" @@ -65,9 +69,7 @@ func init() { // Copy returns a shallow copy of the header. func Copy(header http.Header) http.Header { h := make(http.Header) - for k, vs := range header { - h[k] = vs - } + maps.Copy(h, header) return h } diff --git a/middleware/header/header_test.go b/middleware/header/header_test.go index ba1525d5..ed090cca 100644 --- a/middleware/header/header_test.go +++ b/middleware/header/header_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package header import ( diff --git a/middleware/negotiate.go b/middleware/negotiate.go index d25d58cf..cb0a8528 100644 --- a/middleware/negotiate.go +++ b/middleware/negotiate.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Copyright 2013 The Go Authors. All rights reserved. // // Use of this source code is governed by a BSD-style diff --git a/middleware/negotiate_test.go b/middleware/negotiate_test.go index 6d28ddfb..7530c858 100644 --- a/middleware/negotiate_test.go +++ b/middleware/negotiate_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + // Copyright 2013 The Go Authors. All rights reserved. // // Use of this source code is governed by a BSD-style diff --git a/middleware/not_implemented.go b/middleware/not_implemented.go index bc6942a0..2e63780c 100644 --- a/middleware/not_implemented.go +++ b/middleware/not_implemented.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 middleware @@ -22,7 +11,7 @@ import ( type errorResp struct { code int - response interface{} + response any headers http.Header } @@ -49,7 +38,7 @@ func NotImplemented(message string) Responder { // Error creates a generic responder for returning errors, the data will be serialized // with the matching producer for the request -func Error(code int, data interface{}, headers ...http.Header) Responder { +func Error(code int, data any, headers ...http.Header) Responder { var hdr http.Header for _, h := range headers { for k, v := range h { diff --git a/middleware/not_implemented_test.go b/middleware/not_implemented_test.go index 44517528..94a8fb67 100644 --- a/middleware/not_implemented_test.go +++ b/middleware/not_implemented_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/operation.go b/middleware/operation.go index 1175a63c..2a7ab1fa 100644 --- a/middleware/operation.go +++ b/middleware/operation.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 middleware diff --git a/middleware/operation_test.go b/middleware/operation_test.go index ddb46590..698b1dff 100644 --- a/middleware/operation_test.go +++ b/middleware/operation_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 middleware @@ -29,9 +18,9 @@ import ( func TestOperationExecutor(t *testing.T) { spec, api := petstore.NewAPI(t) - api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(_ interface{}) (interface{}, error) { - return []interface{}{ - map[string]interface{}{"id": 1, "name": "a dog"}, + api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(_ any) (any, error) { + return []any{ + map[string]any{"id": 1, "name": "a dog"}, }, nil })) @@ -49,7 +38,7 @@ func TestOperationExecutor(t *testing.T) { assert.JSONEq(t, `[{"id":1,"name":"a dog"}]`+"\n", recorder.Body.String()) spec, api = petstore.NewAPI(t) - api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(_ interface{}) (interface{}, error) { + api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(_ any) (any, error) { return nil, errors.New(http.StatusUnprocessableEntity, "expected") })) diff --git a/middleware/parameter.go b/middleware/parameter.go index 5301b4c3..7d630d6c 100644 --- a/middleware/parameter.go +++ b/middleware/parameter.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 middleware @@ -192,34 +181,34 @@ func (p *untypedParamBinder) Bind(request *http.Request, routeParams RouteParams func (p *untypedParamBinder) typeForSchema(tpe, format string, items *spec.Items) reflect.Type { switch tpe { case "boolean": - return reflect.TypeOf(true) + return reflect.TypeFor[bool]() case typeString: if tt, ok := p.formats.GetType(format); ok { return tt } - return reflect.TypeOf("") + return reflect.TypeFor[string]() case "integer": switch format { case "int8": - return reflect.TypeOf(int8(0)) + return reflect.TypeFor[int8]() case "int16": - return reflect.TypeOf(int16(0)) + return reflect.TypeFor[int16]() case "int32": - return reflect.TypeOf(int32(0)) + return reflect.TypeFor[int32]() case "int64": - return reflect.TypeOf(int64(0)) + return reflect.TypeFor[int64]() default: - return reflect.TypeOf(int64(0)) + return reflect.TypeFor[int64]() } case "number": switch format { case "float": - return reflect.TypeOf(float32(0)) + return reflect.TypeFor[float32]() case "double": - return reflect.TypeOf(float64(0)) + return reflect.TypeFor[float64]() } case typeArray: @@ -233,10 +222,10 @@ func (p *untypedParamBinder) typeForSchema(tpe, format string, items *spec.Items return reflect.MakeSlice(reflect.SliceOf(itemsType), 0, 0).Type() case "file": - return reflect.TypeOf(&runtime.File{}).Elem() + return reflect.TypeFor[runtime.File]() case "object": - return reflect.TypeOf(map[string]interface{}{}) + return reflect.TypeFor[map[string]any]() } return nil } @@ -279,7 +268,7 @@ func (p *untypedParamBinder) bindValue(data []string, hasKey bool, target reflec return p.setFieldValue(target, p.parameter.Default, d, hasKey) } -func (p *untypedParamBinder) setFieldValue(target reflect.Value, defaultValue interface{}, data string, hasKey bool) error { //nolint:gocyclo +func (p *untypedParamBinder) setFieldValue(target reflect.Value, defaultValue any, data string, hasKey bool) error { //nolint:gocyclo tpe := p.parameter.Type if p.parameter.Format != "" { tpe = p.parameter.Format @@ -341,7 +330,7 @@ func (p *untypedParamBinder) setFieldValue(target reflect.Value, defaultValue in case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: if data == "" { if target.CanSet() { - rd := defVal.Convert(reflect.TypeOf(int64(0))) + rd := defVal.Convert(reflect.TypeFor[int64]()) target.SetInt(rd.Int()) } return nil @@ -360,7 +349,7 @@ func (p *untypedParamBinder) setFieldValue(target reflect.Value, defaultValue in case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: if data == "" { if target.CanSet() { - rd := defVal.Convert(reflect.TypeOf(uint64(0))) + rd := defVal.Convert(reflect.TypeFor[uint64]()) target.SetUint(rd.Uint()) } return nil @@ -379,7 +368,7 @@ func (p *untypedParamBinder) setFieldValue(target reflect.Value, defaultValue in case reflect.Float32, reflect.Float64: if data == "" { if target.CanSet() { - rd := defVal.Convert(reflect.TypeOf(float64(0))) + rd := defVal.Convert(reflect.TypeFor[float64]()) target.SetFloat(rd.Float()) } return nil @@ -426,7 +415,7 @@ func (p *untypedParamBinder) setFieldValue(target reflect.Value, defaultValue in return nil } -func (p *untypedParamBinder) tryUnmarshaler(target reflect.Value, defaultValue interface{}, data string) (bool, error) { +func (p *untypedParamBinder) tryUnmarshaler(target reflect.Value, defaultValue any, data string) (bool, error) { if !target.CanSet() { return false, nil } @@ -458,7 +447,7 @@ func (p *untypedParamBinder) readFormattedSliceFieldValue(data string, target re return stringutils.SplitByFormat(data, p.parameter.CollectionFormat), false, nil } -func (p *untypedParamBinder) setSliceFieldValue(target reflect.Value, defaultValue interface{}, data []string, hasKey bool) error { +func (p *untypedParamBinder) setSliceFieldValue(target reflect.Value, defaultValue any, data []string, hasKey bool) error { sz := len(data) if (!hasKey || (!p.parameter.AllowEmptyValue && (sz == 0 || (sz == 1 && data[0] == "")))) && p.parameter.Required && defaultValue == nil { return errors.Required(p.Name, p.parameter.In, data) diff --git a/middleware/parameter_test.go b/middleware/parameter_test.go index cbec8ab8..eb2eba1d 100644 --- a/middleware/parameter_test.go +++ b/middleware/parameter_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 middleware @@ -62,7 +51,7 @@ func testCollectionFormat(t *testing.T, param *spec.Parameter, valid bool) { } } -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) } @@ -135,8 +124,8 @@ func TestRequiredValidation(t *testing.T) { // validateRequiredAllowEmptyTest(t, dateParam, reflect.ValueOf(strfmt.DateTime{})) sliceParam := spec.QueryParam("tags").CollectionOf(stringItems, "").AsRequired() - validateRequiredTest(t, sliceParam, reflect.MakeSlice(reflect.TypeOf([]string{}), 0, 0)) - validateRequiredAllowEmptyTest(t, sliceParam, reflect.MakeSlice(reflect.TypeOf([]string{}), 0, 0)) + validateRequiredTest(t, sliceParam, reflect.MakeSlice(reflect.TypeFor[[]string](), 0, 0)) + validateRequiredAllowEmptyTest(t, sliceParam, reflect.MakeSlice(reflect.TypeFor[[]string](), 0, 0)) } func TestInvalidCollectionFormat(t *testing.T) { @@ -151,7 +140,7 @@ func TestInvalidCollectionFormat(t *testing.T) { testCollectionFormat(t, invalidCf2, false) } -func invalidTypeError(param *spec.Parameter, data interface{}) *errors.Validation { +func invalidTypeError(param *spec.Parameter, data any) *errors.Validation { tpe := param.Type if param.Format != "" { tpe = param.Format @@ -208,7 +197,7 @@ func TestTypeValidation(t *testing.T) { // fails for overflow str3 := strconv.FormatFloat(math.MaxFloat64, 'f', 5, 64) - v3 := reflect.TypeOf(float32(0)) + v3 := reflect.TypeFor[float32]() value = reflect.New(v3).Elem() binder = np(floatParam) err = binder.bindValue([]string{str3}, true, value) @@ -225,7 +214,7 @@ func TestTypeValidation(t *testing.T) { // fails for overflow str4 := "9" + strconv.FormatFloat(math.MaxFloat64, 'f', 5, 64) - v4 := reflect.TypeOf(float64(0)) + v4 := reflect.TypeFor[float64]() value = reflect.New(v4).Elem() binder = np(doubleParam) err = binder.bindValue([]string{str4}, true, value) diff --git a/middleware/rapidoc.go b/middleware/rapidoc.go index ef75e744..6039a26f 100644 --- a/middleware/rapidoc.go +++ b/middleware/rapidoc.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/rapidoc_test.go b/middleware/rapidoc_test.go index 50682ee6..63d39231 100644 --- a/middleware/rapidoc_test.go +++ b/middleware/rapidoc_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/redoc.go b/middleware/redoc.go index b96b01e7..cbaec73c 100644 --- a/middleware/redoc.go +++ b/middleware/redoc.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/redoc_test.go b/middleware/redoc_test.go index f1178988..35c760b5 100644 --- a/middleware/redoc_test.go +++ b/middleware/redoc_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/request.go b/middleware/request.go index 577e4a0f..52facfef 100644 --- a/middleware/request.go +++ b/middleware/request.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 middleware @@ -50,7 +39,7 @@ func NewUntypedRequestBinder(parameters map[string]spec.Parameter, spec *spec.Sw } // Bind perform the databinding and validation -func (o *UntypedRequestBinder) Bind(request *http.Request, routeParams RouteParams, consumer runtime.Consumer, data interface{}) error { +func (o *UntypedRequestBinder) Bind(request *http.Request, routeParams RouteParams, consumer runtime.Consumer, data any) error { val := reflect.Indirect(reflect.ValueOf(data)) isMap := val.Kind() == reflect.Map var result []error @@ -68,9 +57,9 @@ func (o *UntypedRequestBinder) Bind(request *http.Request, routeParams RoutePara tpe := binder.Type() if tpe == nil { if param.Schema.Type.Contains(typeArray) { - tpe = reflect.TypeOf([]interface{}{}) + tpe = reflect.TypeFor[[]any]() } else { - tpe = reflect.TypeOf(map[string]interface{}{}) + tpe = reflect.TypeFor[map[string]any]() } } target = reflect.Indirect(reflect.New(tpe)) diff --git a/middleware/request_test.go b/middleware/request_test.go index ebf0f5c3..b9390da8 100644 --- a/middleware/request_test.go +++ b/middleware/request_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 middleware @@ -40,7 +29,7 @@ const ( type stubConsumer struct { } -func (s *stubConsumer) Consume(_ io.Reader, _ interface{}) error { +func (s *stubConsumer) Consume(_ io.Reader, _ any) error { return nil } @@ -87,7 +76,7 @@ func parametersForAllTypes(fmt string) map[string]spec.Parameter { friendParam := spec.BodyParam("friend", friendSchema) requestIDParam := spec.HeaderParam("X-Request-Id").Typed("integer", "int64") - requestIDParam.Extensions = spec.Extensions(map[string]interface{}{}) + requestIDParam.Extensions = spec.Extensions(map[string]any{}) requestIDParam.Extensions.Add("go-name", "RequestID") items := new(spec.Items) @@ -126,7 +115,7 @@ func parametersForJSONRequestParams(fmt string) map[string]spec.Parameter { friendParam := spec.BodyParam("friend", friendSchema) requestIDParam := spec.HeaderParam("X-Request-Id").Typed("integer", "int64") - requestIDParam.Extensions = spec.Extensions(map[string]interface{}{}) + requestIDParam.Extensions = spec.Extensions(map[string]any{}) requestIDParam.Extensions.Add("go-name", "RequestID") items := new(spec.Items) @@ -152,7 +141,7 @@ func parametersForJSONRequestSliceParams(fmt string) map[string]spec.Parameter { friendParam := spec.BodyParam("friend", spec.ArrayProperty(friendSchema)) requestIDParam := spec.HeaderParam("X-Request-Id").Typed("integer", "int64") - requestIDParam.Extensions = spec.Extensions(map[string]interface{}{}) + requestIDParam.Extensions = spec.Extensions(map[string]any{}) requestIDParam.Extensions.Add("go-name", "RequestID") items := new(spec.Items) @@ -171,7 +160,7 @@ func parametersForJSONRequestSliceParams(fmt string) map[string]spec.Parameter { func TestRequestBindingDefaultValue(t *testing.T) { confirmed := true name := "thomas" - friend := map[string]interface{}{"name": "toby", "age": float64(32)} + friend := map[string]any{"name": "toby", "age": float64(32)} id, age, score, factor := int64(7575), int32(348), float32(5.309), float64(37.403) requestID := 19394858 tags := []string{"one", "two", "three"} @@ -181,7 +170,7 @@ func TestRequestBindingDefaultValue(t *testing.T) { delivered := strfmt.DateTime(dt2) uri, err := url.Parse(testURL) require.NoError(t, err) - defaults := map[string]interface{}{ + defaults := map[string]any{ "id": id, "age": age, "score": score, @@ -207,7 +196,7 @@ func TestRequestBindingDefaultValue(t *testing.T) { req.Header.Set("Content-Type", "application/json") binder := NewUntypedRequestBinder(op3, new(spec.Swagger), strfmt.Default) - data := make(map[string]interface{}) + data := make(map[string]any) err = binder.Bind(req, RouteParams(nil), runtime.JSONConsumer(), &data) require.NoError(t, err) assert.Equal(t, defaults["id"], data["id"]) diff --git a/middleware/route_authenticator_test.go b/middleware/route_authenticator_test.go index aa5d9c46..7183a44d 100644 --- a/middleware/route_authenticator_test.go +++ b/middleware/route_authenticator_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( @@ -14,27 +17,27 @@ import ( type countAuthenticator struct { count int applies bool - principal interface{} + principal any err error } -func (c *countAuthenticator) Authenticate(_ interface{}) (bool, interface{}, error) { +func (c *countAuthenticator) Authenticate(_ any) (bool, any, error) { c.count++ return c.applies, c.principal, c.err } -func newCountAuthenticator(applies bool, principal interface{}, err error) *countAuthenticator { +func newCountAuthenticator(applies bool, principal any, err error) *countAuthenticator { return &countAuthenticator{applies: applies, principal: principal, err: err} } var ( - successAuth = runtime.AuthenticatorFunc(func(_ interface{}) (bool, interface{}, error) { + successAuth = runtime.AuthenticatorFunc(func(_ any) (bool, any, error) { return true, "the user", nil }) - failAuth = runtime.AuthenticatorFunc(func(_ interface{}) (bool, interface{}, error) { + failAuth = runtime.AuthenticatorFunc(func(_ any) (bool, any, error) { return true, nil, errors.New("unauthenticated") }) - noApplyAuth = runtime.AuthenticatorFunc(func(_ interface{}) (bool, interface{}, error) { + noApplyAuth = runtime.AuthenticatorFunc(func(_ any) (bool, any, error) { return false, nil, nil }) ) @@ -135,11 +138,11 @@ func TestAuthenticateLogicalAnd(t *testing.T) { require.Equal(t, 2, authorizer.count) var count int - successA := runtime.AuthenticatorFunc(func(_ interface{}) (bool, interface{}, error) { + successA := runtime.AuthenticatorFunc(func(_ any) (bool, any, error) { count++ return true, "the user", nil }) - failA := runtime.AuthenticatorFunc(func(_ interface{}) (bool, interface{}, error) { + failA := runtime.AuthenticatorFunc(func(_ any) (bool, any, error) { count++ return true, nil, errors.New("unauthenticated") }) diff --git a/middleware/route_param_test.go b/middleware/route_param_test.go index 714646a1..02727c46 100644 --- a/middleware/route_param_test.go +++ b/middleware/route_param_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 middleware diff --git a/middleware/router.go b/middleware/router.go index 0f931790..16816580 100644 --- a/middleware/router.go +++ b/middleware/router.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 middleware @@ -208,13 +197,13 @@ func (ra *RouteAuthenticator) CommonScopes() []string { } // Authenticate Authenticator interface implementation -func (ra *RouteAuthenticator) Authenticate(req *http.Request, route *MatchedRoute) (bool, interface{}, error) { +func (ra *RouteAuthenticator) Authenticate(req *http.Request, route *MatchedRoute) (bool, any, error) { if ra.allowAnonymous { route.Authenticator = ra return true, nil, nil } // iterate in proper order - var lastResult interface{} + var lastResult any for _, scheme := range ra.Schemes { if authenticator, ok := ra.Authenticator[scheme]; ok { applies, princ, err := authenticator.Authenticate(&security.ScopedAuthRequest{ @@ -287,7 +276,7 @@ func (ras RouteAuthenticators) AllowsAnonymous() bool { } // Authenticate method implemention so this collection can be used as authenticator -func (ras RouteAuthenticators) Authenticate(req *http.Request, route *MatchedRoute) (bool, interface{}, error) { +func (ras RouteAuthenticators) Authenticate(req *http.Request, route *MatchedRoute) (bool, any, error) { var lastError error var allowsAnon bool var anonAuth RouteAuthenticator diff --git a/middleware/router_test.go b/middleware/router_test.go index 6d6a56a6..f98ae433 100644 --- a/middleware/router_test.go +++ b/middleware/router_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 middleware diff --git a/middleware/security.go b/middleware/security.go index 2b061cae..37ecfa6f 100644 --- a/middleware/security.go +++ b/middleware/security.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 middleware diff --git a/middleware/security_test.go b/middleware/security_test.go index 90b01bdb..6dbf0268 100644 --- a/middleware/security_test.go +++ b/middleware/security_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 middleware diff --git a/middleware/spec.go b/middleware/spec.go index 87e17e34..9cc9940a 100644 --- a/middleware/spec.go +++ b/middleware/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 middleware diff --git a/middleware/spec_test.go b/middleware/spec_test.go index 3282461c..324da540 100644 --- a/middleware/spec_test.go +++ b/middleware/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 middleware diff --git a/middleware/string_conversion_test.go b/middleware/string_conversion_test.go index 93bcae2e..eda31bf3 100644 --- a/middleware/string_conversion_test.go +++ b/middleware/string_conversion_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 middleware @@ -64,7 +53,7 @@ type SomeOperationParams struct { Categories unmarshallerSlice } -func FloatParamTest(t *testing.T, _, pName, _ string, val reflect.Value, defVal, expectedDef interface{}, actual func() interface{}) { +func FloatParamTest(t *testing.T, _, pName, _ string, val reflect.Value, defVal, expectedDef any, actual func() any) { fld := val.FieldByName(pName) binder := &untypedParamBinder{ parameter: spec.QueryParam(pName).Typed("number", "double").WithDefault(defVal), @@ -83,7 +72,7 @@ func FloatParamTest(t *testing.T, _, pName, _ string, val reflect.Value, defVal, require.Error(t, err) } -func IntParamTest(t *testing.T, pName string, val reflect.Value, defVal, expectedDef interface{}, actual func() interface{}) { +func IntParamTest(t *testing.T, pName string, val reflect.Value, defVal, expectedDef any, actual func() any) { fld := val.FieldByName(pName) binder := &untypedParamBinder{ @@ -121,31 +110,31 @@ func TestParamBinding(t *testing.T) { require.NoError(t, err) assert.Equal(t, "some-name", actual.Name) - IntParamTest(t, "ID", val, 1, 1, func() interface{} { return actual.ID }) - IntParamTest(t, "ID", val, nil, 0, func() interface{} { return actual.ID }) - IntParamTest(t, "Age", val, 1, 1, func() interface{} { return actual.Age }) - IntParamTest(t, "Age", val, nil, 0, func() interface{} { return actual.Age }) - IntParamTest(t, "Visits", val, 1, 1, func() interface{} { return actual.Visits }) - IntParamTest(t, "Visits", val, nil, 0, func() interface{} { return actual.Visits }) - IntParamTest(t, "Count", val, 1, 1, func() interface{} { return actual.Count }) - IntParamTest(t, "Count", val, nil, 0, func() interface{} { return actual.Count }) - IntParamTest(t, "Seq", val, 1, 1, func() interface{} { return actual.Seq }) - IntParamTest(t, "Seq", val, nil, 0, func() interface{} { return actual.Seq }) - IntParamTest(t, "UID", val, uint64(1), 1, func() interface{} { return actual.UID }) - IntParamTest(t, "UID", val, uint64(0), 0, func() interface{} { return actual.UID }) - IntParamTest(t, "UAge", val, uint(1), 1, func() interface{} { return actual.UAge }) - IntParamTest(t, "UAge", val, nil, 0, func() interface{} { return actual.UAge }) - IntParamTest(t, "UVisits", val, uint32(1), 1, func() interface{} { return actual.UVisits }) - IntParamTest(t, "UVisits", val, nil, 0, func() interface{} { return actual.UVisits }) - IntParamTest(t, "UCount", val, uint16(1), 1, func() interface{} { return actual.UCount }) - IntParamTest(t, "UCount", val, nil, 0, func() interface{} { return actual.UCount }) - IntParamTest(t, "USeq", val, uint8(1), 1, func() interface{} { return actual.USeq }) - IntParamTest(t, "USeq", val, nil, 0, func() interface{} { return actual.USeq }) - - FloatParamTest(t, "score", "Score", "float", val, 1.0, 1, func() interface{} { return actual.Score }) - FloatParamTest(t, "score", "Score", "float", val, nil, 0, func() interface{} { return actual.Score }) - FloatParamTest(t, "rate", "Rate", "double", val, 1.0, 1, func() interface{} { return actual.Rate }) - FloatParamTest(t, "rate", "Rate", "double", val, nil, 0, func() interface{} { return actual.Rate }) + IntParamTest(t, "ID", val, 1, 1, func() any { return actual.ID }) + IntParamTest(t, "ID", val, nil, 0, func() any { return actual.ID }) + IntParamTest(t, "Age", val, 1, 1, func() any { return actual.Age }) + IntParamTest(t, "Age", val, nil, 0, func() any { return actual.Age }) + IntParamTest(t, "Visits", val, 1, 1, func() any { return actual.Visits }) + IntParamTest(t, "Visits", val, nil, 0, func() any { return actual.Visits }) + IntParamTest(t, "Count", val, 1, 1, func() any { return actual.Count }) + IntParamTest(t, "Count", val, nil, 0, func() any { return actual.Count }) + IntParamTest(t, "Seq", val, 1, 1, func() any { return actual.Seq }) + IntParamTest(t, "Seq", val, nil, 0, func() any { return actual.Seq }) + IntParamTest(t, "UID", val, uint64(1), 1, func() any { return actual.UID }) + IntParamTest(t, "UID", val, uint64(0), 0, func() any { return actual.UID }) + IntParamTest(t, "UAge", val, uint(1), 1, func() any { return actual.UAge }) + IntParamTest(t, "UAge", val, nil, 0, func() any { return actual.UAge }) + IntParamTest(t, "UVisits", val, uint32(1), 1, func() any { return actual.UVisits }) + IntParamTest(t, "UVisits", val, nil, 0, func() any { return actual.UVisits }) + IntParamTest(t, "UCount", val, uint16(1), 1, func() any { return actual.UCount }) + IntParamTest(t, "UCount", val, nil, 0, func() any { return actual.UCount }) + IntParamTest(t, "USeq", val, uint8(1), 1, func() any { return actual.USeq }) + IntParamTest(t, "USeq", val, nil, 0, func() any { return actual.USeq }) + + FloatParamTest(t, "score", "Score", "float", val, 1.0, 1, func() any { return actual.Score }) + FloatParamTest(t, "score", "Score", "float", val, nil, 0, func() any { return actual.Score }) + FloatParamTest(t, "rate", "Rate", "double", val, 1.0, 1, func() any { return actual.Rate }) + FloatParamTest(t, "rate", "Rate", "double", val, nil, 0, func() any { return actual.Rate }) pName = "Confirmed" confirmedField := val.FieldByName(pName) diff --git a/middleware/swaggerui.go b/middleware/swaggerui.go index ec3c10cb..b25a3a2c 100644 --- a/middleware/swaggerui.go +++ b/middleware/swaggerui.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/swaggerui_oauth2.go b/middleware/swaggerui_oauth2.go index e81212f7..879bdbaa 100644 --- a/middleware/swaggerui_oauth2.go +++ b/middleware/swaggerui_oauth2.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/swaggerui_oauth2_test.go b/middleware/swaggerui_oauth2_test.go index a19c4307..c3c31f8b 100644 --- a/middleware/swaggerui_oauth2_test.go +++ b/middleware/swaggerui_oauth2_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/swaggerui_test.go b/middleware/swaggerui_test.go index b299c09d..6bcdddd5 100644 --- a/middleware/swaggerui_test.go +++ b/middleware/swaggerui_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/ui_options.go b/middleware/ui_options.go index 7a5fb16f..cf2f673d 100644 --- a/middleware/ui_options.go +++ b/middleware/ui_options.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( @@ -39,7 +42,7 @@ type uiOptions struct { // toCommonUIOptions converts any UI option type to retain the common options. // // This uses gob encoding/decoding to convert common fields from one struct to another. -func toCommonUIOptions(opts interface{}) uiOptions { +func toCommonUIOptions(opts any) uiOptions { var buf bytes.Buffer enc := gob.NewEncoder(&buf) dec := gob.NewDecoder(&buf) diff --git a/middleware/ui_options_test.go b/middleware/ui_options_test.go index 71833691..686f94fe 100644 --- a/middleware/ui_options_test.go +++ b/middleware/ui_options_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package middleware import ( diff --git a/middleware/untyped/api.go b/middleware/untyped/api.go index a98d6690..774da0ba 100644 --- a/middleware/untyped/api.go +++ b/middleware/untyped/api.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 untyped diff --git a/middleware/untyped/api_test.go b/middleware/untyped/api_test.go index fa2a1fe6..238e746c 100644 --- a/middleware/untyped/api_test.go +++ b/middleware/untyped/api_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 untyped @@ -30,36 +19,36 @@ import ( ) func stubAutenticator() runtime.Authenticator { - return runtime.AuthenticatorFunc(func(_ interface{}) (bool, interface{}, error) { return false, nil, nil }) + return runtime.AuthenticatorFunc(func(_ any) (bool, any, error) { return false, nil, nil }) } func stubAuthorizer() runtime.Authorizer { - return runtime.AuthorizerFunc(func(_ *http.Request, _ interface{}) error { return nil }) + return runtime.AuthorizerFunc(func(_ *http.Request, _ any) error { return nil }) } type stubConsumer struct { } -func (s *stubConsumer) Consume(_ io.Reader, _ interface{}) error { +func (s *stubConsumer) Consume(_ io.Reader, _ any) error { return nil } type stubProducer struct { } -func (s *stubProducer) Produce(_ io.Writer, _ interface{}) error { +func (s *stubProducer) Produce(_ io.Writer, _ any) error { return nil } type stubOperationHandler struct { } -func (s *stubOperationHandler) ParameterModel() interface{} { +func (s *stubOperationHandler) ParameterModel() any { return nil } -func (s *stubOperationHandler) Handle(_ interface{}) (interface{}, error) { - return map[string]interface{}{}, nil +func (s *stubOperationHandler) Handle(_ any) (any, error) { + return map[string]any{}, nil } func TestUntypedAPIRegistrations(t *testing.T) { @@ -271,14 +260,14 @@ func TestUntypedAppValidation(t *testing.T) { authenticators := api3.AuthenticatorsFor(definitions) assert.Len(t, authenticators, 1) - opHandler := runtime.OperationHandlerFunc(func(data interface{}) (interface{}, error) { + opHandler := runtime.OperationHandlerFunc(func(data any) (any, error) { return data, nil }) d, err := opHandler.Handle(1) require.NoError(t, err) assert.Equal(t, 1, d) - authenticator := runtime.AuthenticatorFunc(func(params interface{}) (bool, interface{}, error) { + authenticator := runtime.AuthenticatorFunc(func(params any) (bool, any, error) { if str, ok := params.(string); ok { return ok, str, nil } diff --git a/middleware/untyped_request_test.go b/middleware/untyped_request_test.go index 8cdf2c06..e366d663 100644 --- a/middleware/untyped_request_test.go +++ b/middleware/untyped_request_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 middleware @@ -41,7 +30,7 @@ func TestUntypedFormPost(t *testing.T) { require.NoError(t, err) req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - data := make(map[string]interface{}) + data := make(map[string]any) require.NoError(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) assert.Equal(t, "the-name", data["name"]) assert.EqualValues(t, 32, data["age"]) @@ -50,7 +39,7 @@ func TestUntypedFormPost(t *testing.T) { require.NoError(t, err) req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - data = make(map[string]interface{}) + data = make(map[string]any) require.Error(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) } @@ -71,7 +60,7 @@ func TestUntypedFileUpload(t *testing.T) { require.NoError(t, err) req.Header.Set("Content-Type", writer.FormDataContentType()) - data := make(map[string]interface{}) + data := make(map[string]any) require.NoError(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) assert.Equal(t, "the-name", data["name"]) assert.NotNil(t, data["file"]) @@ -87,13 +76,13 @@ func TestUntypedFileUpload(t *testing.T) { req, err = http.NewRequestWithContext(context.Background(), http.MethodPost, testURL, body) require.NoError(t, err) req.Header.Set("Content-Type", "application/json") - data = make(map[string]interface{}) + data = make(map[string]any) require.Error(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) req, err = http.NewRequestWithContext(context.Background(), http.MethodPost, testURL, body) require.NoError(t, err) req.Header.Set("Content-Type", "application(") - data = make(map[string]interface{}) + data = make(map[string]any) require.Error(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) body = bytes.NewBuffer(nil) @@ -109,7 +98,7 @@ func TestUntypedFileUpload(t *testing.T) { require.NoError(t, err) req.Header.Set("Content-Type", writer.FormDataContentType()) - data = make(map[string]interface{}) + data = make(map[string]any) require.Error(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) req, err = http.NewRequestWithContext(context.Background(), http.MethodPost, testURL, body) @@ -118,7 +107,7 @@ func TestUntypedFileUpload(t *testing.T) { _, err = req.MultipartReader() require.NoError(t, err) - data = make(map[string]interface{}) + data = make(map[string]any) require.Error(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) writer = multipart.NewWriter(body) @@ -129,7 +118,7 @@ func TestUntypedFileUpload(t *testing.T) { require.NoError(t, err) req.Header.Set("Content-Type", writer.FormDataContentType()) - data = make(map[string]interface{}) + data = make(map[string]any) require.Error(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) } @@ -145,7 +134,7 @@ func TestUntypedOptionalFileUpload(t *testing.T) { require.NoError(t, err) req.Header.Set("Content-Type", writer.FormDataContentType()) - data := make(map[string]interface{}) + data := make(map[string]any) require.NoError(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) assert.Equal(t, "the-name", data["name"]) @@ -162,7 +151,7 @@ func TestUntypedOptionalFileUpload(t *testing.T) { req.Header.Set("Content-Type", writer.FormDataContentType()) require.NoError(t, writer.Close()) - data = make(map[string]interface{}) + data = make(map[string]any) require.NoError(t, binder.Bind(req, nil, runtime.JSONConsumer(), &data)) assert.Equal(t, "the-name", data["name"]) assert.NotNil(t, data["file"]) @@ -179,7 +168,7 @@ func TestUntypedBindingTypesForValid(t *testing.T) { confirmed := true name := "thomas" - friend := map[string]interface{}{"name": "toby", "age": json.Number("32")} + friend := map[string]any{"name": "toby", "age": json.Number("32")} id, age, score, factor := int64(7575), int32(348), float32(5.309), float64(37.403) requestID := 19394858 tags := []string{"one", "two", "three"} @@ -206,7 +195,7 @@ func TestUntypedBindingTypesForValid(t *testing.T) { req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Request-Id", "19394858") - data := make(map[string]interface{}) + data := make(map[string]any) err = binder.Bind(req, RouteParams([]RouteParam{{"id", "7575"}}), runtime.JSONConsumer(), &data) require.NoError(t, err) assert.Equal(t, id, data["id"]) diff --git a/middleware/validation.go b/middleware/validation.go index 3879d754..ed026d62 100644 --- a/middleware/validation.go +++ b/middleware/validation.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 middleware diff --git a/middleware/validation_test.go b/middleware/validation_test.go index 37889423..01bda840 100644 --- a/middleware/validation_test.go +++ b/middleware/validation_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 middleware diff --git a/request.go b/request.go index 203dab2f..aab7b8c0 100644 --- a/request.go +++ b/request.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 runtime diff --git a/request_test.go b/request_test.go index aab9465d..1e358314 100644 --- a/request_test.go +++ b/request_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 runtime diff --git a/security/apikey_auth_test.go b/security/apikey_auth_test.go index 3899f737..cf216f13 100644 --- a/security/apikey_auth_test.go +++ b/security/apikey_auth_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 security @@ -31,7 +20,7 @@ const ( ) func TestApiKeyAuth(t *testing.T) { - tokenAuth := TokenAuthentication(func(token string) (interface{}, error) { + tokenAuth := TokenAuthentication(func(token string) (any, error) { if token == validToken { return principal, nil } @@ -117,7 +106,7 @@ func TestApiKeyAuth(t *testing.T) { } func TestApiKeyAuthCtx(t *testing.T) { - tokenAuthCtx := TokenAuthenticationCtx(func(ctx context.Context, token string) (context.Context, interface{}, error) { + tokenAuthCtx := TokenAuthenticationCtx(func(ctx context.Context, token string) (context.Context, any, error) { if token == validToken { return context.WithValue(ctx, extra, extraWisdom), principal, nil } diff --git a/security/authenticator.go b/security/authenticator.go index def3746e..b5b7904d 100644 --- a/security/authenticator.go +++ b/security/authenticator.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 security @@ -31,8 +20,8 @@ const ( ) // HttpAuthenticator is a function that authenticates a HTTP request -func HttpAuthenticator(handler func(*http.Request) (bool, interface{}, error)) runtime.Authenticator { //nolint:revive - return runtime.AuthenticatorFunc(func(params interface{}) (bool, interface{}, error) { +func HttpAuthenticator(handler func(*http.Request) (bool, any, error)) runtime.Authenticator { //nolint:revive + return runtime.AuthenticatorFunc(func(params any) (bool, any, error) { if request, ok := params.(*http.Request); ok { return handler(request) } @@ -44,8 +33,8 @@ func HttpAuthenticator(handler func(*http.Request) (bool, interface{}, error)) r } // ScopedAuthenticator is a function that authenticates a HTTP request against a list of valid scopes -func ScopedAuthenticator(handler func(*ScopedAuthRequest) (bool, interface{}, error)) runtime.Authenticator { - return runtime.AuthenticatorFunc(func(params interface{}) (bool, interface{}, error) { +func ScopedAuthenticator(handler func(*ScopedAuthRequest) (bool, any, error)) runtime.Authenticator { + return runtime.AuthenticatorFunc(func(params any) (bool, any, error) { if request, ok := params.(*ScopedAuthRequest); ok { return handler(request) } @@ -54,22 +43,22 @@ func ScopedAuthenticator(handler func(*ScopedAuthRequest) (bool, interface{}, er } // UserPassAuthentication authentication function -type UserPassAuthentication func(string, string) (interface{}, error) +type UserPassAuthentication func(string, string) (any, error) // UserPassAuthenticationCtx authentication function with context.Context -type UserPassAuthenticationCtx func(context.Context, string, string) (context.Context, interface{}, error) +type UserPassAuthenticationCtx func(context.Context, string, string) (context.Context, any, error) // TokenAuthentication authentication function -type TokenAuthentication func(string) (interface{}, error) +type TokenAuthentication func(string) (any, error) // TokenAuthenticationCtx authentication function with context.Context -type TokenAuthenticationCtx func(context.Context, string) (context.Context, interface{}, error) +type TokenAuthenticationCtx func(context.Context, string) (context.Context, any, error) // ScopedTokenAuthentication authentication function -type ScopedTokenAuthentication func(string, []string) (interface{}, error) +type ScopedTokenAuthentication func(string, []string) (any, error) // ScopedTokenAuthenticationCtx authentication function with context.Context -type ScopedTokenAuthenticationCtx func(context.Context, string, []string) (context.Context, interface{}, error) +type ScopedTokenAuthenticationCtx func(context.Context, string, []string) (context.Context, any, error) var DefaultRealmName = "API" @@ -115,7 +104,7 @@ func BasicAuthRealm(realm string, authenticate UserPassAuthentication) runtime.A realm = DefaultRealmName } - return HttpAuthenticator(func(r *http.Request) (bool, interface{}, error) { + return HttpAuthenticator(func(r *http.Request) (bool, any, error) { if usr, pass, ok := r.BasicAuth(); ok { p, err := authenticate(usr, pass) if err != nil { @@ -139,7 +128,7 @@ func BasicAuthRealmCtx(realm string, authenticate UserPassAuthenticationCtx) run realm = DefaultRealmName } - return HttpAuthenticator(func(r *http.Request) (bool, interface{}, error) { + return HttpAuthenticator(func(r *http.Request) (bool, any, error) { if usr, pass, ok := r.BasicAuth(); ok { ctx, p, err := authenticate(r.Context(), usr, pass) if err != nil { @@ -170,7 +159,7 @@ func APIKeyAuth(name, in string, authenticate TokenAuthentication) runtime.Authe getToken = func(r *http.Request) string { return r.URL.Query().Get(name) } } - return HttpAuthenticator(func(r *http.Request) (bool, interface{}, error) { + return HttpAuthenticator(func(r *http.Request) (bool, any, error) { token := getToken(r) if token == "" { return false, nil, nil @@ -198,7 +187,7 @@ func APIKeyAuthCtx(name, in string, authenticate TokenAuthenticationCtx) runtime getToken = func(r *http.Request) string { return r.URL.Query().Get(name) } } - return HttpAuthenticator(func(r *http.Request) (bool, interface{}, error) { + return HttpAuthenticator(func(r *http.Request) (bool, any, error) { token := getToken(r) if token == "" { return false, nil, nil @@ -219,11 +208,11 @@ type ScopedAuthRequest struct { // BearerAuth for use with oauth2 flows func BearerAuth(name string, authenticate ScopedTokenAuthentication) runtime.Authenticator { const prefix = "Bearer " - return ScopedAuthenticator(func(r *ScopedAuthRequest) (bool, interface{}, error) { + return ScopedAuthenticator(func(r *ScopedAuthRequest) (bool, any, error) { var token string hdr := r.Request.Header.Get(runtime.HeaderAuthorization) - if strings.HasPrefix(hdr, prefix) { - token = strings.TrimPrefix(hdr, prefix) + if after, ok := strings.CutPrefix(hdr, prefix); ok { + token = after } if token == "" { qs := r.Request.URL.Query() @@ -249,11 +238,11 @@ func BearerAuth(name string, authenticate ScopedTokenAuthentication) runtime.Aut // BearerAuthCtx for use with oauth2 flows with support for context.Context. func BearerAuthCtx(name string, authenticate ScopedTokenAuthenticationCtx) runtime.Authenticator { const prefix = "Bearer " - return ScopedAuthenticator(func(r *ScopedAuthRequest) (bool, interface{}, error) { + return ScopedAuthenticator(func(r *ScopedAuthRequest) (bool, any, error) { var token string hdr := r.Request.Header.Get(runtime.HeaderAuthorization) - if strings.HasPrefix(hdr, prefix) { - token = strings.TrimPrefix(hdr, prefix) + if after, ok := strings.CutPrefix(hdr, prefix); ok { + token = after } if token == "" { qs := r.Request.URL.Query() diff --git a/security/authorizer.go b/security/authorizer.go index 00c1a4d6..69bd497a 100644 --- a/security/authorizer.go +++ b/security/authorizer.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 security @@ -23,5 +12,5 @@ import ( // Authorized provides a default implementation of the Authorizer interface where all // requests are authorized (successful) func Authorized() runtime.Authorizer { - return runtime.AuthorizerFunc(func(_ *http.Request, _ interface{}) error { return nil }) + return runtime.AuthorizerFunc(func(_ *http.Request, _ any) error { return nil }) } diff --git a/security/authorizer_test.go b/security/authorizer_test.go index 5463748f..0b68b5c6 100644 --- a/security/authorizer_test.go +++ b/security/authorizer_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 security @@ -35,7 +24,7 @@ func TestAuthenticator(t *testing.T) { require.NoError(t, err) t.Run("with HttpAuthenticator", func(t *testing.T) { - auth := HttpAuthenticator(func(_ *http.Request) (bool, interface{}, error) { return true, "test", nil }) + auth := HttpAuthenticator(func(_ *http.Request) (bool, any, error) { return true, "test", nil }) t.Run("authenticator should work on *http.Request", func(t *testing.T) { isAuth, user, err := auth.Authenticate(r) @@ -62,7 +51,7 @@ func TestAuthenticator(t *testing.T) { }) t.Run("with ScopedAuthenticator", func(t *testing.T) { - auth := ScopedAuthenticator(func(_ *ScopedAuthRequest) (bool, interface{}, error) { return true, "test", nil }) + auth := ScopedAuthenticator(func(_ *ScopedAuthRequest) (bool, any, error) { return true, "test", nil }) t.Run("authenticator should work on *ScopedAuthRequest", func(t *testing.T) { scoped := &ScopedAuthRequest{Request: r} diff --git a/security/basic_auth_test.go b/security/basic_auth_test.go index 65aad8a2..b2ad1b49 100644 --- a/security/basic_auth_test.go +++ b/security/basic_auth_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 security @@ -40,7 +29,7 @@ const ( ) func TestBasicAuth(t *testing.T) { - basicAuthHandler := UserPassAuthentication(func(user, pass string) (interface{}, error) { + basicAuthHandler := UserPassAuthentication(func(user, pass string) (any, error) { if user == principal && pass == testPassword { return principal, nil } @@ -123,7 +112,7 @@ func TestBasicAuth(t *testing.T) { } func TestBasicAuthCtx(t *testing.T) { - basicAuthHandlerCtx := UserPassAuthenticationCtx(func(ctx context.Context, user, pass string) (context.Context, interface{}, error) { + basicAuthHandlerCtx := UserPassAuthenticationCtx(func(ctx context.Context, user, pass string) (context.Context, any, error) { if user == principal && pass == testPassword { return context.WithValue(ctx, extra, extraWisdom), principal, nil } diff --git a/security/bearer_auth_test.go b/security/bearer_auth_test.go index eea0c59f..4fe4c20b 100644 --- a/security/bearer_auth_test.go +++ b/security/bearer_auth_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package security import ( @@ -34,7 +37,7 @@ const ( ) func TestBearerAuth(t *testing.T) { - bearerAuth := ScopedTokenAuthentication(func(token string, _ []string) (interface{}, error) { + bearerAuth := ScopedTokenAuthentication(func(token string, _ []string) (any, error) { if token == validToken { return principal, nil } @@ -90,7 +93,7 @@ func TestBearerAuth(t *testing.T) { } func TestBearerAuthCtx(t *testing.T) { - bearerAuthCtx := ScopedTokenAuthenticationCtx(func(ctx context.Context, token string, _ []string) (context.Context, interface{}, error) { + bearerAuthCtx := ScopedTokenAuthenticationCtx(func(ctx context.Context, token string, _ []string) (context.Context, any, error) { if token == validToken { return context.WithValue(ctx, extra, extraWisdom), principal, nil } diff --git a/statuses.go b/statuses.go index 3b011a0b..7e10a5a5 100644 --- a/statuses.go +++ b/statuses.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 runtime diff --git a/text.go b/text.go index d8dee941..2b8e4ac0 100644 --- a/text.go +++ b/text.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 runtime @@ -27,7 +16,7 @@ import ( // TextConsumer creates a new text consumer func TextConsumer() Consumer { - return ConsumerFunc(func(reader io.Reader, data interface{}) error { + return ConsumerFunc(func(reader io.Reader, data any) error { if reader == nil { return errors.New("TextConsumer requires a reader") // early exit } @@ -69,7 +58,7 @@ func TextConsumer() Consumer { // TextProducer creates a new text producer func TextProducer() Producer { - return ProducerFunc(func(writer io.Writer, data interface{}) error { + return ProducerFunc(func(writer io.Writer, data any) error { if writer == nil { return errors.New("TextProducer requires a writer") // early exit } diff --git a/text_test.go b/text_test.go index 5f2f727a..fef20414 100644 --- a/text_test.go +++ b/text_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 runtime diff --git a/values.go b/values.go index 11f5732a..19894e78 100644 --- a/values.go +++ b/values.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package runtime // Values typically represent parameters on a http request. diff --git a/values_test.go b/values_test.go index 7f341cb8..2a4269cf 100644 --- a/values_test.go +++ b/values_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers +// SPDX-License-Identifier: Apache-2.0 + package runtime import ( diff --git a/xml.go b/xml.go index 821c7393..5060b5c8 100644 --- a/xml.go +++ b/xml.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 runtime @@ -21,7 +10,7 @@ import ( // XMLConsumer creates a new XML consumer func XMLConsumer() Consumer { - return ConsumerFunc(func(reader io.Reader, data interface{}) error { + return ConsumerFunc(func(reader io.Reader, data any) error { dec := xml.NewDecoder(reader) return dec.Decode(data) }) @@ -29,7 +18,7 @@ func XMLConsumer() Consumer { // XMLProducer creates a new XML producer func XMLProducer() Producer { - return ProducerFunc(func(writer io.Writer, data interface{}) error { + return ProducerFunc(func(writer io.Writer, data any) error { enc := xml.NewEncoder(writer) return enc.Encode(data) }) diff --git a/xml_test.go b/xml_test.go index 9da96bbe..44e4c0e2 100644 --- a/xml_test.go +++ b/xml_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 runtime diff --git a/yamlpc/yaml.go b/yamlpc/yaml.go index 467408c4..ca63430e 100644 --- a/yamlpc/yaml.go +++ b/yamlpc/yaml.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 yamlpc diff --git a/yamlpc/yaml_test.go b/yamlpc/yaml_test.go index befbba71..ac795fbd 100644 --- a/yamlpc/yaml_test.go +++ b/yamlpc/yaml_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 yamlpc