diff --git a/cmd/wasm/functions.go b/cmd/wasm/functions.go index 81cf9de..594084b 100644 --- a/cmd/wasm/functions.go +++ b/cmd/wasm/functions.go @@ -5,13 +5,14 @@ package main import ( "encoding/json" "fmt" + "reflect" + "syscall/js" + "github.com/speakeasy-api/jsonpath/pkg/jsonpath" "github.com/speakeasy-api/jsonpath/pkg/jsonpath/config" "github.com/speakeasy-api/jsonpath/pkg/jsonpath/token" "github.com/speakeasy-api/jsonpath/pkg/overlay" - "gopkg.in/yaml.v3" - "reflect" - "syscall/js" + "go.yaml.in/yaml/v4" ) func CalculateOverlay(originalYAML, targetYAML, existingOverlay string) (string, error) { diff --git a/go.mod b/go.mod index 8ffd79e..7d79d0f 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,12 @@ go 1.22 require ( github.com/pmezard/go-difflib v1.0.0 github.com/stretchr/testify v1.9.0 - gopkg.in/yaml.v3 v3.0.1 + go.yaml.in/yaml/v4 v4.0.0-rc.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/pretty v0.1.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d85da3a..d98546a 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.yaml.in/yaml/v4 v4.0.0-rc.1 h1:4J1+yLKUIPGexM/Si+9d3pij4hdc7aGO04NhrElqXbY= +go.yaml.in/yaml/v4 v4.0.0-rc.1/go.mod h1:CBdeces52/nUXndfQ5OY8GEQuNR9uEEOJPZj/Xq5IzU= 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 79db502..d43ebc8 100644 --- a/integration_test.go +++ b/integration_test.go @@ -2,14 +2,15 @@ package jsonpath_test import ( "encoding/json" - "github.com/pmezard/go-difflib/difflib" - "github.com/speakeasy-api/jsonpath/pkg/jsonpath" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" "os" "slices" "strings" "testing" + + "github.com/pmezard/go-difflib/difflib" + "github.com/speakeasy-api/jsonpath/pkg/jsonpath" + "github.com/stretchr/testify/require" + "go.yaml.in/yaml/v4" ) type FullTestSuite struct { @@ -93,7 +94,7 @@ func TestJSONPathComplianceTestSuite(t *testing.T) { // Test case with multiple possible results var found bool - for i, _ := range test.Results { + for i := range test.Results { if match, msg := compareResults(result, expectedResults[i]); match { found = true break diff --git a/pkg/jsonpath/filter.go b/pkg/jsonpath/filter.go index 0f5b77f..f7f6ae0 100644 --- a/pkg/jsonpath/filter.go +++ b/pkg/jsonpath/filter.go @@ -1,9 +1,10 @@ package jsonpath import ( - "gopkg.in/yaml.v3" "strconv" "strings" + + "go.yaml.in/yaml/v4" ) // filter-selector = "?" S logical-expr diff --git a/pkg/jsonpath/jsonpath.go b/pkg/jsonpath/jsonpath.go index d5c8a5b..62a1d06 100644 --- a/pkg/jsonpath/jsonpath.go +++ b/pkg/jsonpath/jsonpath.go @@ -2,9 +2,10 @@ package jsonpath import ( "fmt" + "github.com/speakeasy-api/jsonpath/pkg/jsonpath/config" "github.com/speakeasy-api/jsonpath/pkg/jsonpath/token" - "gopkg.in/yaml.v3" + "go.yaml.in/yaml/v4" ) func NewPath(input string, opts ...config.Option) (*JSONPath, error) { diff --git a/pkg/jsonpath/segment.go b/pkg/jsonpath/segment.go index cb6233f..d911a15 100644 --- a/pkg/jsonpath/segment.go +++ b/pkg/jsonpath/segment.go @@ -1,8 +1,9 @@ package jsonpath import ( - "gopkg.in/yaml.v3" "strings" + + "go.yaml.in/yaml/v4" ) type segmentKind int diff --git a/pkg/jsonpath/yaml_eval.go b/pkg/jsonpath/yaml_eval.go index 7291ea9..2ef9d77 100644 --- a/pkg/jsonpath/yaml_eval.go +++ b/pkg/jsonpath/yaml_eval.go @@ -2,11 +2,12 @@ package jsonpath import ( "fmt" - "gopkg.in/yaml.v3" "reflect" "regexp" "strconv" "unicode/utf8" + + "go.yaml.in/yaml/v4" ) func (l literal) Equals(value literal) bool { @@ -266,7 +267,6 @@ func (q relQuery) Evaluate(idx index, node *yaml.Node, root *yaml.Node) literal return nodeToLiteral(result[0]) } return literal{} - } func (q absQuery) Evaluate(idx index, node *yaml.Node, root *yaml.Node) literal { diff --git a/pkg/jsonpath/yaml_eval_test.go b/pkg/jsonpath/yaml_eval_test.go index a74e97b..8038094 100644 --- a/pkg/jsonpath/yaml_eval_test.go +++ b/pkg/jsonpath/yaml_eval_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "gopkg.in/yaml.v3" + "go.yaml.in/yaml/v4" ) func TestLiteralEquals(t *testing.T) { diff --git a/pkg/jsonpath/yaml_query.go b/pkg/jsonpath/yaml_query.go index 44b55a3..9a01e26 100644 --- a/pkg/jsonpath/yaml_query.go +++ b/pkg/jsonpath/yaml_query.go @@ -1,7 +1,7 @@ package jsonpath import ( - "gopkg.in/yaml.v3" + "go.yaml.in/yaml/v4" ) type Evaluator interface { @@ -60,7 +60,7 @@ func (s segment) Query(idx index, value *yaml.Node, root *yaml.Node) []*yaml.Nod return s.child.Query(idx, value, root) case segmentKindDescendant: // run the inner segment against this node - var result = []*yaml.Node{} + result := []*yaml.Node{} children := descend(value, root) for _, child := range children { result = append(result, s.descendant.Query(idx, child, root)...) @@ -142,7 +142,6 @@ func (s innerSegment) Query(idx index, value *yaml.Node, root *yaml.Node) []*yam } return result - } func (s selector) Query(idx index, value *yaml.Node, root *yaml.Node) []*yaml.Node { diff --git a/pkg/jsonpath/yaml_query_test.go b/pkg/jsonpath/yaml_query_test.go index 1927f58..f2fd9aa 100644 --- a/pkg/jsonpath/yaml_query_test.go +++ b/pkg/jsonpath/yaml_query_test.go @@ -1,12 +1,13 @@ package jsonpath import ( - "github.com/speakeasy-api/jsonpath/pkg/jsonpath/config" - "github.com/speakeasy-api/jsonpath/pkg/jsonpath/token" - "gopkg.in/yaml.v3" "reflect" "strings" "testing" + + "github.com/speakeasy-api/jsonpath/pkg/jsonpath/config" + "github.com/speakeasy-api/jsonpath/pkg/jsonpath/token" + "go.yaml.in/yaml/v4" ) func TestQuery(t *testing.T) { diff --git a/pkg/overlay/apply.go b/pkg/overlay/apply.go index 005ee95..c0bcb41 100644 --- a/pkg/overlay/apply.go +++ b/pkg/overlay/apply.go @@ -3,7 +3,7 @@ package overlay import ( "github.com/speakeasy-api/jsonpath/pkg/jsonpath" "github.com/speakeasy-api/jsonpath/pkg/jsonpath/config" - "gopkg.in/yaml.v3" + "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 7f6fcf8..0b84ef6 100644 --- a/pkg/overlay/apply_test.go +++ b/pkg/overlay/apply_test.go @@ -2,11 +2,12 @@ package overlay_test import ( "bytes" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" "os" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.yaml.in/yaml/v4" ) // NodeMatchesFile is a test that marshals the YAML file from the given node, @@ -29,10 +30,10 @@ func NodeMatchesFile( require.NoError(t, err, variadoc("failed to read expected file: ")...) // lazy redo snapshot - //os.WriteFile(expectedFile, actualBuf.Bytes(), 0644) + // os.WriteFile(expectedFile, actualBuf.Bytes(), 0644) - //t.Log("### EXPECT START ###\n" + string(expectedBytes) + "\n### EXPECT END ###\n") - //t.Log("### ACTUAL START ###\n" + actualBuf.string() + "\n### ACTUAL END ###\n") + // t.Log("### EXPECT START ###\n" + string(expectedBytes) + "\n### EXPECT END ###\n") + // t.Log("### ACTUAL START ###\n" + actualBuf.string() + "\n### ACTUAL END ###\n") assert.Equal(t, string(expectedBytes), actualBuf.String(), variadoc("node does not match expected file: ")...) } diff --git a/pkg/overlay/compare.go b/pkg/overlay/compare.go index 1aa8d2f..fb567f5 100644 --- a/pkg/overlay/compare.go +++ b/pkg/overlay/compare.go @@ -6,7 +6,7 @@ import ( "log" "strings" - "gopkg.in/yaml.v3" + "go.yaml.in/yaml/v4" ) // 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 fbf6a39..957386c 100644 --- a/pkg/overlay/compare_test.go +++ b/pkg/overlay/compare_test.go @@ -2,12 +2,13 @@ package overlay_test import ( "fmt" + "os" + "testing" + "github.com/speakeasy-api/jsonpath/pkg/overlay" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v3" - "os" - "testing" + "go.yaml.in/yaml/v4" ) func LoadSpecification(path string) (*yaml.Node, error) { @@ -54,12 +55,11 @@ func TestCompare(t *testing.T) { assert.NoError(t, err) // Uncomment this if we've improved the output - //os.WriteFile("testdata/overlay-generated.yaml", []byte(o2s), 0644) + // os.WriteFile("testdata/overlay-generated.yaml", []byte(o2s), 0644) assert.Equal(t, o1s, o2s) // round trip it err = o.ApplyTo(node) assert.NoError(t, err) NodeMatchesFile(t, node, "testdata/openapi-overlayed.yaml") - } diff --git a/pkg/overlay/parents.go b/pkg/overlay/parents.go index a2b4942..5954689 100644 --- a/pkg/overlay/parents.go +++ b/pkg/overlay/parents.go @@ -1,6 +1,6 @@ package overlay -import "gopkg.in/yaml.v3" +import "go.yaml.in/yaml/v4" type parentIndex map[*yaml.Node]*yaml.Node diff --git a/pkg/overlay/parse.go b/pkg/overlay/parse.go index 0708846..320ea6e 100644 --- a/pkg/overlay/parse.go +++ b/pkg/overlay/parse.go @@ -2,10 +2,11 @@ package overlay import ( "fmt" - "gopkg.in/yaml.v3" "io" "os" "path/filepath" + + "go.yaml.in/yaml/v4" ) // Parse will parse the given reader as an overlay file. @@ -47,7 +48,7 @@ func Format(path string) error { return err } - return os.WriteFile(filePath, []byte(formatted), 0644) + return os.WriteFile(filePath, []byte(formatted), 0o644) } // Format writes the file back out as YAML. diff --git a/pkg/overlay/schema.go b/pkg/overlay/schema.go index ae1ea3e..1d7a785 100644 --- a/pkg/overlay/schema.go +++ b/pkg/overlay/schema.go @@ -2,7 +2,8 @@ package overlay import ( "bytes" - "gopkg.in/yaml.v3" + + "go.yaml.in/yaml/v4" ) // Extensible provides a place for extensions to be added to components of the