Skip to content

Commit 88a738f

Browse files
authored
feat: Support RFC 9535 JSON Path syntax and prune dependencies (#11)
Reference: https://pkg.go.dev/github.com/wasilibs/go-re2 Reference: https://spec.openapis.org/arazzo/v1.0.1#criterion-expression-type-object The first change to remove the `github.com/wasilibs/go-re2` Go module dependency is purely for binary size considerations. It adds 2.49 MB by itself, plus its dependencies, to binary size. As noted by its README: > Note that if your regular expressions or input are small, this library is slower than the standard library. You will generally "know" if your application requires high performance for complex regular expressions, for example in security filtering software. If you do not know your app has such needs, you should turn away now. If regular expression parsing speed is a real concern, a separate Go submodule with the swapped dependency might be a better implementation so its opt-in for consumers. The second change replaces `k8s.io/client-go/util/jsonpath` with `github.com/speakeasy-api/jsonpath`. When this Go module was initially created, RFC 9535 compatible libraries did not exist yet. This change ensures RFC 9535 compliance, which is noted in the Arazzo version 1.0.1 specification as what should be the default when Criterion Expression Type Object (and its `version`) is not specified, which is the most common use case. If handling `version: draft-goessner-dispatch-jsonpath-00` is absolutely required, then a separate feature request should be created for consideration. Additional test validation ignores are added for legitimate RFC 9535 syntax issues (e.g. those criterion without explicit `version: draft-goessner-dispatch-jsonpath-00`) and the opposite now-unsupported `version: draft-goessner-dispatch-jsonpath-00`.
1 parent 9d7acca commit 88a738f

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

arazzo/arazzo_test.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ var stressTests = []struct {
480480
name: "Redocly Museum API",
481481
args: args{
482482
location: "https://raw.githubusercontent.com/Redocly/museum-openapi-example/2770b2b2e59832d245c7b0eb0badf6568d7efb53/arazzo/museum-api.arazzo.yaml",
483+
validationIgnores: []string{
484+
"[71:24] invalid jsonpath expression: Error at line 1, column 7: unexpected token when parsing segment", // legit invalid RFC 9535 syntax
485+
"[107:24] invalid jsonpath expression: Error at line 1, column 7: unexpected token when parsing segment", // legit invalid RFC 9535 syntax
486+
},
483487
},
484488
wantTitle: "Redocly Museum API Test Workflow",
485489
},
@@ -494,6 +498,9 @@ var stressTests = []struct {
494498
name: "Redocly Warp API",
495499
args: args{
496500
location: "https://raw.githubusercontent.com/Redocly/warp-single-sidebar/b78fc09da52d7755e92e1bc8f990edd37421cbde/apis/arazzo.yaml",
501+
validationIgnores: []string{
502+
"[63:24] invalid jsonpath expression: Error at line 1, column 12: unexpected token when parsing segment", // legit invalid RFC 9535 syntax
503+
},
497504
},
498505
wantTitle: "Warp API",
499506
},
@@ -532,6 +539,12 @@ var stressTests = []struct {
532539
name: "Arazzo OAuth Example",
533540
args: args{
534541
location: "https://raw.githubusercontent.com/OAI/Arazzo-Specification/23852b8b0d13ab1e3288a57a990611ffed45ab5d/examples/1.0.0/oauth.arazzo.yaml",
542+
validationIgnores: []string{
543+
"[65:24] invalid jsonpath expression: Error at line 1, column 15: unexpected token when parsing segment", // legit invalid RFC 9535 syntax
544+
"[105:24] invalid jsonpath expression: Error at line 1, column 15: unexpected token when parsing segment", // legit invalid RFC 9535 syntax
545+
"[155:24] invalid jsonpath expression: Error at line 1, column 15: unexpected token when parsing segment", // legit invalid RFC 9535 syntax
546+
"[175:24] invalid jsonpath expression: Error at line 1, column 15: unexpected token when parsing segment", // legit invalid RFC 9535 syntax
547+
},
535548
},
536549
wantTitle: "Example OAuth service",
537550
},
@@ -567,7 +580,9 @@ var stressTests = []struct {
567580
args: args{
568581
location: "https://raw.githubusercontent.com/leidenheit/itarazzo-library/3b335e1c4293444add52b5f2476420e2d871b1a5/src/test/resources/test.arazzo.yaml",
569582
validationIgnores: []string{
570-
"expression is not valid, must begin with $: <root><id>4711</id><name>Chocolate</name></root>", // legit issue
583+
"expression is not valid, must begin with $: <root><id>4711</id><name>Chocolate</name></root>", // legit issue
584+
"[32:24] invalid jsonpath expression: Error at line 1, column 0: unexpected token", // unsupported version: draft-goessner-dispatch-jsonpath-00
585+
"[36:24] invalid jsonpath expression: Error at line 1, column 5: unexpected token when parsing segment", // unsupported version: draft-goessner-dispatch-jsonpath-00
571586
},
572587
},
573588
wantTitle: "A cookie eating workflow",
@@ -579,6 +594,9 @@ var stressTests = []struct {
579594
validationIgnores: []string{
580595
"jsonpointer must start with /: $.status", // legit issues TODO: improve the error returned as it is wrong
581596
"jsonpointer must start with /: $.id", // legit issues TODO: improve the error returned as it is wrong
597+
"[81:24] invalid jsonpath expression: Error at line 1, column 7: unexpected token when parsing segment", // unsupported version: draft-goessner-dispatch-jsonpath-00
598+
"[110:24] invalid jsonpath expression: Error at line 1, column 5: unexpected token when parsing segment", // unsupported version: draft-goessner-dispatch-jsonpath-00
599+
"[114:24] invalid jsonpath expression: Error at line 1, column 9: unexpected token when parsing segment", // unsupported version: draft-goessner-dispatch-jsonpath-00
582600
},
583601
},
584602
wantTitle: "PetStore - Example of Workflows",
@@ -587,6 +605,9 @@ var stressTests = []struct {
587605
name: "Ritza build-a-bot workflow",
588606
args: args{
589607
location: "https://raw.githubusercontent.com/ritza-co/e2e-testing-arazzo/c0615c3708a1e4c0fcaeb79edae78ddc4eb5ba82/arazzo.yaml",
608+
validationIgnores: []string{
609+
"[42:24] invalid jsonpath expression: Error at line 1, column 8: unexpected token", // legit invalid RFC 9535 syntax
610+
},
590611
},
591612
wantTitle: "Build-a-Bot Workflow",
592613
},

arazzo/criterion/criterion.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package criterion
33
import (
44
"context"
55
"fmt"
6+
"regexp"
67
"strings"
78

9+
"github.com/speakeasy-api/jsonpath/pkg/jsonpath"
810
"github.com/speakeasy-api/openapi/arazzo/core"
911
"github.com/speakeasy-api/openapi/arazzo/expression"
1012
"github.com/speakeasy-api/openapi/extensions"
1113
"github.com/speakeasy-api/openapi/marshaller"
1214
"github.com/speakeasy-api/openapi/validation"
13-
regexp "github.com/wasilibs/go-re2"
14-
"k8s.io/client-go/util/jsonpath"
1515
)
1616

1717
// CriterionType represents the type of criterion.
@@ -297,7 +297,7 @@ func (c *Criterion) validateCondition(opts ...validation.Option) []error {
297297
})
298298
}
299299
case CriterionTypeJsonPath:
300-
if err := jsonpath.NewParser("jsonpath").Parse(c.Condition); err != nil {
300+
if _, err := jsonpath.NewPath(c.Condition); err != nil {
301301
errs = append(errs, &validation.Error{
302302
Message: fmt.Errorf("invalid jsonpath expression: %w", err).Error(),
303303
Line: conditionLine,

go.mod

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ go 1.23
44

55
require (
66
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
7+
github.com/speakeasy-api/jsonpath v0.6.1
78
github.com/stretchr/testify v1.9.0
8-
github.com/wasilibs/go-re2 v1.7.0
99
gopkg.in/yaml.v3 v3.0.1
10-
k8s.io/client-go v0.31.1
1110
)
1211

1312
require (
1413
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
14+
github.com/kr/text v0.2.0 // indirect
1515
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
16-
github.com/tetratelabs/wazero v1.8.0 // indirect
17-
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
18-
golang.org/x/sys v0.21.0 // indirect
1916
golang.org/x/text v0.18.0 // indirect
2017
)

go.sum

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
12
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
23
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
34
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
45
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
5-
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a h1:tdPcGgyiH0K+SbsJBBm2oPyEIOTAvLBwD9TuUwVtZho=
6-
github.com/magefile/mage v1.15.1-0.20230912152418-9f54e0f83e2a/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
6+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
7+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
8+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
710
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
811
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
912
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
1013
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
14+
github.com/speakeasy-api/jsonpath v0.6.1 h1:FWbuCEPGaJTVB60NZg2orcYHGZlelbNJAcIk/JGnZvo=
15+
github.com/speakeasy-api/jsonpath v0.6.1/go.mod h1:ymb2iSkyOycmzKwbEAYPJV/yi2rSmvBCLZJcyD+VVWw=
1116
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
1217
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
13-
github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g=
14-
github.com/tetratelabs/wazero v1.8.0/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
15-
github.com/wasilibs/go-re2 v1.7.0 h1:bYhl8gn+a9h01dxwotNycxkiFPTiSgwUrIz8KZJ90Lc=
16-
github.com/wasilibs/go-re2 v1.7.0/go.mod h1:sUsZMLflgl+LNivDE229omtmvjICmOseT9xOy199VDU=
17-
github.com/wasilibs/nottinygc v0.4.0 h1:h1TJMihMC4neN6Zq+WKpLxgd9xCFMw7O9ETLwY2exJQ=
18-
github.com/wasilibs/nottinygc v0.4.0/go.mod h1:oDcIotskuYNMpqMF23l7Z8uzD4TC0WXHK8jetlB3HIo=
19-
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4=
20-
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY=
21-
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
22-
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2318
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
2419
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
25-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2620
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
21+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
22+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2723
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2824
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
29-
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
30-
k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg=

0 commit comments

Comments
 (0)