@@ -314,14 +314,42 @@ internal void SetSummaryAndDescriptionFromMapNode(MapNode mapNode)
314314 }
315315 }
316316
317- internal void SetJsonPointerPath ( string pointer )
317+ internal void SetJsonPointerPath ( string pointer , string nodeLocation )
318318 {
319- // Eg of an internal subcomponent's JSONPath: #/components/schemas/person/properties/address
320- if ( ( pointer . Contains ( '#' ) || pointer . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) )
321- && ! string . IsNullOrEmpty ( ReferenceV3 ) && ! ReferenceV3 ! . Equals ( pointer , StringComparison . OrdinalIgnoreCase ) )
319+ // Relative reference to internal JSON schema node/resource (e.g. "#/properties/b")
320+ if ( pointer . StartsWith ( "#/" , StringComparison . OrdinalIgnoreCase ) && ! pointer . Contains ( "/components/schemas" ) )
321+ {
322+ ReferenceV3 = ResolveRelativePointer ( nodeLocation , pointer ) ;
323+ }
324+
325+ // Absolute reference or anchor (e.g. "#/components/schemas/..." or full URL)
326+ else if ( ( pointer . Contains ( '#' ) || pointer . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) )
327+ && ! string . Equals ( ReferenceV3 , pointer , StringComparison . OrdinalIgnoreCase ) )
322328 {
323329 ReferenceV3 = pointer ;
330+ }
331+ }
332+
333+ private static string ResolveRelativePointer ( string nodeLocation , string relativeRef )
334+ {
335+ // Convert nodeLocation to path segments
336+ var segments = nodeLocation . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
337+
338+ // Convert relativeRef to dynamic segments
339+ var relativeSegments = relativeRef . TrimStart ( '#' ) . Split ( [ '/' ] , StringSplitOptions . RemoveEmptyEntries ) ;
340+
341+ // Locate the first occurrence of relativeRef segments in the full path
342+ for ( int i = 0 ; i <= segments . Count - relativeSegments . Length ; i ++ )
343+ {
344+ if ( relativeSegments . SequenceEqual ( segments . Skip ( i ) . Take ( relativeSegments . Length ) ) )
345+ {
346+ // Trim to include just the matching segment chain
347+ segments = [ .. segments . Take ( i + relativeSegments . Length ) ] ;
348+ break ;
349+ }
324350 }
351+
352+ return $ "#/{ string . Join ( "/" , segments ) } ";
325353 }
326354 }
327355}
0 commit comments