diff --git a/README.md b/README.md index fc76e3e..ead9792 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/cmd/wasm/functions.go b/cmd/wasm/functions.go index 81cf9de..b534d21 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" ) func CalculateOverlay(originalYAML, targetYAML, existingOverlay string) (string, error) { diff --git a/integration_test.go b/integration_test.go index 79db502..cc074d4 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" + "gopkg.in/yaml.v3" ) type FullTestSuite struct { diff --git a/pkg/jsonpath/filter.go b/pkg/jsonpath/filter.go index 0f5b77f..b2e1a19 100644 --- a/pkg/jsonpath/filter.go +++ b/pkg/jsonpath/filter.go @@ -1,9 +1,10 @@ package jsonpath import ( - "gopkg.in/yaml.v3" "strconv" "strings" + + "gopkg.in/yaml.v3" ) // filter-selector = "?" S logical-expr @@ -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 @@ -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)) @@ -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 { @@ -241,7 +242,7 @@ func (e basicExpr) ToString() string { return "" } -// literal literal = number / +// literal literal-value = number / // . string-literal / // . true / false / null type literal struct { @@ -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 { @@ -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 = "==" / "!=" / diff --git a/pkg/jsonpath/jsonpath.go b/pkg/jsonpath/jsonpath.go index d5c8a5b..ade1d69 100644 --- a/pkg/jsonpath/jsonpath.go +++ b/pkg/jsonpath/jsonpath.go @@ -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" diff --git a/pkg/jsonpath/parser.go b/pkg/jsonpath/parser.go index ae6e7f1..d5fa1c3 100644 --- a/pkg/jsonpath/parser.go +++ b/pkg/jsonpath/parser.go @@ -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 @@ -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(¤tToken, "unexpected token when parsing segment") } @@ -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 { @@ -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) @@ -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: diff --git a/pkg/jsonpath/parser_test.go b/pkg/jsonpath/parser_test.go index 85f9878..bcc58c1 100644 --- a/pkg/jsonpath/parser_test.go +++ b/pkg/jsonpath/parser_test.go @@ -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) { diff --git a/pkg/jsonpath/segment.go b/pkg/jsonpath/segment.go index cb6233f..a26007a 100644 --- a/pkg/jsonpath/segment.go +++ b/pkg/jsonpath/segment.go @@ -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 { @@ -37,7 +38,7 @@ func (s segment) ToString() string { } case segmentKindDescendant: return ".." + s.descendant.ToString() - case segmentKindProperyName: + case segmentKindPropertyName: return "~" } panic("unknown segment kind") diff --git a/pkg/jsonpath/token/token.go b/pkg/jsonpath/token/token.go index 6cf1654..faf892f 100644 --- a/pkg/jsonpath/token/token.go +++ b/pkg/jsonpath/token/token.go @@ -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" ) // ***************************************************************************** diff --git a/pkg/jsonpath/token/token_test.go b/pkg/jsonpath/token/token_test.go index d8c7931..f2f4ec8 100644 --- a/pkg/jsonpath/token/token_test.go +++ b/pkg/jsonpath/token/token_test.go @@ -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) { diff --git a/pkg/jsonpath/yaml_eval.go b/pkg/jsonpath/yaml_eval.go index 7291ea9..d16749b 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" + + "gopkg.in/yaml.v3" ) func (l literal) Equals(value literal) bool { @@ -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) diff --git a/pkg/jsonpath/yaml_eval_test.go b/pkg/jsonpath/yaml_eval_test.go index a74e97b..31b9e39 100644 --- a/pkg/jsonpath/yaml_eval_test.go +++ b/pkg/jsonpath/yaml_eval_test.go @@ -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)}, diff --git a/pkg/jsonpath/yaml_query.go b/pkg/jsonpath/yaml_query.go index 44b55a3..ce36535 100644 --- a/pkg/jsonpath/yaml_query.go +++ b/pkg/jsonpath/yaml_query.go @@ -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} diff --git a/pkg/jsonpath/yaml_query_test.go b/pkg/jsonpath/yaml_query_test.go index 1927f58..6e1867b 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" + "gopkg.in/yaml.v3" ) func TestQuery(t *testing.T) { diff --git a/pkg/overlay/apply_test.go b/pkg/overlay/apply_test.go index 7f6fcf8..fe637d3 100644 --- a/pkg/overlay/apply_test.go +++ b/pkg/overlay/apply_test.go @@ -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, diff --git a/pkg/overlay/compare_test.go b/pkg/overlay/compare_test.go index fbf6a39..182c34d 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" ) func LoadSpecification(path string) (*yaml.Node, error) { diff --git a/pkg/overlay/parse.go b/pkg/overlay/parse.go index 0708846..e877413 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" + + "gopkg.in/yaml.v3" ) // Parse will parse the given reader as an overlay file. diff --git a/pkg/overlay/parse_test.go b/pkg/overlay/parse_test.go index 077157e..274537c 100644 --- a/pkg/overlay/parse_test.go +++ b/pkg/overlay/parse_test.go @@ -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{ diff --git a/pkg/overlay/schema.go b/pkg/overlay/schema.go index ae1ea3e..658a347 100644 --- a/pkg/overlay/schema.go +++ b/pkg/overlay/schema.go @@ -2,6 +2,7 @@ package overlay import ( "bytes" + "gopkg.in/yaml.v3" ) diff --git a/web/src/bridge.ts b/web/src/bridge.ts index 45123a7..04f9894 100644 --- a/web/src/bridge.ts +++ b/web/src/bridge.ts @@ -6,7 +6,7 @@ let messageQueue: { resolve: Function; reject: Function; message: any; - supercede: boolean; + supersede: boolean; }[] = []; let isProcessing = false; @@ -19,12 +19,12 @@ function processQueue() { wasmWorker.postMessage(message); wasmWorker.onmessage = (event: MessageEvent) => { if (event.data.type.endsWith("Result")) { - // Reject all superceded messages before resolving the current message - const supercedeMessages = messageQueue.filter((_, index) => { - return messageQueue.slice(index + 1).some((later) => later.supercede); + // Reject all superseded messages before resolving the current message + const supersedeMessages = messageQueue.filter((_, index) => { + return messageQueue.slice(index + 1).some((later) => later.supersede); }); - supercedeMessages.forEach((m) => m.reject(new Error("supercedeerror"))); - messageQueue = messageQueue.filter((m) => !supercedeMessages.includes(m)); + supersedeMessages.forEach((m) => m.reject(new Error("supersedeerror"))); + messageQueue = messageQueue.filter((m) => !supersedeMessages.includes(m)); resolve(event.data.payload); } else if (event.data.type.endsWith("Error")) { reject(new Error(event.data.error)); @@ -34,9 +34,9 @@ function processQueue() { }; } -function sendMessage(message: any, supercede = false): Promise { +function sendMessage(message: any, supersede = false): Promise { return new Promise((resolve, reject) => { - messageQueue.push({ resolve, reject, message, supercede }); + messageQueue.push({ resolve, reject, message, supersede }); processQueue(); }); } @@ -121,14 +121,14 @@ export function CalculateOverlay( from: string, to: string, existing: string, - supercede = false, + supersede = false, ): Promise { return sendMessage( { type: "CalculateOverlay", payload: { from, to, existing }, } satisfies CalculateOverlayMessage["Request"], - supercede, + supersede, ); } @@ -159,14 +159,14 @@ type ApplyOverlaySuccess = export async function ApplyOverlay( source: string, overlay: string, - supercede = false, + supersede = false, ): Promise { const result = await sendMessage( { type: "ApplyOverlay", payload: { source, overlay }, } satisfies ApplyOverlayMessage["Request"], - supercede, + supersede, ); return JSON.parse(result); } @@ -174,23 +174,23 @@ export async function ApplyOverlay( export function QueryJSONPath( source: string, jsonpath: string, - supercede = false, + supersede = false, ): Promise { return sendMessage( { type: "QueryJSONPath", payload: { source, jsonpath }, } satisfies QueryJSONPathMessage["Request"], - supercede, + supersede, ); } -export function GetInfo(openapi: string, supercede = false): Promise { +export function GetInfo(openapi: string, supersede = false): Promise { return sendMessage( { type: "GetInfo", payload: { openapi }, } satisfies GetInfoMessage["Request"], - supercede, + supersede, ); } diff --git a/web/src/defaults.ts b/web/src/defaults.ts index 67f28af..8e25fd9 100644 --- a/web/src/defaults.ts +++ b/web/src/defaults.ts @@ -73,7 +73,7 @@ paths: tags: - pet summary: Update an existing pet - description: Update an existing pet by Id + description: Update an existing pet by ID operationId: updatePet responses: '200':