@@ -300,7 +300,11 @@ protected virtual void SetAdditional31MetadataFromMapNode(JsonObject jsonObject)
300
300
internal void SetJsonPointerPath ( string pointer , string nodeLocation )
301
301
{
302
302
// 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
304
308
{
305
309
ReferenceV3 = ResolveRelativePointer ( nodeLocation , pointer ) ;
306
310
}
@@ -316,23 +320,28 @@ internal void SetJsonPointerPath(string pointer, string nodeLocation)
316
320
private static string ResolveRelativePointer ( string nodeLocation , string relativeRef )
317
321
{
318
322
// Convert nodeLocation to path segments
319
- var segments = nodeLocation . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
323
+ var nodeLocationSegments = nodeLocation . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
320
324
321
325
// Convert relativeRef to dynamic segments
322
326
var relativeSegments = relativeRef . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) ;
323
327
324
328
// 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 ++ )
326
330
{
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 )
328
333
{
329
334
// Trim to include just the matching segment chain
330
- segments = [ .. segments . Take ( i + relativeSegments . Length ) ] ;
331
- break ;
335
+ return $ "#/{ string . Join ( "/" , matchingSegments ) } ";
332
336
}
333
337
}
334
338
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
336
345
}
337
346
}
338
347
}
0 commit comments