Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Vault
Commits
d41f8cf1
Unverified
Commit
d41f8cf1
authored
3 years ago
by
Vinny Mannello
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
[Vault-4628] OpenAPI endpoint not expanding root alternations (#13487)
parent
b046cd9f
Branches unavailable
v1.10.2
v1.10.1
v1.10.0
v1.10.0-rc1
sdk/v0.4.1
sdk/v0.4.0
last-go-modable
api/v1.5.0
api/v1.4.1
api/v1.4.0
api/auth/ldap/v0.1.0
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog/13487.txt
+3
-0
changelog/13487.txt
sdk/framework/openapi.go
+21
-9
sdk/framework/openapi.go
sdk/framework/openapi_test.go
+4
-0
sdk/framework/openapi_test.go
with
28 additions
and
9 deletions
+28
-9
changelog/13487.txt
0 → 100644
+
3
-
0
View file @
d41f8cf1
```release-note:bug
sdk/framework: Generate proper OpenAPI specs for path patterns that use an alternation as the root.
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
sdk/framework/openapi.go
+
21
-
9
View file @
d41f8cf1
...
...
@@ -191,15 +191,16 @@ var OASStdRespNoContent = &OASResponse{
var
optRe
=
regexp
.
MustCompile
(
`(?U)\([^(]*\)\?|\(/\(\?P<[^(]*\)\)\?`
)
var
(
reqdRe
=
regexp
.
MustCompile
(
`\(?\?P<(\w+)>[^)]*\)?`
)
// Capture required parameters, e.g. "(?P<name>regex)"
altRe
=
regexp
.
MustCompile
(
`\((.*)\|(.*)\)`
)
// Capture alternation elements, e.g. "(raw/?$|raw/(?P<path>.+))"
pathFieldsRe
=
regexp
.
MustCompile
(
`{(\w+)}`
)
// Capture OpenAPI-style named parameters, e.g. "lookup/{urltoken}",
cleanCharsRe
=
regexp
.
MustCompile
(
"[()^$?]"
)
// Set of regex characters that will be stripped during cleaning
cleanSuffixRe
=
regexp
.
MustCompile
(
`/\?\$?$`
)
// Path suffix patterns that will be stripped during cleaning
wsRe
=
regexp
.
MustCompile
(
`\s+`
)
// Match whitespace, to be compressed during cleaning
altFieldsGroupRe
=
regexp
.
MustCompile
(
`\(\?P<\w+>\w+(\|\w+)+\)`
)
// Match named groups that limit options, e.g. "(?<foo>a|b|c)"
altFieldsRe
=
regexp
.
MustCompile
(
`\w+(\|\w+)+`
)
// Match an options set, e.g. "a|b|c"
nonWordRe
=
regexp
.
MustCompile
(
`[^\w]+`
)
// Match a sequence of non-word characters
altFieldsGroupRe
=
regexp
.
MustCompile
(
`\(\?P<\w+>\w+(\|\w+)+\)`
)
// Match named groups that limit options, e.g. "(?<foo>a|b|c)"
altFieldsRe
=
regexp
.
MustCompile
(
`\w+(\|\w+)+`
)
// Match an options set, e.g. "a|b|c"
altRe
=
regexp
.
MustCompile
(
`\((.*)\|(.*)\)`
)
// Capture alternation elements, e.g. "(raw/?$|raw/(?P<path>.+))"
altRootsRe
=
regexp
.
MustCompile
(
`^\(([\w\-_]+(?:\|[\w\-_]+)+)\)(/.*)$`
)
// Pattern starting with alts, e.g. "(root1|root2)/(?P<name>regex)"
cleanCharsRe
=
regexp
.
MustCompile
(
"[()^$?]"
)
// Set of regex characters that will be stripped during cleaning
cleanSuffixRe
=
regexp
.
MustCompile
(
`/\?\$?$`
)
// Path suffix patterns that will be stripped during cleaning
nonWordRe
=
regexp
.
MustCompile
(
`[^\w]+`
)
// Match a sequence of non-word characters
pathFieldsRe
=
regexp
.
MustCompile
(
`{(\w+)}`
)
// Capture OpenAPI-style named parameters, e.g. "lookup/{urltoken}",
reqdRe
=
regexp
.
MustCompile
(
`\(?\?P<(\w+)>[^)]*\)?`
)
// Capture required parameters, e.g. "(?P<name>regex)"
wsRe
=
regexp
.
MustCompile
(
`\s+`
)
// Match whitespace, to be compressed during cleaning
)
// documentPaths parses all paths in a framework.Backend into OpenAPI paths.
...
...
@@ -464,6 +465,17 @@ func specialPathMatch(path string, specialPaths []string) bool {
func
expandPattern
(
pattern
string
)
[]
string
{
var
paths
[]
string
// Determine if the pattern starts with an alternation for multiple roots
// example (root1|root2)/(?P<name>regex) -> match['(root1|root2)/(?P<name>regex)','root1|root2','/(?P<name>regex)']
match
:=
altRootsRe
.
FindStringSubmatch
(
pattern
)
if
len
(
match
)
==
3
{
var
expandedRoots
[]
string
for
_
,
root
:=
range
strings
.
Split
(
match
[
1
],
"|"
)
{
expandedRoots
=
append
(
expandedRoots
,
expandPattern
(
root
+
match
[
2
])
...
)
}
return
expandedRoots
}
// GenericNameRegex adds a regex that complicates our parsing. It is much easier to
// detect and remove it now than to compensate for in the other regexes.
//
...
...
This diff is collapsed.
Click to expand it.
sdk/framework/openapi_test.go
+
4
-
0
View file @
d41f8cf1
...
...
@@ -199,6 +199,10 @@ func TestOpenAPI_ExpandPattern(t *testing.T) {
{
"^plugins/catalog/(?P<type>auth|database|secret)/?$"
,
[]
string
{
"plugins/catalog/{type}"
,
}},
{
"(pathOne|pathTwo)/"
,
[]
string
{
"pathOne/"
,
"pathTwo/"
}},
{
"(pathOne|pathTwo)/"
+
GenericNameRegex
(
"name"
),
[]
string
{
"pathOne/{name}"
,
"pathTwo/{name}"
}},
{
"(pathOne|path-2|Path_3)/"
+
GenericNameRegex
(
"name"
),
[]
string
{
"Path_3/{name}"
,
"path-2/{name}"
,
"pathOne/{name}"
}},
}
for
i
,
test
:=
range
tests
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help