Skip to content

Commit bb21002

Browse files
committed
feat(): dotnet format using overrides
Signed-off-by: Joe Feser <[email protected]>
1 parent c45c05c commit bb21002

38 files changed

+445
-446
lines changed

src/ApiGenerator/CodeTemplatePage.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ namespace ApiGenerator;
3333

3434
public abstract class CodeTemplatePage<TModel> : TemplatePage<TModel>
3535
{
36-
protected new Task IncludeAsync(string key, object model = null)
37-
=> base.IncludeAsync(key.Replace('/', '.'), model);
36+
protected new Task IncludeAsync(string key, object model = null)
37+
=> base.IncludeAsync(key.Replace('/', '.'), model);
3838

39-
protected async Task IncludeLegacyGeneratorNotice() => await IncludeAsync("GeneratorNotice", true);
39+
protected async Task IncludeLegacyGeneratorNotice() => await IncludeAsync("GeneratorNotice", true);
4040

41-
protected async Task IncludeGeneratorNotice() => await IncludeAsync("GeneratorNotice", false);
41+
protected async Task IncludeGeneratorNotice() => await IncludeAsync("GeneratorNotice", false);
4242
}

src/ApiGenerator/Configuration/CodeConfiguration.cs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,31 @@
3636
namespace ApiGenerator.Configuration
3737
{
3838
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"),
4444

45-
new("cat.*"),
46-
new("cluster.*"),
47-
new("dangling_indices.*"),
45+
new("cat.*"),
46+
new("cluster.*"),
47+
new("dangling_indices.*"),
4848

49-
new("indices.{delete,exists,get,put}_index_template"),
49+
new("indices.{delete,exists,get,put}_index_template"),
5050

51-
new("ingest.*"),
51+
new("ingest.*"),
5252
new("nodes.*"),
53-
new("snapshot.*"),
54-
new("tasks.*")
55-
};
53+
new("snapshot.*"),
54+
new("tasks.*")
55+
};
5656

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));
5858

