From 26d48cf3f299b5e4d439049a39e650fcc52c78ec Mon Sep 17 00:00:00 2001 From: quobix Date: Fri, 25 Sep 2026 19:19:16 -0400 Subject: [PATCH] chore: use github.com/pb33f/go-yaml for YAML support Replace go.yaml.in/yaml/v4 (rc.4) with github.com/pb33f/go-yaml v0.1.0, pb33f's maintained fork of the YAML library, so jsonpath queries and overlays work on the same yaml.Node type as libopenapi and the other pb33f modules. The fork carries upstream's later encoder defaults, which wrap long lines at 80 columns. Overlay.Format and ToString now write with a Dumper pinned to the layout overlays have always had (V3 defaults, two space indent, no wrapping), so their output is unchanged. The overlay test helper uses the same settings. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 ++-- cmd/wasm/functions.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- integration_test.go | 2 +- pkg/jsonpath/context_usage_test.go | 2 +- pkg/jsonpath/filter.go | 2 +- pkg/jsonpath/filter_context.go | 2 +- pkg/jsonpath/filter_context_test.go | 2 +- pkg/jsonpath/jsonpath.go | 2 +- pkg/jsonpath/jsonpath_plus_test.go | 2 +- .../lazy_context_tracking_stress_test.go | 2 +- pkg/jsonpath/lazy_context_tracking_test.go | 2 +- pkg/jsonpath/segment.go | 2 +- pkg/jsonpath/spectral_bench_test.go | 2 +- pkg/jsonpath/spectral_corpus_test.go | 2 +- pkg/jsonpath/spectral_eval.go | 2 +- pkg/jsonpath/spectral_eval_test.go | 2 +- pkg/jsonpath/spectral_test.go | 2 +- .../testdata/spectral/generate/collect_public.go | 2 +- .../spectral/generate/collect_public_test.go | 2 +- pkg/jsonpath/yaml_eval.go | 2 +- pkg/jsonpath/yaml_eval_test.go | 2 +- pkg/jsonpath/yaml_query.go | 2 +- pkg/jsonpath/yaml_query_test.go | 2 +- pkg/overlay/apply.go | 2 +- pkg/overlay/apply_test.go | 9 +++++---- pkg/overlay/compare.go | 2 +- pkg/overlay/compare_test.go | 2 +- pkg/overlay/parents.go | 2 +- pkg/overlay/parse.go | 16 +++++++++++----- pkg/overlay/schema.go | 6 ++---- 32 files changed, 49 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 63e1f2c..1d56010 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ package main import ( "fmt" "github.com/pb33f/jsonpath/pkg/jsonpath" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) func main() { @@ -415,7 +415,7 @@ package main import ( "fmt" "github.com/pb33f/jsonpath/pkg/overlay" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) func main() { diff --git a/cmd/wasm/functions.go b/cmd/wasm/functions.go index 6d8dfcb..27dca62 100644 --- a/cmd/wasm/functions.go +++ b/cmd/wasm/functions.go @@ -9,7 +9,7 @@ import ( "github.com/pb33f/jsonpath/pkg/jsonpath/config" "github.com/pb33f/jsonpath/pkg/jsonpath/token" "github.com/pb33f/jsonpath/pkg/overlay" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" "reflect" "syscall/js" ) diff --git a/go.mod b/go.mod index 7d05a1c..e01abdf 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/pb33f/jsonpath go 1.24 require ( + github.com/pb33f/go-yaml v0.1.0 github.com/pmezard/go-difflib v1.0.0 github.com/stretchr/testify v1.11.1 - go.yaml.in/yaml/v4 v4.0.0-rc.4 ) require ( diff --git a/go.sum b/go.sum index 6cf1eda..fd9bf2a 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pb33f/go-yaml v0.1.0 h1:zZ6Gg+ATbumXlXZNLMHIe7+zTkVqe20lx+TSYRrXEuY= +github.com/pb33f/go-yaml v0.1.0/go.mod h1:QvWdkHP5VjFYAeHMQUkaPQqREaQnBNOXmWzAjNrnSdo= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -12,8 +14,6 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U= -go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/integration_test.go b/integration_test.go index bcb9799..299e0fd 100644 --- a/integration_test.go +++ b/integration_test.go @@ -10,7 +10,7 @@ import ( "github.com/pmezard/go-difflib/difflib" "github.com/pb33f/jsonpath/pkg/jsonpath" "github.com/stretchr/testify/require" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) type FullTestSuite struct { diff --git a/pkg/jsonpath/context_usage_test.go b/pkg/jsonpath/context_usage_test.go index 6953937..4c2b96b 100644 --- a/pkg/jsonpath/context_usage_test.go +++ b/pkg/jsonpath/context_usage_test.go @@ -3,7 +3,7 @@ package jsonpath import ( "testing" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) func TestContextUsageAndPropertyReferenceDetection(t *testing.T) { diff --git a/pkg/jsonpath/filter.go b/pkg/jsonpath/filter.go index a481039..9208dd8 100644 --- a/pkg/jsonpath/filter.go +++ b/pkg/jsonpath/filter.go @@ -1,7 +1,7 @@ package jsonpath import ( - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" "strconv" "strings" ) diff --git a/pkg/jsonpath/filter_context.go b/pkg/jsonpath/filter_context.go index 2349ce5..634b4e7 100644 --- a/pkg/jsonpath/filter_context.go +++ b/pkg/jsonpath/filter_context.go @@ -4,7 +4,7 @@ import ( "strconv" "strings" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) // FilterContext provides rich context during filter evaluation for JSONPath Plus extensions. diff --git a/pkg/jsonpath/filter_context_test.go b/pkg/jsonpath/filter_context_test.go index 978c837..8b46b89 100644 --- a/pkg/jsonpath/filter_context_test.go +++ b/pkg/jsonpath/filter_context_test.go @@ -3,7 +3,7 @@ package jsonpath import ( "testing" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) func TestFilterContextLazyGuardsAndTrackingFlags(t *testing.T) { diff --git a/pkg/jsonpath/jsonpath.go b/pkg/jsonpath/jsonpath.go index aaacda6..e60a8f9 100644 --- a/pkg/jsonpath/jsonpath.go +++ b/pkg/jsonpath/jsonpath.go @@ -2,9 +2,9 @@ package jsonpath import ( "fmt" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath/config" "github.com/pb33f/jsonpath/pkg/jsonpath/token" - "go.yaml.in/yaml/v4" ) // NewPath compiles input into a reusable JSONPath using the supplied options. diff --git a/pkg/jsonpath/jsonpath_plus_test.go b/pkg/jsonpath/jsonpath_plus_test.go index b2581a3..b94014b 100644 --- a/pkg/jsonpath/jsonpath_plus_test.go +++ b/pkg/jsonpath/jsonpath_plus_test.go @@ -5,7 +5,7 @@ import ( "github.com/pb33f/jsonpath/pkg/jsonpath/config" "github.com/stretchr/testify/assert" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) // TestPropertyContextVariable tests @property filter context variable diff --git a/pkg/jsonpath/lazy_context_tracking_stress_test.go b/pkg/jsonpath/lazy_context_tracking_stress_test.go index 41f7a07..e5a5950 100644 --- a/pkg/jsonpath/lazy_context_tracking_stress_test.go +++ b/pkg/jsonpath/lazy_context_tracking_stress_test.go @@ -7,9 +7,9 @@ import ( "os" "testing" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath/config" "github.com/pb33f/jsonpath/pkg/jsonpath/token" - "go.yaml.in/yaml/v4" ) func BenchmarkLazyContextTrackingStress(b *testing.B) { diff --git a/pkg/jsonpath/lazy_context_tracking_test.go b/pkg/jsonpath/lazy_context_tracking_test.go index d36dfcc..1d05a8b 100644 --- a/pkg/jsonpath/lazy_context_tracking_test.go +++ b/pkg/jsonpath/lazy_context_tracking_test.go @@ -3,9 +3,9 @@ package jsonpath import ( + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath/config" "github.com/pb33f/jsonpath/pkg/jsonpath/token" - "go.yaml.in/yaml/v4" "testing" ) diff --git a/pkg/jsonpath/segment.go b/pkg/jsonpath/segment.go index e4e9ec3..dc333f6 100644 --- a/pkg/jsonpath/segment.go +++ b/pkg/jsonpath/segment.go @@ -2,7 +2,7 @@ package jsonpath import ( "fmt" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" "strings" ) diff --git a/pkg/jsonpath/spectral_bench_test.go b/pkg/jsonpath/spectral_bench_test.go index a97f1fd..5eebe3d 100644 --- a/pkg/jsonpath/spectral_bench_test.go +++ b/pkg/jsonpath/spectral_bench_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath/config" - "go.yaml.in/yaml/v4" ) func BenchmarkSpectralRegexFilter(b *testing.B) { diff --git a/pkg/jsonpath/spectral_corpus_test.go b/pkg/jsonpath/spectral_corpus_test.go index 77df4f1..9e1c48d 100644 --- a/pkg/jsonpath/spectral_corpus_test.go +++ b/pkg/jsonpath/spectral_corpus_test.go @@ -8,8 +8,8 @@ import ( "strings" "testing" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath/config" - "go.yaml.in/yaml/v4" ) type spectralCorpus struct { diff --git a/pkg/jsonpath/spectral_eval.go b/pkg/jsonpath/spectral_eval.go index 0abaadd..637e410 100644 --- a/pkg/jsonpath/spectral_eval.go +++ b/pkg/jsonpath/spectral_eval.go @@ -5,8 +5,8 @@ import ( "strconv" "unicode/utf16" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath/token" - "go.yaml.in/yaml/v4" ) type spectralRuntimeKind uint8 diff --git a/pkg/jsonpath/spectral_eval_test.go b/pkg/jsonpath/spectral_eval_test.go index 500962c..71ff636 100644 --- a/pkg/jsonpath/spectral_eval_test.go +++ b/pkg/jsonpath/spectral_eval_test.go @@ -3,7 +3,7 @@ package jsonpath import ( "testing" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) func TestSpectralTruthinessAllValueKinds(t *testing.T) { diff --git a/pkg/jsonpath/spectral_test.go b/pkg/jsonpath/spectral_test.go index 8fa8af7..919dbc3 100644 --- a/pkg/jsonpath/spectral_test.go +++ b/pkg/jsonpath/spectral_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath/config" - "go.yaml.in/yaml/v4" ) func parseSpectralTestYAML(t *testing.T, source string) *yaml.Node { diff --git a/pkg/jsonpath/testdata/spectral/generate/collect_public.go b/pkg/jsonpath/testdata/spectral/generate/collect_public.go index 1205510..cb150d0 100644 --- a/pkg/jsonpath/testdata/spectral/generate/collect_public.go +++ b/pkg/jsonpath/testdata/spectral/generate/collect_public.go @@ -12,9 +12,9 @@ import ( "strings" "time" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath" "github.com/pb33f/jsonpath/pkg/jsonpath/config" - "go.yaml.in/yaml/v4" ) type publicSource struct { diff --git a/pkg/jsonpath/testdata/spectral/generate/collect_public_test.go b/pkg/jsonpath/testdata/spectral/generate/collect_public_test.go index af36499..b52ea16 100644 --- a/pkg/jsonpath/testdata/spectral/generate/collect_public_test.go +++ b/pkg/jsonpath/testdata/spectral/generate/collect_public_test.go @@ -5,7 +5,7 @@ import ( "sort" "testing" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) func TestCollectPublicSelectorsExpandsAliasesAndLists(t *testing.T) { diff --git a/pkg/jsonpath/yaml_eval.go b/pkg/jsonpath/yaml_eval.go index 7143ad9..ab749a2 100644 --- a/pkg/jsonpath/yaml_eval.go +++ b/pkg/jsonpath/yaml_eval.go @@ -7,7 +7,7 @@ import ( "strconv" "unicode/utf8" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) // Pre-allocated boolean literals to avoid repeated allocations diff --git a/pkg/jsonpath/yaml_eval_test.go b/pkg/jsonpath/yaml_eval_test.go index d881c8e..80eebaf 100644 --- a/pkg/jsonpath/yaml_eval_test.go +++ b/pkg/jsonpath/yaml_eval_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) func TestLiteralEquals(t *testing.T) { diff --git a/pkg/jsonpath/yaml_query.go b/pkg/jsonpath/yaml_query.go index 5c80963..4b6971d 100644 --- a/pkg/jsonpath/yaml_query.go +++ b/pkg/jsonpath/yaml_query.go @@ -3,7 +3,7 @@ package jsonpath import ( "strconv" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) type Evaluator interface { diff --git a/pkg/jsonpath/yaml_query_test.go b/pkg/jsonpath/yaml_query_test.go index f0ff1ae..6998c31 100644 --- a/pkg/jsonpath/yaml_query_test.go +++ b/pkg/jsonpath/yaml_query_test.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/pb33f/jsonpath/pkg/jsonpath/config" "github.com/pb33f/jsonpath/pkg/jsonpath/token" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" "reflect" "strings" "testing" diff --git a/pkg/overlay/apply.go b/pkg/overlay/apply.go index 476f7bb..a1a14df 100644 --- a/pkg/overlay/apply.go +++ b/pkg/overlay/apply.go @@ -1,9 +1,9 @@ package overlay import ( + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/jsonpath" "github.com/pb33f/jsonpath/pkg/jsonpath/config" - "go.yaml.in/yaml/v4" ) // ApplyTo will take an overlay and apply its changes to the given YAML diff --git a/pkg/overlay/apply_test.go b/pkg/overlay/apply_test.go index ba62849..94a8a48 100644 --- a/pkg/overlay/apply_test.go +++ b/pkg/overlay/apply_test.go @@ -5,10 +5,10 @@ import ( "errors" "testing" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/overlay" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.yaml.in/yaml/v4" "os" "strings" ) @@ -24,10 +24,11 @@ func NodeMatchesFile( variadoc := func(pre ...any) []any { return append(msgAndArgs, pre...) } var actualBuf bytes.Buffer - enc := yaml.NewEncoder(&actualBuf) - enc.SetIndent(2) - err := enc.Encode(actual) + enc, err := yaml.NewDumper(&actualBuf, yaml.WithV3Defaults(), yaml.WithIndent(2), yaml.WithLineWidth(-1)) + require.NoError(t, err, variadoc("failed to create dumper: ")...) + err = enc.Dump(actual) require.NoError(t, err, variadoc("failed to marshal node: ")...) + require.NoError(t, enc.Close(), variadoc("failed to flush node: ")...) expectedBytes, err := os.ReadFile(expectedFile) require.NoError(t, err, variadoc("failed to read expected file: ")...) diff --git a/pkg/overlay/compare.go b/pkg/overlay/compare.go index 4f9cd6d..f344515 100644 --- a/pkg/overlay/compare.go +++ b/pkg/overlay/compare.go @@ -6,7 +6,7 @@ import ( "log" "strings" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) // Compare compares input specifications from two files and returns an overlay diff --git a/pkg/overlay/compare_test.go b/pkg/overlay/compare_test.go index 584a233..7836693 100644 --- a/pkg/overlay/compare_test.go +++ b/pkg/overlay/compare_test.go @@ -2,10 +2,10 @@ package overlay_test import ( "fmt" + "github.com/pb33f/go-yaml" "github.com/pb33f/jsonpath/pkg/overlay" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.yaml.in/yaml/v4" "os" "strings" "testing" diff --git a/pkg/overlay/parents.go b/pkg/overlay/parents.go index 1815d2f..073e6b5 100644 --- a/pkg/overlay/parents.go +++ b/pkg/overlay/parents.go @@ -1,6 +1,6 @@ package overlay -import "go.yaml.in/yaml/v4" +import "github.com/pb33f/go-yaml" type parentIndex map[*yaml.Node]*yaml.Node diff --git a/pkg/overlay/parse.go b/pkg/overlay/parse.go index 2c225d5..6e59517 100644 --- a/pkg/overlay/parse.go +++ b/pkg/overlay/parse.go @@ -2,7 +2,7 @@ package overlay import ( "fmt" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" "io" "os" "path/filepath" @@ -50,9 +50,15 @@ func Format(path string) error { return os.WriteFile(filePath, []byte(formatted), 0644) } -// Format writes the file back out as YAML. +// Format writes the file back out as YAML, with two space indentation and no line wrapping: the +// layout overlays have always been written in. func (o *Overlay) Format(w io.Writer) error { - enc := yaml.NewEncoder(w) - enc.SetIndent(2) - return enc.Encode(o) + enc, err := yaml.NewDumper(w, yaml.WithV3Defaults(), yaml.WithIndent(2), yaml.WithLineWidth(-1)) + if err != nil { + return err + } + if err := enc.Dump(o); err != nil { + return err + } + return enc.Close() } diff --git a/pkg/overlay/schema.go b/pkg/overlay/schema.go index 8f1c476..6e0ed7d 100644 --- a/pkg/overlay/schema.go +++ b/pkg/overlay/schema.go @@ -2,7 +2,7 @@ package overlay import ( "bytes" - "go.yaml.in/yaml/v4" + "github.com/pb33f/go-yaml" ) // Extensible provides a place for extensions to be added to components of the @@ -31,9 +31,7 @@ type Overlay struct { func (o *Overlay) ToString() (string, error) { buf := bytes.NewBuffer([]byte{}) - decoder := yaml.NewEncoder(buf) - decoder.SetIndent(2) - err := decoder.Encode(o) + err := o.Format(buf) return buf.String(), err }