@@ -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,27 @@ 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 ) )
328
332
{
329
333
// 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 ) ] ) } ";
332
335
}
333
336
}
334
337
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
336
344
}
337
345
}
338
346
}
0 commit comments