59-
/// <summary>
59+
/// <summary>
6060
/// Map API default names for API's we are only supporting on the low level client first
6161
/// </summary>
6262
private static readonly Dictionary<string, string> LowLevelApiNameMapping = new()
63-
{
63+
{
6464
};
6565

6666
/// <summary>
@@ -69,10 +69,10 @@ public static class CodeConfiguration
6969
/// </summary>
7070
public static readonly Dictionary<string, string> HighLevelApiNameMapping =
7171
(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", "") })
7676
.DistinctBy(v => v.Key)
7777
.ToDictionary(k => k.Key, v => v.Value.Replace(".cs", ""));
7878

@@ -84,7 +84,7 @@ public static bool IsNewHighLevelApi(string apiFileName) =>
8484

8585
public static bool IgnoreHighLevelApi(string apiFileName)
8686
{
87-
//always generate already mapped requests
87+
//always generate already mapped requests
8888

8989
if (HighLevelApiNameMapping.ContainsKey(apiFileName.Replace(".json", ""))) return false;
9090

@@ -119,20 +119,20 @@ public static Dictionary<string, string> ApiNameMapping
119119
/// </summary>
120120
public static readonly Dictionary<string, string> ResponseBuilderInClientCalls =
121121
(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 })
126126
.DistinctBy(v => v.Key)
127127
.ToDictionary(k => k.Key, v => v.Value);
128128

129129
public static readonly Dictionary<string, string> DescriptorGenericsLookup =
130130
(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") })
136136
.DistinctBy(v => v.Key)
137137
.OrderBy(v => v.Key)
138138
.ToDictionary(k => k.Key, v => v.Value);
@@ -142,16 +142,16 @@ where Regex.IsMatch(l, ResponseBuilderAttributeRegex)
142142
// find all files in OSC ending with Request.cs
143143
from f in new DirectoryInfo(GeneratorLocations.OpenSearchClientFolder).GetFiles("*Request.cs", SearchOption.AllDirectories)
144144
from l in File.ReadLines(f.FullName)
145-
// attempt to locate all Request interfaces lines
145+
// attempt to locate all Request interfaces lines
146146
where Regex.IsMatch(l, @"^.+interface [^ \r\n]+Request")
147147
//grab the interface name including any generics declared on it
148148
let c = Regex.Replace(l, @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$", "$1", RegexOptions.Singleline)
149149
where c.StartsWith("I") && c.Contains("Request")
150150
let request = Regex.Replace(c, "<.*$", "")
151151
let generics = Regex.Replace(c, @"^.*?(?:(\<.+>).*?)?$", "$1")
152-
select Tuple.Create(request, generics)
152+
select Tuple.Create(request, generics)
153153
)
154-
.OrderBy(v=>v.Item1)
154+
.OrderBy(v => v.Item1)
155155
.ToList();
156156

157157
public static readonly HashSet<string> GenericOnlyInterfaces = new HashSet<string>(AllKnownRequestInterfaces
@@ -164,7 +164,7 @@ select Tuple.Create(request, generics)
164164
// find all files in OSC ending with Request.cs
165165
from f in new DirectoryInfo(GeneratorLocations.OpenSearchClientFolder).GetFiles("*Request.cs", SearchOption.AllDirectories)
166166
from l in File.ReadLines(f.FullName)
167-
// attempt to locate all Request interfaces lines
167+
// attempt to locate all Request interfaces lines
168168
where Regex.IsMatch(l, @"^.+interface [^ \r\n]+Request")
169169
where l.Contains("IDocumentRequest")
170170
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)
189189

190190
public static readonly Dictionary<string, string> RequestInterfaceGenericsLookup =
191191
AllKnownRequestInterfaces
192-
.GroupBy(v=>v.Item1)
193-
.Select(g=>g.Last())
192+
.GroupBy(v => v.Item1)
193+
.Select(g => g.Last())
194194
.ToDictionary(k => k.Item1, v => v.Item2);
195195

196196
/// <summary>
@@ -213,17 +213,17 @@ where Regex.IsMatch(l, re)
213213
// find all files in OSC ending with Request.cs
214214
from f in new DirectoryInfo(GeneratorLocations.OpenSearchClientFolder).GetFiles("*Response.cs", SearchOption.AllDirectories)
215215
from l in File.ReadLines(f.FullName)
216-
// attempt to locate all Response class lines
216+
// attempt to locate all Response class lines
217217
where Regex.IsMatch(l, @"^.+public class [^ \r\n]+Response")
218218
//grab the response name including any generics declared on it
219219
let c = Regex.Replace(l, @"^.+public class ([^ \r\n]+Response(?:<[^>\r\n]+>)?[^ \r\n]*).*$", "$1", RegexOptions.Singleline)
220220
where c.Contains("Response")
221221
let response = Regex.Replace(c, "<.*$", "")
222222
let generics = Regex.Replace(c, @"^.*?(?:(\<.+>).*?)?$", "$1")
223-
select (response, (response, generics))
223+
select (response, (response, generics))
224224
)
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));
227227

228228
}
229229
}

src/ApiGenerator/Configuration/GeneratorLocations.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,42 @@
3131

