@@ -117,31 +117,34 @@ func composedRefFor(
117117 return "" , false
118118 }
119119
120- longestKey := ""
121- var longestRef * processRef
122- for key , pr := range processedNodes .FromOldest () {
123- if pr == nil || len (pr .location ) == 0 {
124- continue
125- }
126- if key == absoluteKey {
127- continue
128- }
129- if ! strings .HasPrefix (absoluteKey , key ) {
130- continue
131- }
132- suffix := strings .TrimPrefix (absoluteKey , key )
133- if suffix == "" || ! strings .HasPrefix (suffix , "/" ) {
134- continue
120+ if ref , ok := composedRefFromProcessRef (processedNodes .GetOrZero (absoluteKey ), "" ); ok {
121+ return ref , true
122+ }
123+
124+ fragmentStart := strings .Index (absoluteKey , "#/" )
125+ if fragmentStart == - 1 {
126+ return "" , false
127+ }
128+
129+ parentKey := absoluteKey
130+ for {
131+ slash := strings .LastIndex (parentKey , "/" )
132+ if slash <= fragmentStart + 1 {
133+ return "" , false
135134 }
136- if len (key ) > len (longestKey ) {
137- longestKey = key
138- longestRef = pr
135+
136+ parentKey = parentKey [:slash ]
137+ if ref , ok := composedRefFromProcessRef (processedNodes .GetOrZero (parentKey ), absoluteKey [len (parentKey ):]); ok {
138+ return ref , true
139139 }
140140 }
141- if longestRef == nil {
141+ }
142+
143+ func composedRefFromProcessRef (pr * processRef , suffix string ) (string , bool ) {
144+ if pr == nil || len (pr .location ) == 0 {
142145 return "" , false
143146 }
144- return "#/" + joinLocationAsJSONPointer (longestRef .location ) + strings . TrimPrefix ( absoluteKey , longestKey ) , true
147+ return "#/" + joinLocationAsJSONPointer (pr .location ) + suffix , true
145148}
146149
147150func calculateCollisionName (name , pointer , delimiter string , iteration int ) string {
0 commit comments