Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-generate the tasks namespace #320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 8 additions & 14 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This await is new, is it ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are in the code generator, it is because I changed the WriteFormattedCsharpFile method to be async, as I changed the formatter and from sync file write to async file write.

I can split these changes to the code generator out into a seperate PR if you like

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, I just want to make sure there's no negative end-user impact.

}
catch (TemplateGenerationException e)
{
Expand All @@ -72,12 +70,11 @@ protected async Task DoRazorDependantFiles<TModel>(
CancellationToken token
)
{
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
using (var c = pbar.Spawn(items.Count, "Generating namespaces", new ProgressBarOptions
using var c = pbar.Spawn(items.Count, "Generating namespaces", new ProgressBarOptions
{
ProgressCharacter = '─',
ForegroundColor = ConsoleColor.Yellow
}))
{
});
foreach (var item in items)
{
var id = identifier(item);
Expand All @@ -86,17 +83,14 @@ CancellationToken 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
3,705 changes: 3,181 additions & 524 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
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"});
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
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
Loading