diff --git a/src/ApiGenerator/Configuration/CodeConfiguration.cs b/src/ApiGenerator/Configuration/CodeConfiguration.cs index 43d90c8470..e26d906491 100644 --- a/src/ApiGenerator/Configuration/CodeConfiguration.cs +++ b/src/ApiGenerator/Configuration/CodeConfiguration.cs @@ -42,6 +42,7 @@ public static class CodeConfiguration // e.g. new Glob("nodes.*"), new("dangling_indices.*"), new("ingest.*"), + new("snapshot.*"), new("tasks.*") }; diff --git a/src/ApiGenerator/Domain/Specification/ApiEndpoint.cs b/src/ApiGenerator/Domain/Specification/ApiEndpoint.cs index 541f3cfc65..d1ffdeb14b 100644 --- a/src/ApiGenerator/Domain/Specification/ApiEndpoint.cs +++ b/src/ApiGenerator/Domain/Specification/ApiEndpoint.cs @@ -103,17 +103,14 @@ public class ApiEndpoint HttpMethod = PreferredHttpMethod }; - public string PreferredHttpMethod - { - get + public string PreferredHttpMethod => + HttpMethods.OrderByDescending(m => m switch { - var first = HttpMethods.First(); - if (HttpMethods.Count > 1 && first.ToUpperInvariant() == "GET") - return HttpMethods.Last(); - - return first; - } - } + "GET" => 0, + "POST" => 1, + "PUT" or "DELETE" or "PATCH" or "HEAD" => 2, // Prefer "resource" methods over GET/POST methods + _ => -1 + }).First(); public string HighLevelMethodXmlDocDescription => $"{PreferredHttpMethod} request to the {Name} API, read more about this API online:"; diff --git a/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs b/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs index 362396187d..fe5a37ef96 100644 --- a/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs +++ b/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs @@ -44,7 +44,7 @@ public class HighLevelClientImplementationGenerator : RazorGeneratorBase public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, CancellationToken token) { var view = ViewLocations.HighLevel("Client", "Implementation", "OpenSearchClient.cshtml"); - var target = GeneratorLocations.HighLevel($"OpenSearchClient.{CsharpNames.RootNamespace}.cs"); + var target = GeneratorLocations.HighLevel($"OpenSearchClient.cs"); await DoRazor(spec, view, target, token); string Target(string id) => GeneratorLocations.HighLevel($"OpenSearchClient.{id}.cs"); diff --git a/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs b/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs index f9a9038fc1..8136fa30f0 100644 --- a/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs +++ b/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs @@ -44,7 +44,7 @@ public class LowLevelClientImplementationGenerator : RazorGeneratorBase public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, CancellationToken token) { var view = ViewLocations.LowLevel("Client", "Implementation", "OpenSearchLowLevelClient.cshtml"); - var target = GeneratorLocations.LowLevel($"OpenSearchLowLevelClient.{CsharpNames.RootNamespace}.cs"); + var target = GeneratorLocations.LowLevel("OpenSearchLowLevelClient.cs"); await DoRazor(spec, view, target, token); var namespaced = spec.EndpointsPerNamespaceLowLevel.Where(kv => kv.Key != CsharpNames.RootNamespace).ToList();