3232
namespace ApiGenerator.Configuration
3333
{
34-
public static class GeneratorLocations
35-
{
36-
public static string OpenApiSpecFile { get; } = $"{Root}opensearch-openapi.yaml";
34+
public static class GeneratorLocations
35+
{
36+
public static string OpenApiSpecFile { get; } = $"{Root}opensearch-openapi.yaml";
3737

38-
public static string OpenSearchNetFolder { get; } = $"{Root}../../src/OpenSearch.Net/";
38+
public static string OpenSearchNetFolder { get; } = $"{Root}../../src/OpenSearch.Net/";
3939

40-
public static string OpenSearchClientFolder { get; } = $"{Root}../../src/OpenSearch.Client/";
40+
public static string OpenSearchClientFolder { get; } = $"{Root}../../src/OpenSearch.Client/";
4141

42-
public static string LowLevelGeneratedFolder { get; } = $"{OpenSearchNetFolder}_Generated/";
42+
public static string LowLevelGeneratedFolder { get; } = $"{OpenSearchNetFolder}_Generated/";
4343

44-
public static string HighLevelGeneratedFolder { get; } = $"{OpenSearchClientFolder}_Generated/";
44+
public static string HighLevelGeneratedFolder { get; } = $"{OpenSearchClientFolder}_Generated/";
4545

46-
public static string HighLevel(params string[] paths) => HighLevelGeneratedFolder + string.Join("/", paths);
46+
public static string HighLevel(params string[] paths) => HighLevelGeneratedFolder + string.Join("/", paths);
4747

48-
public static string LowLevel(params string[] paths) => LowLevelGeneratedFolder + string.Join("/", paths);
48+
public static string LowLevel(params string[] paths) => LowLevelGeneratedFolder + string.Join("/", paths);
4949

50-
public static readonly Assembly Assembly = typeof(Generator.ApiGenerator).Assembly;
50+
public static readonly Assembly Assembly = typeof(Generator.ApiGenerator).Assembly;
5151

52-
private static string _root;
52+
private static string _root;
5353

54-
public static string Root
55-
{
56-
get
57-
{
58-
if (_root != null) return _root;
54+
public static string Root
55+
{
56+
get
57+
{
58+
if (_root != null) return _root;
5959

60-
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
60+
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
6161

62-
var dotnetRun =
63-
directoryInfo.Name == "ApiGenerator" &&
64-
directoryInfo.Parent != null &&
65-
directoryInfo.Parent.Name == "src";
62+
var dotnetRun =
63+
directoryInfo.Name == "ApiGenerator" &&
64+
directoryInfo.Parent != null &&
65+
directoryInfo.Parent.Name == "src";
6666

67-
_root = dotnetRun ? "" : "../../../";
68-
return _root;
69-
}
70-
}
71-
}
67+
_root = dotnetRun ? "" : "../../../";
68+
return _root;
69+
}
70+
}
71+
}
7272
}

