77using System . Linq . Expressions ;
88using System . Net . Http ;
99using System . Text . Json . Nodes ;
10+ using System . Text . RegularExpressions ;
1011
1112namespace Microsoft . OpenApi
1213{
@@ -48,6 +49,17 @@ public OpenApiWalker(OpenApiVisitorBase visitor):this(visitor, null)
4849 {
4950 // TODO: remove this constructor in next major version and make nodesToVisit params
5051 }
52+ private static readonly Regex _normalizeExpression = new ( @"\w+ => \w+\." , RegexOptions . Compiled ) ;
53+ private static string NormalizeExpressionRepresentation ( Expression < Func < OpenApiDocument , object > > expression )
54+ {
55+ var stringRepresentation = expression . ToString ( ) ;
56+ var matchResult = _normalizeExpression . Match ( stringRepresentation ) ;
57+ if ( ! matchResult . Success )
58+ {
59+ throw new InvalidOperationException ( $ "Could not parse expression: { stringRepresentation } , the passed lambda expression is not in the expected format: d => d.Paths") ;
60+ }
61+ return _normalizeExpression . Replace ( stringRepresentation , "d => d." ) ;
62+ }
5163 private HashSet < string > ? nodesToVisitPaths ;
5264 private bool IsNodeSelected ( Expression < Func < OpenApiDocument , object > > candidate )
5365 {
@@ -61,11 +73,11 @@ private bool IsNodeSelected(Expression<Func<OpenApiDocument, object>> candidate)
6173 nodesToVisitPaths = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
6274 foreach ( var node in _nodesToVisit )
6375 {
64- nodesToVisitPaths . Add ( node . ToString ( ) ) ;
76+ nodesToVisitPaths . Add ( NormalizeExpressionRepresentation ( node ) ) ;
6577 }
6678 }
6779
68- return nodesToVisitPaths . Contains ( candidate . ToString ( ) ) ;
80+ return nodesToVisitPaths . Contains ( NormalizeExpressionRepresentation ( candidate ) ) ;
6981 }
7082
7183 /// <summary>
0 commit comments