Skip to content

Commit

Permalink
Merge pull request #29 from cerberauth/fix-match-rule
Browse files Browse the repository at this point in the history
fix: change regex for path params special chars
  • Loading branch information
emmanuelgautier authored Jun 22, 2023
2 parents bc6ca82 + 2d2c0f6 commit 017df41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions generator/.snapshots/TestGenerateFromPetstoreWithOpenIdConnect
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
Methods: ([]string) (len=1) {
(string) (len=6) "DELETE"
},
URL: (string) (len=103) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/store/order/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>"
URL: (string) (len=108) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/store/order/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -177,7 +177,7 @@
Methods: ([]string) (len=1) {
(string) (len=6) "DELETE"
},
URL: (string) (len=95) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>"
URL: (string) (len=100) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -230,7 +230,7 @@
Methods: ([]string) (len=1) {
(string) (len=6) "DELETE"
},
URL: (string) (len=96) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/user/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>"
URL: (string) (len=101) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/user/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -414,7 +414,7 @@
Methods: ([]string) (len=1) {
(string) (len=3) "GET"
},
URL: (string) (len=103) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/store/order/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>"
URL: (string) (len=108) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/store/order/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -453,7 +453,7 @@
Methods: ([]string) (len=1) {
(string) (len=3) "GET"
},
URL: (string) (len=95) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>"
URL: (string) (len=100) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -506,7 +506,7 @@
Methods: ([]string) (len=1) {
(string) (len=3) "GET"
},
URL: (string) (len=96) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/user/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>"
URL: (string) (len=101) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/user/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -715,7 +715,7 @@
Methods: ([]string) (len=1) {
(string) (len=4) "POST"
},
URL: (string) (len=102) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]\\x2D=\\?&)+/?(\\?.+)?)$>"
URL: (string) (len=107) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?(\\?.+)?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -768,7 +768,7 @@
Methods: ([]string) (len=1) {
(string) (len=3) "PUT"
},
URL: (string) (len=96) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/user/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>"
URL: (string) (len=101) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/user/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down Expand Up @@ -807,7 +807,7 @@
Methods: ([]string) (len=1) {
(string) (len=4) "POST"
},
URL: (string) (len=114) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]\\x2D=\\?&)+/uploadImage/?(\\?.+)?)$>"
URL: (string) (len=119) "<^(https://cerberauth\\.com/api/v3|http://swagger\\.io/api/v3)(/pet/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/uploadImage/?(\\?.+)?)$>"
}),
Authenticators: ([]rule.Handler) (len=1) {
(rule.Handler) {
Expand Down
10 changes: 5 additions & 5 deletions generator/match_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ var (

separatorToken = rex.Chars.Single('/')
stringToken = rex.Group.NonCaptured(
rex.Chars.Alphanumeric(),
rex.Chars.Single('-'),
rex.Chars.Single('='),
rex.Chars.Single('?'),
rex.Chars.Single('&'),
rex.Chars.Alphanumeric().Repeat().ZeroOrOne(),
rex.Chars.Single('-').Repeat().ZeroOrOne(),
rex.Chars.Single('=').Repeat().ZeroOrOne(),
rex.Chars.Single('?').Repeat().ZeroOrOne(),
rex.Chars.Single('&').Repeat().ZeroOrOne(),
)
)

Expand Down
4 changes: 2 additions & 2 deletions generator/match_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestGenerateMatchRuleWithMultipleServerUrls(t *testing.T) {

func TestGenerateMatchRuleWithPathParams(t *testing.T) {
expectedMatchingRule := rule.Match{
URL: "<^(https://cerberauth\\.com/api/v3)(/(?:[[:alnum:]]\\x2D=\\?&)+/resource/(?:[[:alnum:]]\\x2D=\\?&)+/?)$>",
URL: "<^(https://cerberauth\\.com/api/v3)(/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/resource/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?)$>",
Methods: []string{"GET"},
}
matchRule, err := createMatchRule([]string{"https://cerberauth.com/api/v3"}, "GET", "/{param}/resource/{otherParam}", nil)
Expand All @@ -50,7 +50,7 @@ func TestGenerateMatchRuleWithPathParams(t *testing.T) {

func TestGenerateMatchRuleWithQueryParams(t *testing.T) {
expectedMatchingRule := rule.Match{
URL: "<^(https://cerberauth\\.com/api/v3)(/(?:[[:alnum:]]\\x2D=\\?&)+/resource/(?:[[:alnum:]]\\x2D=\\?&)+/?(\\?.+)?)$>",
URL: "<^(https://cerberauth\\.com/api/v3)(/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/resource/(?:[[:alnum:]]?\\x2D?=?\\??&?)+/?(\\?.+)?)$>",
Methods: []string{"GET"},
}
params := openapi3.NewParameters()
Expand Down

0 comments on commit 017df41

Please sign in to comment.