@@ -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,27 @@ 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 ) )
328332 {
329333 // Trim to include just the matching segment chain
330- segments = [ .. segments . Take ( i + relativeSegments . Length ) ] ;
331- break ;
334+ return $ "#/{ string . Join ( "/" , [ .. nodeLocationSegments . Take ( i + relativeSegments . Length ) ] ) } ";
332335 }
333336 }
334337
335- return $ "#/{ string . Join ( "/" , segments ) } ";
338+ // Fallback on building a full path
339+ #if NETSTANDARD2_1 || NETCOREAPP2_1_OR_GREATER || NET5_0_OR_GREATER
340+ return $ "#/{ string . Join ( "/" , nodeLocationSegments . SkipLast ( relativeSegments . Length ) . Union ( relativeSegments ) ) } ";
341+ #else
342+ return $ "#/{ string . Join ( "/" , nodeLocationSegments . Take ( nodeLocationSegments . Count - relativeSegments . Length ) . Union ( relativeSegments ) ) } ";
343+ #endif
336344 }
337345 }
338346}
0 commit comments