mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
updated regex for path conversions
This commit is contained in:
@@ -588,7 +588,7 @@ func IsHttpVerb(verb string) bool {
|
|||||||
|
|
||||||
// define bracket name expression
|
// define bracket name expression
|
||||||
var (
|
var (
|
||||||
bracketNameExp = regexp.MustCompile(`^(\w+)\['?(\w+)'?]$`)
|
bracketNameExp = regexp.MustCompile(`^(\w+)\['?([\w/]+)'?]$`)
|
||||||
pathCharExp = regexp.MustCompile(`[%=;~.]`)
|
pathCharExp = regexp.MustCompile(`[%=;~.]`)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -689,8 +689,12 @@ func ConvertComponentIdIntoPath(id string) (string, string) {
|
|||||||
|
|
||||||
// if there are brackets, shift the path to encapsulate them correctly.
|
// if there are brackets, shift the path to encapsulate them correctly.
|
||||||
if len(brackets) > 0 {
|
if len(brackets) > 0 {
|
||||||
|
|
||||||
|
//bracketNameExp/.
|
||||||
|
key := bracketNameExp.ReplaceAllString(segs[i], "$1")
|
||||||
|
val := strings.ReplaceAll(bracketNameExp.ReplaceAllString(segs[i], "$2"), "/", "~1")
|
||||||
cleaned = append(cleaned[:i],
|
cleaned = append(cleaned[:i],
|
||||||
append([]string{bracketNameExp.ReplaceAllString(segs[i], "$1/$2")}, cleaned[i:]...)...)
|
append([]string{fmt.Sprintf("%s/%s", key, val)}, cleaned[i:]...)...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cleaned = append(cleaned, segs[i])
|
cleaned = append(cleaned, segs[i])
|
||||||
|
|||||||
@@ -817,6 +817,11 @@ func TestConvertComponentIdIntoPath_Alt2(t *testing.T) {
|
|||||||
assert.Equal(t, "#/chicken/chips/pizza/cakes/0/burgers/2", path)
|
assert.Equal(t, "#/chicken/chips/pizza/cakes/0/burgers/2", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertComponentIdIntoPath_Alt3(t *testing.T) {
|
||||||
|
_, path := ConvertComponentIdIntoPath("chicken.chips['/one/two/pizza'].cakes[0].burgers[2]")
|
||||||
|
assert.Equal(t, "#/chicken/chips/~1one~1two~1pizza/cakes/0/burgers/2", path)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDetectCase(t *testing.T) {
|
func TestDetectCase(t *testing.T) {
|
||||||
assert.Equal(t, PascalCase, DetectCase("PizzaPie"))
|
assert.Equal(t, PascalCase, DetectCase("PizzaPie"))
|
||||||
assert.Equal(t, CamelCase, DetectCase("anyoneForTennis"))
|
assert.Equal(t, CamelCase, DetectCase("anyoneForTennis"))
|
||||||
|
|||||||
Reference in New Issue
Block a user