Skip to content

Spelling #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ This application is included in the [speakeasy](https://github.com/speakeasy-api

## Contributing

We welcome contributions to this repository! Please open a Github issue or a Pull Request if you have an implementation for a bug fix or feature. This repository is compliant with the [jsonpath standard compliance test suite](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite/tree/9277705cda4489c3d0d984831e7656e48145399b)
We welcome contributions to this repository! Please open a GitHub issue or a Pull Request if you have an implementation for a bug fix or feature. This repository is compliant with the [jsonpath standard compliance test suite](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite/tree/9277705cda4489c3d0d984831e7656e48145399b)
5 changes: 3 additions & 2 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"
Comment on lines +8 to -14
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode / go format didn't approve of the format for many of these files. I can drop this commit if that's a problem...

)

func CalculateOverlay(originalYAML, targetYAML, existingOverlay string) (string, error) {
Expand Down
9 changes: 5 additions & 4 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"
"gopkg.in/yaml.v3"
)

type FullTestSuite struct {
Expand Down
29 changes: 15 additions & 14 deletions 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"

"gopkg.in/yaml.v3"
)

// filter-selector = "?" S logical-expr
Expand Down Expand Up @@ -78,13 +79,13 @@ func (q filterQuery) ToString() string {
return ""
}

