mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
Added coverage, removed dead code from path utils
This commit is contained in:
@@ -702,11 +702,6 @@ func ConvertComponentIdIntoPath(id string) (string, string) {
|
||||
}
|
||||
replaced := strings.ReplaceAll(strings.Join(cleaned, "/"), "$", "#")
|
||||
|
||||
if len(replaced) > 0 {
|
||||
if replaced[0] != '#' {
|
||||
replaced = fmt.Sprintf("#%s", replaced)
|
||||
}
|
||||
}
|
||||
return name, replaced
|
||||
}
|
||||
|
||||
|
||||
@@ -783,6 +783,11 @@ func TestConvertComponentIdIntoFriendlyPathSearch_Array(t *testing.T) {
|
||||
assert.Equal(t, "0", segment)
|
||||
}
|
||||
|
||||
func TestConvertComponentIdIntoFriendlyPathSearch_Slashes(t *testing.T) {
|
||||
_, path := ConvertComponentIdIntoFriendlyPathSearch(`#/nice/\rice/\and/\spice`)
|
||||
assert.Equal(t, "$.nice.rice.and.spice", path)
|
||||
}
|
||||
|
||||
func TestConvertComponentIdIntoFriendlyPathSearch_HTTPCode(t *testing.T) {
|
||||
segment, path := ConvertComponentIdIntoFriendlyPathSearch("#/paths/~1crazy~1ass~1references/get/responses/404")
|
||||
assert.Equal(t, "$.paths['/crazy/ass/references'].get.responses['404']", path)
|
||||
@@ -795,6 +800,12 @@ func TestConvertComponentIdIntoPath(t *testing.T) {
|
||||
assert.Equal(t, "cake", segment)
|
||||
}
|
||||
|
||||
func TestConvertComponentIdIntoPath_NoHash(t *testing.T) {
|
||||
segment, path := ConvertComponentIdIntoPath("chicken.chips.pizza.cake")
|
||||
assert.Equal(t, "#/chicken/chips/pizza/cake", path)
|
||||
assert.Equal(t, "cake", segment)
|
||||
}
|
||||
|
||||
func TestConvertComponentIdIntoPath_Alt1(t *testing.T) {
|
||||
segment, path := ConvertComponentIdIntoPath("$.chicken.chips['pizza'].cakes[0].burgers[2]")
|
||||
assert.Equal(t, "#/chicken/chips/pizza/cakes/0/burgers/2", path)
|
||||
|
||||
Reference in New Issue
Block a user