src/ApiGenerator/Configuration/Overrides/EndpointOverridesBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ApiGenerator.Configuration.Overrides
3333
{
3434
public abstract class EndpointOverridesBase : IEndpointOverrides
3535
{
36-
public virtual IDictionary<string, string> RenameUrlParts { get; } = new SortedDictionary<string, string>();
36+
public virtual IDictionary<string, string> RenameUrlParts { get; } = new SortedDictionary<string, string>();
3737

3838
public virtual IDictionary<string, string> ObsoleteQueryStringParams { get; set; } = new SortedDictionary<string, string>();
3939

src/ApiGenerator/Configuration/Overrides/GlobalOverrides.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
namespace ApiGenerator.Configuration.Overrides
3232
{
3333
public class GlobalOverrides : EndpointOverridesBase
34-
{
35-
public static readonly GlobalOverrides Instance = new();
34+
{
35+
public static readonly GlobalOverrides Instance = new();
3636

37-
private GlobalOverrides() { }
37+
private GlobalOverrides() { }
3838

39-
public IDictionary<string, string> RenameEnums { get; } = new Dictionary<string, string>
40-
{
41-
{ "ExpandWildcard", "ExpandWildcards" }
42-
};
39+
public IDictionary<string, string> RenameEnums { get; } = new Dictionary<string, string>
40+
{
41+
{ "ExpandWildcard", "ExpandWildcards" }
42+
};
4343

4444
public override IDictionary<string, string> ObsoleteQueryStringParams { get; set; } = new Dictionary<string, string>
4545
{

src/ApiGenerator/Configuration/Overrides/IEndpointOverrides.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ namespace ApiGenerator.Configuration.Overrides
3535
/// </summary>
3636
public interface IEndpointOverrides
3737
{
38-
/// <summary>
39-
/// Override how the url part is exposed to the client.
40-
/// </summary>
41-
IDictionary<string, string> RenameUrlParts { get; }
38+
/// <summary>
39+
/// Override how the url part is exposed to the client.
40+
/// </summary>
41+
IDictionary<string, string> RenameUrlParts { get; }
4242

4343
/// <summary>
4444
/// A map of key -> obsolete message for properties in the spec that should not be used any longer

src/ApiGenerator/Domain/ApiRequestParametersPatcher.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ namespace ApiGenerator.Domain
3636
{
3737
public static class ApiRequestParametersPatcher
3838
{
39-
public static void PatchUrlPaths(string endpointName, IList<UrlPath> source, IEndpointOverrides overrides)
40-
{
41-
var declaredKeys = source.SelectMany(p => p.Parts).Select(p => p.Name).ToHashSet();
42-
var renameLookup = CreateUrlPartRenameLookup(overrides, declaredKeys);
43-
44-
foreach (var path in source)
45-
{
46-
foreach (var part in path.Parts)
47-
{
48-
if (!renameLookup.TryGetValue(part.Name, out var newName)) continue;
49-
50-
path.Path = path.Path.Replace($"{{{part.Name}}}", $"{{{newName}}}");
51-
part.Name = newName;
52-
}
53-
}
54-
}
39+
public static void PatchUrlPaths(string endpointName, IList<UrlPath> source, IEndpointOverrides overrides)
40+
{
41+
var declaredKeys = source.SelectMany(p => p.Parts).Select(p => p.Name).ToHashSet();
42+
var renameLookup = CreateUrlPartRenameLookup(overrides, declaredKeys);
43+
44+
foreach (var path in source)
45+
{
46+
foreach (var part in path.Parts)
47+
{
48+
if (!renameLookup.TryGetValue(part.Name, out var newName)) continue;
49+
50+
path.Path = path.Path.Replace($"{{{part.Name}}}", $"{{{newName}}}");
51+
part.Name = newName;
52+
}
53+
}
54+
}
5555

5656
public static SortedDictionary<string, QueryParameters> PatchQueryParameters(
5757
string endpointName,
@@ -69,7 +69,7 @@ IEndpointOverrides overrides
6969
var patchedParams = new SortedDictionary<string, QueryParameters>();
7070
foreach (var (queryStringKey, value) in source)
7171
{
72-
value.QueryStringKey = queryStringKey;
72+
value.QueryStringKey = queryStringKey;
7373

7474
if (!renameLookup.TryGetValue(queryStringKey, out var preferredName)) preferredName = queryStringKey;
7575

@@ -84,7 +84,7 @@ IEndpointOverrides overrides
8484
//make sure source_enabled takes a boolean only
8585
if (preferredName == "source_enabled") value.Type = "boolean";
8686

87-
patchedParams[preferredName] = value;
87+
patchedParams[preferredName] = value;
8888
}
8989

9090
return patchedParams;
@@ -97,8 +97,8 @@ private static string CreateCSharpName(string queryStringKey, string endpointNam
9797
if (queryStringKey == "format" && endpointName == "text_structure.find_structure")
9898
return "TextStructureFindStructureFormat";
9999

100-
return queryStringKey.ToPascalCase();
101-
}
100+
return queryStringKey.ToPascalCase();
101+
}
102102

103103
private static IList<string> CreateSkipList(IEndpointOverrides local, ICollection<string> declaredKeys) =>
104104
CreateList(local, "skip", e => e.SkipQueryStringParams, declaredKeys);
@@ -142,8 +142,8 @@ Func<IEndpointOverrides, IEnumerable<string>> @from, ICollection<string> declare
142142
return list.Distinct().ToList();
143143
}
144144

145-
private static IDictionary<string, string> CreateUrlPartRenameLookup(IEndpointOverrides local, ICollection<string> declaredKeys) =>
146-
CreateLookup(local, "url_part_rename", e => e.RenameUrlParts, declaredKeys);
145+
private static IDictionary<string, string> CreateUrlPartRenameLookup(IEndpointOverrides local, ICollection<string> declaredKeys) =>
146+
CreateLookup(local, "url_part_rename", e => e.RenameUrlParts, declaredKeys);
147147

148148
private static IDictionary<string, string> CreateRenameLookup(IEndpointOverrides local, ICollection<string> declaredKeys) =>
149149
CreateLookup(local, "rename", e => e.RenameQueryStringParams, declaredKeys);

0 commit comments

Comments
 (0)