36
36
namespace ApiGenerator . Configuration
37
37
{
38
38
public static class CodeConfiguration
39
- {
40
- private static readonly Glob [ ] OperationsToInclude =
41
- {
42
- new ( "{create,delete}_pit" ) ,
43
- new ( "{delete,get}_all_pits" ) ,
39
+ {
40
+ private static readonly Glob [ ] OperationsToInclude =
41
+ {
42
+ new ( "{create,delete}_pit" ) ,
43
+ new ( "{delete,get}_all_pits" ) ,
44
44
45
- new ( "cat.*" ) ,
46
- new ( "cluster.*" ) ,
47
- new ( "dangling_indices.*" ) ,
45
+ new ( "cat.*" ) ,
46
+ new ( "cluster.*" ) ,
47
+ new ( "dangling_indices.*" ) ,
48
48
49
- new ( "indices.{delete,exists,get,put}_index_template" ) ,
49
+ new ( "indices.{delete,exists,get,put}_index_template" ) ,
50
50
51
- new ( "ingest.*" ) ,
51
+ new ( "ingest.*" ) ,
52
52
new ( "nodes.*" ) ,
53
- new ( "snapshot.*" ) ,
54
- new ( "tasks.*" )
55
- } ;
53
+ new ( "snapshot.*" ) ,
54
+ new ( "tasks.*" )
55
+ } ;
56
56
57
- public static bool IncludeOperation ( string name ) => OperationsToInclude . Any ( g => g . IsMatch ( name ) ) ;
57
+ public static bool IncludeOperation ( string name ) => OperationsToInclude . Any ( g => g . IsMatch ( name ) ) ;
58
58
59
- /// <summary>
59
+ /// <summary>
60
60
/// Map API default names for API's we are only supporting on the low level client first
61
61
/// </summary>
62
62
private static readonly Dictionary < string , string > LowLevelApiNameMapping = new ( )
63
- {
63
+ {
64
64
} ;
65
65
66
66
/// <summary>
@@ -69,10 +69,10 @@ public static class CodeConfiguration
69
69
/// </summary>
70
70
public static readonly Dictionary < string , string > HighLevelApiNameMapping =
71
71
( from f in new DirectoryInfo ( GeneratorLocations . OpenSearchClientFolder ) . GetFiles ( "*.cs" , SearchOption . AllDirectories )
72
- let contents = File . ReadAllText ( f . FullName )
73
- let c = Regex . Replace ( contents , @"^.+\[MapsApi\(""([^ \r\n]+)""\)\].*$" , "$1" , RegexOptions . Singleline )
74
- where ! c . Contains ( " " ) //filter results that did not match
75
- select new { Value = f . Name . Replace ( "Request" , "" ) , Key = c . Replace ( ".json" , "" ) } )
72
+ let contents = File . ReadAllText ( f . FullName )
73
+ let c = Regex . Replace ( contents , @"^.+\[MapsApi\(""([^ \r\n]+)""\)\].*$" , "$1" , RegexOptions . Singleline )
74
+ where ! c . Contains ( " " ) //filter results that did not match
75
+ select new { Value = f . Name . Replace ( "Request" , "" ) , Key = c . Replace ( ".json" , "" ) } )
76
76
. DistinctBy ( v => v . Key )
77
77
. ToDictionary ( k => k . Key , v => v . Value . Replace ( ".cs" , "" ) ) ;
78
78
@@ -84,7 +84,7 @@ public static bool IsNewHighLevelApi(string apiFileName) =>
84
84
85
85
public static bool IgnoreHighLevelApi ( string apiFileName )
86
86
{
87
- //always generate already mapped requests
87
+ //always generate already mapped requests
88
88
89
89
if ( HighLevelApiNameMapping . ContainsKey ( apiFileName . Replace ( ".json" , "" ) ) ) return false ;
90
90
@@ -119,20 +119,20 @@ public static Dictionary<string, string> ApiNameMapping
119
119
/// </summary>
120
120
public static readonly Dictionary < string , string > ResponseBuilderInClientCalls =
121
121
( from f in new DirectoryInfo ( GeneratorLocations . OpenSearchClientFolder ) . GetFiles ( "*.cs" , SearchOption . AllDirectories )
122
- from l in File . ReadLines ( f . FullName )
123
- where Regex . IsMatch ( l , ResponseBuilderAttributeRegex )
124
- let c = Regex . Replace ( l , @"^.+\[ResponseBuilderWithGeneric\(""([^ \r\n]+)""\)\].*$" , "$1" , RegexOptions . Singleline )
125
- select new { Key = f . Name . Replace ( ".cs" , "" ) , Value = c } )
122
+ from l in File . ReadLines ( f . FullName )
123
+ where Regex . IsMatch ( l , ResponseBuilderAttributeRegex )
124
+ let c = Regex . Replace ( l , @"^.+\[ResponseBuilderWithGeneric\(""([^ \r\n]+)""\)\].*$" , "$1" , RegexOptions . Singleline )
125
+ select new { Key = f . Name . Replace ( ".cs" , "" ) , Value = c } )
126
126
. DistinctBy ( v => v . Key )
127
127
. ToDictionary ( k => k . Key , v => v . Value ) ;
128
128
129
129
public static readonly Dictionary < string , string > DescriptorGenericsLookup =
130
130
( from f in new DirectoryInfo ( GeneratorLocations . OpenSearchClientFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
131
- let name = Path . GetFileNameWithoutExtension ( f . Name ) . Replace ( "Request" , "" )
132
- let contents = File . ReadAllText ( f . FullName )
133
- let c = Regex . Replace ( contents , $@ "^.+class ({ name } Descriptor(?:<[^>\r\n]+>)?[^ \r\n]*).*$", "$1" , RegexOptions . Singleline )
134
- let key = $ "{ name } Descriptor"
135
- select new { Key = key , Value = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" ) } )
131
+ let name = Path . GetFileNameWithoutExtension ( f . Name ) . Replace ( "Request" , "" )
132
+ let contents = File . ReadAllText ( f . FullName )
133
+ let c = Regex . Replace ( contents , $@ "^.+class ({ name } Descriptor(?:<[^>\r\n]+>)?[^ \r\n]*).*$", "$1" , RegexOptions . Singleline )
134
+ let key = $ "{ name } Descriptor"
135
+ select new { Key = key , Value = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" ) } )
136
136
. DistinctBy ( v => v . Key )
137
137
. OrderBy ( v => v . Key )
138
138
. ToDictionary ( k => k . Key , v => v . Value ) ;
@@ -142,16 +142,16 @@ where Regex.IsMatch(l, ResponseBuilderAttributeRegex)
142
142
// find all files in OSC ending with Request.cs
143
143
from f in new DirectoryInfo ( GeneratorLocations . OpenSearchClientFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
144
144
from l in File . ReadLines ( f . FullName )
145
- // attempt to locate all Request interfaces lines
145
+ // attempt to locate all Request interfaces lines
146
146
where Regex . IsMatch ( l , @"^.+interface [^ \r\n]+Request" )
147
147
//grab the interface name including any generics declared on it
148
148
let c = Regex . Replace ( l , @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
149
149
where c . StartsWith ( "I" ) && c . Contains ( "Request" )
150
150
let request = Regex . Replace ( c , "<.*$" , "" )
151
151
let generics = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" )
152
- select Tuple . Create ( request , generics )
152
+ select Tuple . Create ( request , generics )
153
153
)
154
- . OrderBy ( v=> v . Item1 )
154
+ . OrderBy ( v => v . Item1 )
155
155
. ToList ( ) ;
156
156
157
157
public static readonly HashSet < string > GenericOnlyInterfaces = new HashSet < string > ( AllKnownRequestInterfaces
@@ -164,7 +164,7 @@ select Tuple.Create(request, generics)
164
164
// find all files in OSC ending with Request.cs
165
165
from f in new DirectoryInfo ( GeneratorLocations . OpenSearchClientFolder ) . GetFiles ( "*Request.cs" , SearchOption . AllDirectories )
166
166
from l in File . ReadLines ( f . FullName )
167
- // attempt to locate all Request interfaces lines
167
+ // attempt to locate all Request interfaces lines
168
168
where Regex . IsMatch ( l , @"^.+interface [^ \r\n]+Request" )
169
169
where l . Contains ( "IDocumentRequest" )
170
170
let c = Regex . Replace ( l , @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
@@ -189,8 +189,8 @@ where Regex.IsMatch(l, re)
189
189
190
190
public static readonly Dictionary < string , string > RequestInterfaceGenericsLookup =
191
191
AllKnownRequestInterfaces
192
- . GroupBy ( v=> v . Item1 )
193
- . Select ( g=> g . Last ( ) )
192
+ . GroupBy ( v => v . Item1 )
193
+ . Select ( g => g . Last ( ) )
194
194
. ToDictionary ( k => k . Item1 , v => v . Item2 ) ;
195
195
196
196
/// <summary>
@@ -213,17 +213,17 @@ where Regex.IsMatch(l, re)
213
213
// find all files in OSC ending with Request.cs
214
214
from f in new DirectoryInfo ( GeneratorLocations . OpenSearchClientFolder ) . GetFiles ( "*Response.cs" , SearchOption . AllDirectories )
215
215
from l in File . ReadLines ( f . FullName )
216
- // attempt to locate all Response class lines
216
+ // attempt to locate all Response class lines
217
217
where Regex . IsMatch ( l , @"^.+public class [^ \r\n]+Response" )
218
218
//grab the response name including any generics declared on it
219
219
let c = Regex . Replace ( l , @"^.+public class ([^ \r\n]+Response(?:<[^>\r\n]+>)?[^ \r\n]*).*$" , "$1" , RegexOptions . Singleline )
220
220
where c . Contains ( "Response" )
221
221
let response = Regex . Replace ( c , "<.*$" , "" )
222
222
let generics = Regex . Replace ( c , @"^.*?(?:(\<.+>).*?)?$" , "$1" )
223
- select ( response , ( response , generics ) )
223
+ select ( response , ( response , generics ) )
224
224
)
225
- . Concat ( ResponseReroute . Select ( kv=> ( kv . Key , ( kv . Value . Item1 , kv . Value . Item2 ) ) ) )
226
- . ToDictionary ( t=> t . Item1 , t=> t . Item2 ) ) ;
225
+ . Concat ( ResponseReroute . Select ( kv => ( kv . Key , ( kv . Value . Item1 , kv . Value . Item2 ) ) ) )
226
+ . ToDictionary ( t => t . Item1 , t => t . Item2 ) ) ;
227
227
228
228
}
229
229
}
0 commit comments