@@ -73,11 +73,21 @@ public static class CodeConfiguration
7373 } ;
7474
7575
76+ /// <summary>
77+ /// Map API default names for API's we are only supporting on the low level client first
78+ /// </summary>
79+ private static readonly Dictionary < string , string > LowLevelApiNameMapping = new Dictionary < string , string >
80+ {
81+ { "indices.delete_index_template" , "DeleteIndexTemplateV2" } ,
82+ { "indices.get_index_template" , "GetIndexTemplateV2" } ,
83+ { "indices.put_index_template" , "PutIndexTemplateV2" }
84+ } ;
85+
7686 /// <summary>
7787 /// Scan all nest source code files for Requests and look for the [MapsApi(filename)] attribute.
7888 /// The class name minus Request is used as the canonical .NET name for the API.
7989 /// </summary>
80- public static readonly Dictionary < string , string > ApiNameMapping =
90+ private static readonly Dictionary < string , string > HighLevelApiNameMapping =
8191 ( from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*.cs" , SearchOption . AllDirectories )
8292 let contents = File . ReadAllText ( f . FullName )
8393 let c = Regex . Replace ( contents , @"^.+\[MapsApi\(""([^ \r\n]+)""\)\].*$" , "$1" , RegexOptions . Singleline )
@@ -86,7 +96,28 @@ public static class CodeConfiguration
8696 . DistinctBy ( v => v . Key )
8797 . ToDictionary ( k => k . Key , v => v . Value . Replace ( ".cs" , "" ) ) ;
8898
99+ private static Dictionary < string , string > _apiNameMapping ;
100+
101+ public static Dictionary < string , string > ApiNameMapping
102+ {
103+ get
104+ {
105+ if ( _apiNameMapping != null ) return _apiNameMapping ;
106+ lock ( LowLevelApiNameMapping )
107+ {
108+ if ( _apiNameMapping != null ) return _apiNameMapping ;
109+
110+ var mapping = HighLevelApiNameMapping ;
111+ foreach ( var ( k , v ) in LowLevelApiNameMapping )
112+ mapping [ k ] = v ;
113+ _apiNameMapping = mapping ;
114+ return _apiNameMapping ;
115+ }
116+ }
117+ }
118+
89119 private static readonly string ResponseBuilderAttributeRegex = @"^.+\[ResponseBuilderWithGeneric\(""([^ \r\n]+)""\)\].*$" ;
120+
90121 /// <summary>
91122 /// Scan all nest source code files for Requests and look for the [MapsApi(filename)] attribute.
92123 /// The class name minus Request is used as the canonical .NET name for the API.
@@ -113,19 +144,19 @@ where Regex.IsMatch(l, ResponseBuilderAttributeRegex)
113144
114145 /// <summary> Scan all NEST files for request interfaces and note any generics declared on them </summary>
115146 private static readonly List < Tuple < string , string > > AllKnownRequestInterfaces = (
116- // find all files in NEST ending with Request.cs
117- from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
118- from l in File . ReadLines ( f . FullName )
119- // attempt to locate all Request interfaces lines
120- where Regex . IsMatch ( l , @"^.+interface [^ \r\n]+Request" )
121- //grab the interface name including any generics declared on it
122- let c = Regex . Replace ( l , @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
123- where c . StartsWith ( "I" ) && c . Contains ( "Request" )
124- let request = Regex . Replace ( c , "<.*$" , "" )
125- let generics = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" )
126- select Tuple . Create ( request , generics )
147+ // find all files in NEST ending with Request.cs
148+ from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
149+ from l in File . ReadLines ( f . FullName )
150+ // attempt to locate all Request interfaces lines
151+ where Regex . IsMatch ( l , @"^.+interface [^ \r\n]+Request" )
152+ //grab the interface name including any generics declared on it
153+ let c = Regex . Replace ( l , @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
154+ where c . StartsWith ( "I" ) && c . Contains ( "Request" )
155+ let request = Regex . Replace ( c , "<.*$" , "" )
156+ let generics = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" )
157+ select Tuple . Create ( request , generics )
127158 )
128- . OrderBy ( v=> v . Item1 )
159+ . OrderBy ( v => v . Item1 )
129160 . ToList ( ) ;
130161
131162 public static readonly HashSet < string > GenericOnlyInterfaces = new HashSet < string > ( AllKnownRequestInterfaces
@@ -135,69 +166,67 @@ select Tuple.Create(request, generics)
135166 . ToList ( ) ) ;
136167
137168 public static readonly HashSet < string > DocumentRequests = new HashSet < string > ( (
138- // find all files in NEST ending with Request.cs
139- from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
140- from l in File . ReadLines ( f . FullName )
141- // attempt to locate all Request interfaces lines
142- where Regex . IsMatch ( l , @"^.+interface [^ \r\n]+Request" )
143- where l . Contains ( "IDocumentRequest" )
144- let c = Regex . Replace ( l , @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
145- //grab the interface name including any generics declared on it
146- let request = Regex . Replace ( c , "<.*$" , "" )
147- select request
169+ // find all files in NEST ending with Request.cs
170+ from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
171+ from l in File . ReadLines ( f . FullName )
172+ // attempt to locate all Request interfaces lines
173+ where Regex . IsMatch ( l , @"^.+interface [^ \r\n]+Request" )
174+ where l . Contains ( "IDocumentRequest" )
175+ let c = Regex . Replace ( l , @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
176+ //grab the interface name including any generics declared on it
177+ let request = Regex . Replace ( c , "<.*$" , "" )
178+ select request
148179 )
149180 . ToList ( ) ) ;
150181
151182 public static readonly Dictionary < string , string > DescriptorConstructors = (
152- // find all files in NEST ending with Request.cs
153- from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
154- let descriptor = Path . GetFileNameWithoutExtension ( f . Name ) . Replace ( "Request" , "Descriptor" )
155- let re = $@ "^.+public { descriptor } \(([^\r\n\)]+?)\).*$"
156- from l in File . ReadLines ( f . FullName )
157- where Regex . IsMatch ( l , re )
158- let args = Regex . Replace ( l , re , "$1" , RegexOptions . Singleline )
159- where ! string . IsNullOrWhiteSpace ( args ) && ! args . Contains ( ": base" )
160- select ( Descriptor : descriptor , Args : args )
183+ // find all files in NEST ending with Request.cs
184+ from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
185+ let descriptor = Path . GetFileNameWithoutExtension ( f . Name ) . Replace ( "Request" , "Descriptor" )
186+ let re = $@ "^.+public { descriptor } \(([^\r\n\)]+?)\).*$"
187+ from l in File . ReadLines ( f . FullName )
188+ where Regex . IsMatch ( l , re )
189+ let args = Regex . Replace ( l , re , "$1" , RegexOptions . Singleline )
190+ where ! string . IsNullOrWhiteSpace ( args ) && ! args . Contains ( ": base" )
191+ select ( Descriptor : descriptor , Args : args )
161192 )
162193 . ToDictionary ( r => r . Descriptor , r => r . Args ) ;
163194
164195 public static readonly Dictionary < string , string > RequestInterfaceGenericsLookup =
165196 AllKnownRequestInterfaces
166- . GroupBy ( v=> v . Item1 )
167- . Select ( g=> g . Last ( ) )
168- . ToDictionary ( k => k . Item1 , v => v . Item2 ) ;
197+ . GroupBy ( v => v . Item1 )
198+ . Select ( g => g . Last ( ) )
199+ . ToDictionary ( k => k . Item1 , v => v . Item2 ) ;
169200
170201 /// <summary>
171202 /// Some API's reuse response this is a hardcoded map of these cases
172203 /// </summary>
173204 private static Dictionary < string , ( string , string ) > ResponseReroute = new Dictionary < string , ( string , string ) >
174205 {
175- { "UpdateByQueryRethrottleResponse" , ( "ListTasksResponse" , "" ) } ,
176- { "DeleteByQueryRethrottleResponse" , ( "ListTasksResponse" , "" ) } ,
177- { "MultiSearchTemplateResponse" , ( "MultiSearchResponse" , "" ) } ,
178- { "ScrollResponse" , ( "SearchResponse" , "<TDocument>" ) } ,
179- { "SearchTemplateResponse" , ( "SearchResponse" , "<TDocument>" ) } ,
180-
206+ { "UpdateByQueryRethrottleResponse" , ( "ListTasksResponse" , "" ) } ,
207+ { "DeleteByQueryRethrottleResponse" , ( "ListTasksResponse" , "" ) } ,
208+ { "MultiSearchTemplateResponse" , ( "MultiSearchResponse" , "" ) } ,
209+ { "ScrollResponse" , ( "SearchResponse" , "<TDocument>" ) } ,
210+ { "SearchTemplateResponse" , ( "SearchResponse" , "<TDocument>" ) } ,
181211 } ;
182212
183213
184214 /// <summary> Create a dictionary lookup of all responses and their generics </summary>
185215 public static readonly SortedDictionary < string , ( string , string ) > ResponseLookup = new SortedDictionary < string , ( string , string ) > (
186- (
187- // find all files in NEST ending with Request.cs
188- from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Response.cs" , SearchOption . AllDirectories )
189- from l in File . ReadLines ( f . FullName )
190- // attempt to locate all Response class lines
191- where Regex . IsMatch ( l , @"^.+public class [^ \r\n]+Response" )
192- //grab the response name including any generics declared on it
193- let c = Regex . Replace ( l , @"^.+public class ([^ \r\n]+Response(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
194- where c . Contains ( "Response" )
195- let response = Regex . Replace ( c , "<.*$" , "" )
196- let generics = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" )
197- select ( response , ( response , generics ) )
198- )
199- . Concat ( ResponseReroute . Select ( kv=> ( kv . Key , ( kv . Value . Item1 , kv . Value . Item2 ) ) ) )
200- . ToDictionary ( t=> t . Item1 , t=> t . Item2 ) ) ;
201-
216+ (
217+ // find all files in NEST ending with Request.cs
218+ from f in new DirectoryInfo ( GeneratorLocations . NestFolder ) . GetFiles ( "*Response.cs" , SearchOption . AllDirectories )
219+ from l in File . ReadLines ( f . FullName )
220+ // attempt to locate all Response class lines
221+ where Regex . IsMatch ( l , @"^.+public class [^ \r\n]+Response" )
222+ //grab the response name including any generics declared on it
223+ let c = Regex . Replace ( l , @"^.+public class ([^ \r\n]+Response(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
224+ where c . Contains ( "Response" )
225+ let response = Regex . Replace ( c , "<.*$" , "" )
226+ let generics = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" )
227+ select ( response , ( response , generics ) )
228+ )
229+ . Concat ( ResponseReroute . Select ( kv => ( kv . Key , ( kv . Value . Item1 , kv . Value . Item2 ) ) ) )
230+ . ToDictionary ( t => t . Item1 , t => t . Item2 ) ) ;
202231 }
203232}
0 commit comments