// functionArgument function-argument = literal /
// functionArgument function-argument = literal-value /
//
// filter-query / ; (includes singular-query)
// logical-expr /
// function-expr
type functionArgument struct {
literal *literal
literalValue *literal
filterQuery *filterQuery
logicalExpr *logicalOrExpr
functionExpr *functionExpr
Expand All @@ -104,8 +105,8 @@ type resolvedArgument struct {
}

func (a functionArgument) Eval(idx index, node *yaml.Node, root *yaml.Node) resolvedArgument {
if a.literal != nil {
return resolvedArgument{kind: functionArgTypeLiteral, literal: a.literal}
if a.literalValue != nil {
return resolvedArgument{kind: functionArgTypeLiteral, literal: a.literalValue}
} else if a.filterQuery != nil {
result := a.filterQuery.Query(idx, node, root)
lits := make([]*literal, len(result))
Expand All @@ -130,8 +131,8 @@ func (a functionArgument) Eval(idx index, node *yaml.Node, root *yaml.Node) reso

func (a functionArgument) ToString() string {
builder := strings.Builder{}
if a.literal != nil {
builder.WriteString(a.literal.ToString())
if a.literalValue != nil {
builder.WriteString(a.literalValue.ToString())
} else if a.filterQuery != nil {
builder.WriteString(a.filterQuery.ToString())
} else if a.logicalExpr != nil {
Expand Down Expand Up @@ -241,7 +242,7 @@ func (e basicExpr) ToString() string {
return ""
}

// literal literal = number /
// literal literal-value = number /
Comment on lines -244 to +245
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to disambiguate the two things, the first, appears to be a golang struct name, and the second appears to be the name for the type to be used in other RHS locations.

// . string-literal /
// . true / false / null
type literal struct {
Expand Down Expand Up @@ -352,18 +353,18 @@ func (q singularQuery) ToString() string {

// comparable
//
// comparable = literal /
// comparable = literal-value /
// singular-query / ; singular query value
// function-expr ; ValueType
type comparable struct {
literal *literal
literalValue *literal
singularQuery *singularQuery
functionExpr *functionExpr
}

func (c comparable) ToString() string {
if c.literal != nil {
return c.literal.ToString()
if c.literalValue != nil {
return c.literalValue.ToString()
} else if c.singularQuery != nil {
return c.singularQuery.ToString()
} else if c.functionExpr != nil {
Expand All @@ -375,9 +376,9 @@ func (c comparable) ToString() string {
// comparisonExpr represents a comparison expression
//
// comparison-expr = comparable S comparison-op S comparable
// literal = number / string-literal /
// literal-value = number / string-literal /
// true / false / null
// comparable = literal /
// comparable = literal-value /
// singular-query / ; singular query value
// function-expr ; ValueType
// comparison-op = "==" / "!=" /
Expand Down
1 change: 1 addition & 0 deletions pkg/jsonpath/jsonpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jsonpath

import (
"fmt"

"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
"github.com/speakeasy-api/jsonpath/pkg/jsonpath/token"
"gopkg.in/yaml.v3"
Expand Down
13 changes: 7 additions & 6 deletions pkg/jsonpath/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package jsonpath
import (
"errors"
"fmt"
"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
"github.com/speakeasy-api/jsonpath/pkg/jsonpath/token"
"strconv"
"strings"

"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
"github.com/speakeasy-api/jsonpath/pkg/jsonpath/token"
)

const MaxSafeFloat int64 = 9007199254740991
Expand Down Expand Up @@ -107,7 +108,7 @@ func (p *JSONPath) parseSegment() (*segment, error) {
return &segment{kind: segmentKindChild, child: child}, nil
} else if p.config.PropertyNameEnabled() && currentToken.Token == token.PROPERTY_NAME {
p.current++
return &segment{kind: segmentKindProperyName}, nil
return &segment{kind: segmentKindPropertyName}, nil
}
return nil, p.parseFailure(&currentToken, "unexpected token when parsing segment")
}
Expand Down Expand Up @@ -460,7 +461,7 @@ func (p *JSONPath) parseComparable() (*comparable, error) {
// singular-query / ; singular query value
// function-expr ; ValueType
if literal, err := p.parseLiteral(); err == nil {
return &comparable{literal: literal}, nil
return &comparable{literalValue: literal}, nil
}
if funcExpr, err := p.parseFunctionExpr(); err == nil {
if funcExpr.funcType == functionTypeMatch {
Expand Down Expand Up @@ -573,7 +574,7 @@ func (p *JSONPath) parseFunctionExpr() (*functionExpr, error) {
if err != nil {
return nil, err
}
if arg.literal != nil && arg.literal.node == nil {
if arg.literalValue != nil && arg.literalValue.node == nil {
return nil, p.parseFailure(&p.tokens[p.current], "count function only supports containers")
}
args = append(args, arg)
Expand Down Expand Up @@ -636,7 +637,7 @@ func (p *JSONPath) parseFunctionArgument(single bool) (*functionArgument, error)
// function-expr

if lit, err := p.parseLiteral(); err == nil {
return &functionArgument{literal: lit}, nil
return &functionArgument{literalValue: lit}, nil
}
switch p.tokens[p.current].Token {
case token.CURRENT:
Expand Down
3 changes: 2 additions & 1 deletion pkg/jsonpath/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package jsonpath_test

import (
"testing"

"github.com/speakeasy-api/jsonpath/pkg/jsonpath"
"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
"github.com/stretchr/testify/require"
"testing"
)

func TestParser(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions pkg/jsonpath/segment.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package jsonpath

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

"gopkg.in/yaml.v3"
)

type segmentKind int

const (
segmentKindChild segmentKind = iota // .
segmentKindDescendant // ..
segmentKindProperyName // ~ (extension only)
segmentKindChild segmentKind = iota // .
segmentKindDescendant // ..
segmentKindPropertyName // ~ (extension only)
)

type segment struct {
Expand All @@ -37,7 +38,7 @@ func (s segment) ToString() string {
}
case segmentKindDescendant:
return ".." + s.descendant.ToString()
case segmentKindProperyName:
case segmentKindPropertyName:
return "~"
}
panic("unknown segment kind")
Expand Down
3 changes: 2 additions & 1 deletion pkg/jsonpath/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package token

import (
"fmt"
"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
"strconv"
"strings"

"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
)

// *****************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion pkg/jsonpath/token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package token

import (
"fmt"
"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
"testing"

"github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
)

func TestTokenizer(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 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"

"gopkg.in/yaml.v3"
)

func (l literal) Equals(value literal) bool {
Expand Down Expand Up @@ -105,8 +106,8 @@ func (l literal) LessThanOrEqual(value literal) bool {
}

func (c comparable) Evaluate(idx index, node *yaml.Node, root *yaml.Node) literal {
if c.literal != nil {
return *c.literal
if c.literalValue != nil {
return *c.literalValue
}
if c.singularQuery != nil {
return c.singularQuery.Evaluate(idx, node, root)
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 @@ -212,7 +212,7 @@ func TestComparableEvaluate(t *testing.T) {
}{
{
name: "literal",
comparable: comparable{literal: &literal{integer: intPtr(10)}},
comparable: comparable{literalValue: &literal{integer: intPtr(10)}},
node: yamlNodeFromString("foo"),
root: yamlNodeFromString("foo"),
expected: literal{integer: intPtr(10)},
Expand Down
2 changes: 1 addition & 1 deletion pkg/jsonpath/yaml_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s segment) Query(idx index, value *yaml.Node, root *yaml.Node) []*yaml.Nod
// make children unique by pointer value
result = unique(result)
return result
case segmentKindProperyName:
case segmentKindPropertyName:
found := idx.getPropertyKey(value)
if found != nil {
return []*yaml.Node{found}
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"
"gopkg.in/yaml.v3"
)

func TestQuery(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 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"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
"os"
"testing"
)

// NodeMatchesFile is a test that marshals the YAML file from the given node,
Expand Down
5 changes: 3 additions & 2 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"
)

func LoadSpecification(path string) (*yaml.Node, error) {
Expand Down
3 changes: 2 additions & 1 deletion 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"

"gopkg.in/yaml.v3"
)

// Parse will parse the given reader as an overlay file.
Expand Down
5 changes: 3 additions & 2 deletions pkg/overlay/parse_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package overlay_test

import (
"os"
"testing"

"github.com/speakeasy-api/jsonpath/pkg/overlay"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)

var expectOverlay = &overlay.Overlay{
Expand Down
1 change: 1 addition & 0 deletions pkg/overlay/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package overlay

import (
"bytes"

"gopkg.in/yaml.v3"
)

Expand Down
Loading