@@ -740,17 +740,28 @@ func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
740740 sb .WriteString ("']" )
741741 segs [i ] = sb .String ()
742742
743- if len (cleaned ) > 0 {
743+ if len (cleaned ) > 0 && i < len ( segs ) - 1 {
744744 sb .Reset ()
745745 sb .WriteString (segs [i - 1 ])
746746 sb .WriteString (segs [i ])
747747 cleaned [len (cleaned )- 1 ] = sb .String ()
748748 continue
749749 } else {
750- if i > 0 {
750+ if i > 0 && i < len ( segs ) - 1 {
751751 cleaned = append (cleaned , segs [i ])
752752 continue
753753 }
754+ if i == len (segs )- 1 {
755+ sb .Reset ()
756+ l := len (cleaned )
757+ if l > 0 {
758+ sb .WriteString (cleaned [l - 1 ])
759+ sb .WriteString (segs [i ])
760+ cleaned [l - 1 ] = sb .String ()
761+ } else {
762+ cleaned = append (cleaned , segs [i ])
763+ }
764+ }
754765 }
755766 } else {
756767
@@ -761,21 +772,6 @@ func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
761772 continue
762773 }
763774
764- // check for brackets in the name, and if found, rewire the path to encapsulate them
765- // correctly. https://github.com/pb33f/libopenapi/issues/112
766- brackets := bracketNameExp .FindStringSubmatch (segs [i ])
767-
768- if len (brackets ) > 0 {
769- segs [i ] = bracketNameExp .ReplaceAllString (segs [i ], "['$1[$2]']" )
770- if len (cleaned ) > 0 {
771- sb .Reset ()
772- sb .WriteString (segs [i - 1 ])
773- sb .WriteString (segs [i ])
774- cleaned [len (cleaned )- 1 ] = sb .String ()
775- continue
776- }
777- }
778-
779775 intVal , err := strconv .Atoi (segs [i ])
780776 if err == nil {
781777 if intVal <= 99 {
@@ -812,10 +808,6 @@ func ConvertComponentIdIntoFriendlyPathSearch(id string) (string, string) {
812808 }
813809 }
814810
815- if len (cleaned ) == 0 && len (segs ) == 1 {
816- cleaned = append (cleaned , segs [0 ])
817- }
818-
819811 var replaced string
820812 if len (cleaned ) > 1 {
821813 replaced = strings .ReplaceAll (strings .Join (cleaned , "." ), "#" , "$" )
0 commit comments