Skip to content

Commit

Permalink
Re-generate tasks namespace (#320)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
  • Loading branch information
Xtansia authored Aug 22, 2023
1 parent 610eab2 commit 65ac116
Show file tree
Hide file tree
Showing 31 changed files with 13,325 additions and 10,542 deletions.
2 changes: 1 addition & 1 deletion src/ApiGenerator/ApiGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSharpier.Core" Version="0.25.0" />
<PackageReference Include="Glob" Version="1.1.9" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NSwag.Core.Yaml" Version="13.19.0" />
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
Expand Down
1 change: 1 addition & 0 deletions src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static class CodeConfiguration
private static readonly Glob[] OperationsToInclude =
{
// e.g. new Glob("nodes.*"),
new("tasks.*")
};

public static bool IncludeOperation(string name) => OperationsToInclude.Any(g => g.IsMatch(name));
Expand Down
46 changes: 20 additions & 26 deletions src/ApiGenerator/Generator/Razor/RazorGeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using CSharpier;
using RazorLight;
using RazorLight.Generation;
using RazorLight.Razor;
Expand All @@ -51,13 +49,13 @@ public abstract class RazorGeneratorBase
.EnableDebugMode()
.Build();

protected async Task DoRazor<TModel>(TModel model, string viewLocation, string targetLocation, CancellationToken token)
protected static async Task DoRazor<TModel>(TModel model, string viewLocation, string targetLocation, CancellationToken token)
{
try
{
token.ThrowIfCancellationRequested();
var generated = await Engine.CompileRenderAsync(viewLocation, model);
WriteFormattedCsharpFile(targetLocation, generated);
await WriteFormattedCsharpFile(targetLocation, generated);
}
catch (TemplateGenerationException e)
{
Expand All @@ -71,32 +69,28 @@ protected async Task DoRazorDependantFiles<TModel>(
Func<TModel, string> identifier, Func<string, string> target,
CancellationToken token
)
{
using (var c = pbar.Spawn(items.Count, "Generating namespaces", new ProgressBarOptions
{
ProgressCharacter = '─',
ForegroundColor = ConsoleColor.Yellow
}))
{
foreach (var item in items)
{
var id = identifier(item);
var targetLocation = target(id);
await DoRazor(item, viewLocation, targetLocation, token);
c.Tick($"{Title}: {id}");
}
}
}
{
using var c = pbar.Spawn(items.Count, "Generating namespaces", new ProgressBarOptions
{
ProgressCharacter = '─',
ForegroundColor = ConsoleColor.Yellow
});
foreach (var item in items)
{
var id = identifier(item);
var targetLocation = target(id);
await DoRazor(item, viewLocation, targetLocation, token);
c.Tick($"{Title}: {id}");
}
}

protected static void WriteFormattedCsharpFile(string path, string contents)
private static async Task WriteFormattedCsharpFile(string path, string contents)
{
var tree = CSharpSyntaxTree.ParseText(contents);
var root = tree.GetRoot().NormalizeWhitespace(indentation:"\t", "\n");
contents = root.ToFullString();
contents = (await CodeFormatter.FormatAsync(contents)).Code;

if (Directory.GetParent(path) is { Exists: false } dir) dir.Create();

File.WriteAllText(path, contents);
await File.WriteAllTextAsync(path, contents);
}

public abstract string Title { get; }
Expand Down
21,775 changes: 12,216 additions & 9,559 deletions src/ApiGenerator/OpenSearch.openapi.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenSearch.Client.@(CsharpNames.ApiNamespace).@ns@(CsharpNames.ApiName
/// on <see cref="IOpenSearchClient"/>.
///</para>
///</summary>
public class @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
public partial class @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
{
internal @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix)(OpenSearchClient client) : base(client) {}
@foreach(var e in endpoints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using OpenSearch.Net.Utf8Json;
// ReSharper disable UnusedTypeParameter
// ReSharper disable PartialMethodWithSinglePart
// ReSharper disable RedundantNameQualifier
namespace OpenSearch.Client
namespace OpenSearch.Client@(ns)
{
@foreach (var endpoint in endpoints)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ApiGenerator/Views/HighLevel/Requests/Requests.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using OpenSearch.Net.Utf8Json;
// ReSharper disable UnusedTypeParameter
// ReSharper disable PartialMethodWithSinglePart
// ReSharper disable RedundantNameQualifier
namespace OpenSearch.Client
namespace OpenSearch.Client@(ns)
{
@foreach (var endpoint in endpoints)
{
Expand Down
3 changes: 0 additions & 3 deletions src/OpenSearch.Client/ApiUrlsLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ internal static partial class ApiUrlsLookups
internal static ApiUrls SnapshotRestore = new ApiUrls(new[]{"_snapshot/{repository}/{snapshot}/_restore"});
internal static ApiUrls SnapshotStatus = new ApiUrls(new[]{"_snapshot/_status", "_snapshot/{repository}/_status", "_snapshot/{repository}/{snapshot}/_status"});
internal static ApiUrls SnapshotVerifyRepository = new ApiUrls(new[]{"_snapshot/{repository}/_verify"});
internal static ApiUrls TasksCancel = new ApiUrls(new[]{"_tasks/_cancel", "_tasks/{task_id}/_cancel"});
internal static ApiUrls TasksGetTask = new ApiUrls(new[]{"_tasks/{task_id}"});
internal static ApiUrls TasksList = new ApiUrls(new[]{"_tasks"});
internal static ApiUrls NoNamespaceTermVectors = new ApiUrls(new[]{"{index}/_termvectors/{id}", "{index}/_termvectors"});
internal static ApiUrls NoNamespaceUpdate = new ApiUrls(new[]{"{index}/_update/{id}"});
internal static ApiUrls NoNamespaceUpdateByQuery = new ApiUrls(new[]{"{index}/_update_by_query"});
Expand Down
136 changes: 0 additions & 136 deletions src/OpenSearch.Client/Descriptors.Tasks.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/OpenSearch.Client/IOpenSearchClient.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,11 +1042,5 @@ SnapshotNamespace Snapshot
{
get;
}

///<summary>Tasks APIs</summary>
TasksNamespace Tasks
{
get;
}
}
}
8 changes: 0 additions & 8 deletions src/OpenSearch.Client/OpenSearchClient.NoNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ public SnapshotNamespace Snapshot
private set;
}

///<summary>Tasks APIs</summary>
public TasksNamespace Tasks
{
get;
private set;
}

partial void SetupNamespaces()
{
Cat = new CatNamespace(this);
Expand All @@ -128,7 +121,6 @@ partial void SetupNamespaces()
Ingest = new IngestNamespace(this);
Nodes = new NodesNamespace(this);
Snapshot = new SnapshotNamespace(this);
Tasks = new TasksNamespace(this);
}

/// <summary>
Expand Down
Loading

0 comments on commit 65ac116

Please sign in to comment.