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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/wasm/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 6 additions & 5 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/jsonpath/filter.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package jsonpath

import (
"gopkg.in/yaml.v3"
"strconv"
"strings"

"go.yaml.in/yaml/v4"
)

// filter-selector = "?" S logical-expr
Expand Down
3 changes: 2 additions & 1 deletion pkg/jsonpath/jsonpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/jsonpath/segment.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package jsonpath

import (
"gopkg.in/yaml.v3"
"strings"

"go.yaml.in/yaml/v4"
)

type segmentKind int
Expand Down
4 changes: 2 additions & 2 deletions pkg/jsonpath/yaml_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/jsonpath/yaml_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"gopkg.in/yaml.v3"
"go.yaml.in/yaml/v4"
)

func TestLiteralEquals(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/jsonpath/yaml_query.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jsonpath

import (
"gopkg.in/yaml.v3"
"go.yaml.in/yaml/v4"
)

type Evaluator interface {
Expand Down Expand Up @@ -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)...)
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions pkg/jsonpath/yaml_query_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/overlay/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions pkg/overlay/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: ")...)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/overlay/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/overlay/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")

}
2 changes: 1 addition & 1 deletion pkg/overlay/parents.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package overlay

import "gopkg.in/yaml.v3"
import "go.yaml.in/yaml/v4"

type parentIndex map[*yaml.Node]*yaml.Node

Expand Down
5 changes: 3 additions & 2 deletions pkg/overlay/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pkg/overlay/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading