From a69bcedaca95f66b5e9353d65e5202b938419db5 Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Mon, 20 Jul 2026 23:46:45 +0200 Subject: [PATCH] fix(flatten): in options, guarded against possible json serialization of funcs Non-serializable exported fields should be guarded by json tag "-". Also: updated linter (discarded goconst, deprecated linters, deprecated nolint directives). Acknowledged one remaining high complexity in flatter. Signed-off-by: Frederic BIDON --- .golangci.yml | 3 +++ flatten.go | 2 +- flatten_options.go | 4 ++-- internal/antest/helpers_test.go | 2 +- internal/debug/debug_test.go | 6 +++--- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b97d680..0d7baa1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,8 +4,11 @@ linters: disable: - depguard - funlen + - goconst - godox - gomoddirectives + - gomodguard + - gomodguard_v2 - exhaustruct - nlreturn - nonamedreturns diff --git a/flatten.go b/flatten.go index 789449a..c90456f 100644 --- a/flatten.go +++ b/flatten.go @@ -575,7 +575,7 @@ func stripOAIGenForRef(opts *FlattenOpts, k string, r *newRef) (bool, error) { } // rewrite other parents to point to first parent - if len(pr) > 1 { + if len(pr) > 1 { //nolint:nestif // should be refactored at a later time for _, p := range pr[1:] { replacingRef := spec.MustCreateRef(pr[0]) diff --git a/flatten_options.go b/flatten_options.go index 84d92db..1e182ad 100644 --- a/flatten_options.go +++ b/flatten_options.go @@ -33,7 +33,7 @@ type FlattenOpts struct { RemoveUnused bool // When true, remove unused parameters, responses and definitions after expansion/flattening ContinueOnError bool // Continue when spec expansion issues are found KeepNames bool // Do not attempt to jsonify names from references when flattening - ManglerOpts []mangling.Option // Options for the name mangler used to jsonify names + ManglerOpts []mangling.Option `json:"-"` // Options for the name mangler used to jsonify names // PathLoaderWithOptions injects the document loader used to resolve remote and relative $ref // while flattening or expanding the specification. It matches the option-aware loader signature @@ -43,7 +43,7 @@ type FlattenOpts struct { // confined loader — for example one built with loading.WithRoot (to confine local reads) and // loading.WithHTTPClient (to restrict remote fetches), or a restricted loader from // go-openapi/loads. Left nil, the spec package default (unsandboxed) loader is used. - PathLoaderWithOptions func(string, ...loading.Option) (json.RawMessage, error) + PathLoaderWithOptions func(string, ...loading.Option) (json.RawMessage, error) `json:"-"` /* Extra keys */ _ struct{} // require keys diff --git a/internal/antest/helpers_test.go b/internal/antest/helpers_test.go index 6440a6d..8e64572 100644 --- a/internal/antest/helpers_test.go +++ b/internal/antest/helpers_test.go @@ -101,7 +101,7 @@ info: } require.NoError(t, - os.WriteFile(file, data, 0o600), //nolint:gosec // false positive on temp test dir: G703: Path traversal via taint analysis. + os.WriteFile(file, data, 0o600), ) return file, func() {} diff --git a/internal/debug/debug_test.go b/internal/debug/debug_test.go index aeed19c..8c58458 100644 --- a/internal/debug/debug_test.go +++ b/internal/debug/debug_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers // SPDX-License-Identifier: Apache-2.0 -package debug //nolint:revive // this package is called debug and there is no confusion with the standard library for that. +package debug import ( "os" @@ -32,7 +32,7 @@ func TestDebug(t *testing.T) { tmpFile.Close() tmpFileClosed = true - flushed, err := os.ReadFile(tmpName) //nolint:gosec // false positive on temp test dir: G703: Path traversal via taint analysis. + flushed, err := os.ReadFile(tmpName) require.NoError(t, err) assert.StringContainsT(t, string(flushed), "A debug: a string") @@ -53,7 +53,7 @@ func TestDebug(t *testing.T) { tmpEmptyFile.Close() tmpEmptyFileClosed = true - flushed, err = os.ReadFile(tmpEmpty) //nolint:gosec // false positive on temp test dir: G703: Path traversal via taint analysis. + flushed, err = os.ReadFile(tmpEmpty) require.NoError(t, err) assert.Empty(t, flushed)