@@ -300,7 +300,11 @@ protected virtual void SetAdditional31MetadataFromMapNode(JsonObject jsonObject)
300300 internal void SetJsonPointerPath ( string pointer , string nodeLocation )
301301 {
302302 // Relative reference to internal JSON schema node/resource (e.g. "#/properties/b")
303- if ( pointer . StartsWith ( "#/" , StringComparison . OrdinalIgnoreCase ) && ! pointer . Contains ( "/components/schemas" ) )
303+ #if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER || NET5_0_OR_GREATER
304+ if ( pointer . StartsWith ( "#/" , StringComparison . OrdinalIgnoreCase ) && ! pointer . Contains ( "/components/schemas" , StringComparison . OrdinalIgnoreCase ) )
305+ #else
306+ if ( pointer . StartsWith ( "#/" , StringComparison . OrdinalIgnoreCase ) && ! pointer . ToLowerInvariant ( ) . Contains ( "/components/schemas" ) )
307+ #endif
304308 {
305309 ReferenceV3 = ResolveRelativePointer ( nodeLocation , pointer ) ;
306310 }
@@ -316,23 +320,28 @@ internal void SetJsonPointerPath(string pointer, string nodeLocation)
316320 private static string ResolveRelativePointer ( string nodeLocation , string relativeRef )
317321 {
318322 // Convert nodeLocation to path segments
319- var segments = nodeLocation . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
323+ var nodeLocationSegments = nodeLocation . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
320324
321325 // Convert relativeRef to dynamic segments
322326 var relativeSegments = relativeRef . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) ;
323327
324328 // Locate the first occurrence of relativeRef segments in the full path
325- for ( int i = 0 ; i <= segments . Count - relativeSegments . Length ; i ++ )
329+ for ( int i = 0 ; i <= nodeLocationSegments . Count - relativeSegments . Length ; i ++ )
326330 {
327- if ( relativeSegments . SequenceEqual ( segments . Skip ( i ) . Take ( relativeSegments . Length ) ) )
331+ if ( relativeSegments . SequenceEqual ( nodeLocationSegments . Skip ( i ) . Take ( relativeSegments . Length ) , StringComparer . Ordinal ) &&
332+ nodeLocationSegments . Take ( i + relativeSegments . Length ) . ToArray ( ) is { Length : > 0 } matchingSegments )
328333 {
329334 // Trim to include just the matching segment chain
330- segments = [ .. segments . Take ( i + relativeSegments . Length ) ] ;
331- break ;
335+ return $ "#/{ string . Join ( "/" , matchingSegments ) } ";
332336 }
333337 }
334338
335- return $ "#/{ string . Join ( "/" , segments ) } ";
339+ // Fallback on building a full path
340+ #if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER || NET5_0_OR_GREATER
341+ return $ "#/{ string . Join ( "/" , nodeLocationSegments . SkipLast ( relativeSegments . Length ) . Union ( relativeSegments ) ) } ";
342+ #else
343+ return $ "#/{ string . Join ( "/" , nodeLocationSegments . Take ( nodeLocationSegments . Count - relativeSegments . Length ) . Union ( relativeSegments ) ) } ";
344+ #endif
336345 }
337346 }
338347}
0 commit comments