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

[Backport 1.x] Code generation updates #755

Merged
merged 11 commits into from
Aug 17, 2024
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
20 changes: 4 additions & 16 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,19 @@ root=true
[*]
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 4
insert_final_newline=true

[*.cs]
trim_trailing_whitespace=true

[*.cshtml]
indent_style = tab
indent_size = 4

[*.{fs,fsx}]
indent_style = space
indent_size = 4
insert_final_newline=true

[*.yml]
indent_style = space
indent_size = 2

[*.{md,markdown,json,js,csproj,fsproj,targets,targets,props}]
indent_style = space
[*.{md,markdown,json,js,csproj,fsproj,targets,props}]
indent_size = 2

# Dotnet code style settings:
[*.{cs,vb}]
trim_trailing_whitespace = true

# ---
# naming conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions
Expand Down Expand Up @@ -171,7 +159,7 @@ csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
# just a suggestion do to our JSON tests that use anonymous types to
# just a suggestion do to our JSON tests that use anonymous types to
# represent json quite a bit (makes copy paste easier).
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
restore-keys: |
${{ runner.os }}-nuget-

- run: "./build.sh integrate ${{ matrix.version }} readonly,writable random:test_only_one --report"
- run: "./build.sh integrate ${{ matrix.version }} readonly,replicatedreadonly,writable random:test_only_one --report"
name: Integration Tests
working-directory: client

Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
knn_plugin: true
plugins_output_directory: ${{ env.OPENSEARCH_PLUGINS_DIRECTORY }}

- run: "./build.sh integrate $OPENSEARCH_VERSION readonly,writable random:test_only_one --report"
- run: "./build.sh integrate $OPENSEARCH_VERSION readonly,replicatedreadonly,writable random:test_only_one --report"
name: Integration Tests
working-directory: client
env:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]
### Added
- Added support for the `Cat.PitSegments` and `Cat.SegmentReplication` APIs ([#527](https://github.com/opensearch-project/opensearch-net/pull/527))
- Added support for `MinScore` on `ScriptScoreQuery` ([#624](https://github.com/opensearch-project/opensearch-net/pull/624))
- Added support for serializing the `DateOnly` and `TimeOnly` types ([#734](https://github.com/opensearch-project/opensearch-net/pull/734))
- Added support for the `Ext` parameter on `SearchRequest` ([#738](https://github.com/opensearch-project/opensearch-net/pull/738))
- Added support for the `Indices.Stats` API ([#753](https://github.com/opensearch-project/opensearch-net/pull/753))

### Dependencies
- Bumps `AWSSDK.Core` from 3.7.204.12 to 3.7.400.4
Expand All @@ -21,6 +23,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Bumps `Octokit` from 11.0.0 to 13.0.1
- Bumps `System.Reactive` from 6.0.0 to 6.0.1
- Bumps `Argu` from 6.2.3 to 6.2.4
- Bumps `YamlDotNet` from 15.1.2 to 16.0.0
- Bumps `NSwag.Core` from 14.0.7 to 14.1.0
- Bumps `System.Text.Json` from 8.0.3 to 8.0.4
- Bumps `JetBrains.Annotations` from 2023.3.0 to 2024.2.0
- Bumps `JunitXml.TestLogger` from 3.1.12 to 4.0.254
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ public IDisposable Start(IConsoleLineHandler writer, TimeSpan waitForStarted)
OnBeforeStart();

var subscriptions = new Subscriptions();
foreach (var node in Nodes) subscriptions.Add(node.SubscribeLines(writer));

var waitHandles = Nodes.Select(w => w.StartedHandle).ToArray();
if (!WaitHandle.WaitAll(waitHandles, waitForStarted))
foreach (var node in Nodes)
{
subscriptions.Add(node.SubscribeLines(writer));
if (node.WaitForStarted(waitForStarted)) continue;

var nodeExceptions = Nodes.Select(n => n.LastSeenException).Where(e => e != null).ToList();
writer?.WriteError(
$"{{{GetType().Name}.{nameof(Start)}}} cluster did not start after {waitForStarted}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ private static StartArguments StartArgs(NodeConfiguration config)

private static Dictionary<string, string> EnvVars(NodeConfiguration config)
{
var environmentVariables = new Dictionary<string, string> { { "OPENSEARCH_JAVA_OPTS", "-Xms1g -Xmx1g" } };
var javaOpts = new List<string> { "-Xms1g", "-Xmx1g" };

var environmentVariables = new Dictionary<string, string> { { "OPENSEARCH_JAVA_OPTS", string.Join(" ", javaOpts) } };

if (!string.IsNullOrWhiteSpace(config.FileSystem.ConfigPath))
environmentVariables.Add(config.FileSystem.ConfigEnvironmentVariableName, config.FileSystem.ConfigPath);

Expand Down
6 changes: 4 additions & 2 deletions build/scripts/scripts.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@
<Content Include="..\..\.github\license-header-fs.txt"><Link>license-header-fs.txt</Link></Content>
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="8.0.301" />

<PackageReference Include="Bullseye" Version="5.0.0" />
<ProjectReference Include="$(SolutionRoot)\abstractions\src\OpenSearch.OpenSearch.Managed\OpenSearch.OpenSearch.Managed.csproj" />

<PackageReference Include="Fake.Core.Environment" Version="6.1.0" />
<PackageReference Include="Fake.Core.SemVer" Version="6.1.0" />
<PackageReference Include="Fake.IO.FileSystem" Version="6.1.0" />
<PackageReference Include="Fake.IO.Zip" Version="6.1.0" />
<PackageReference Include="Fake.Tools.Git" Version="5.23.1" />

<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

<PackageReference Include="Octokit" Version="13.0.1" />
Expand Down
5 changes: 3 additions & 2 deletions src/ApiGenerator/ApiGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>

<NoWarn>CS1591;NU1701</NoWarn>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSharpier.Core" Version="0.28.2" />
<PackageReference Include="Glob" Version="1.1.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NSwag.Core.Yaml" Version="14.0.7" />
<PackageReference Include="NSwag.Core" Version="14.1.0" />
<PackageReference Include="YamlDotNet" Version="16.0.0" />
<PackageReference Include="SemanticVersioning" Version="2.0.2" />
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
Expand Down
6 changes: 4 additions & 2 deletions src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public static class CodeConfiguration
{
new("{create,delete}_pit"),
new("{delete,get}_all_pits"),

new("cat.{all_pit,pit}_segments"),
new("cat.segment_replication"),
new("cluster.{delete,exists,get,put}_component_template"),
new("indices.{delete,exists,get,put}_index_template")
new("indices.{delete,exists,get,put}_index_template"),
new("indices.stats")
};

public static bool IncludeOperation(string name) => OperationsToInclude.Any(g => g.IsMatch(name));
Expand Down
50 changes: 24 additions & 26 deletions src/ApiGenerator/Configuration/GeneratorLocations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,42 @@

namespace ApiGenerator.Configuration
{
public static class GeneratorLocations
{
// @formatter:off — disable formatter after this line
public static string OpenApiSpecFile { get; } = $@"{Root}OpenSearch.openapi.json";
public static class GeneratorLocations
{
public static string OpenApiSpecFile { get; } = $"{Root}opensearch-openapi.yaml";

public static string OpenSearchNetFolder { get; } = $@"{Root}../../src/OpenSearch.Net/";
public static string OpenSearchNetFolder { get; } = $"{Root}../../src/OpenSearch.Net/";

public static string OpenSearchClientFolder { get; } = $@"{Root}../../src/OpenSearch.Client/";
public static string OpenSearchClientFolder { get; } = $"{Root}../../src/OpenSearch.Client/";

public static string LowLevelGeneratedFolder { get; } = $"{OpenSearchNetFolder}_Generated/";

public static string HighLevelGeneratedFolder { get; } = $"{OpenSearchClientFolder}_Generated/";

// @formatter:on — enable formatter after this line
public static string HighLevel(params string[] paths) => HighLevelGeneratedFolder + string.Join("/", paths);

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

public static readonly Assembly Assembly = typeof(Generator.ApiGenerator).Assembly;
public static readonly Assembly Assembly = typeof(Generator.ApiGenerator).Assembly;

private static string _root;
public static string Root
{
get
{
if (_root != null) return _root;
private static string _root;

var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
public static string Root
{
get
{
if (_root != null) return _root;

var dotnetRun =
directoryInfo.Name == "ApiGenerator" &&
directoryInfo.Parent != null &&
directoryInfo.Parent.Name == "src";
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());

_root = dotnetRun ? "" : @"../../../";
return _root;
}
}
var dotnetRun =
directoryInfo.Name == "ApiGenerator" &&
directoryInfo.Parent != null &&
directoryInfo.Parent.Name == "src";

}
_root = dotnetRun ? "" : "../../../";
return _root;
}
}
}
}

This file was deleted.

8 changes: 4 additions & 4 deletions src/ApiGenerator/Configuration/Overrides/GlobalOverrides.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public class GlobalOverrides : EndpointOverridesBase

private GlobalOverrides() { }

public IDictionary<string, Dictionary<string, string>> ObsoleteEnumMembers { get; set; } = new Dictionary<string, Dictionary<string, string>>()
{
{ "VersionType", new Dictionary<string, string>() { { "force", "Force is no longer accepted by the server as of 7.5.0 and will result in an error when used" } } }
};
public IDictionary<string, string> RenameEnums { get; } = new Dictionary<string, string>
{
{ "ExpandWildcard", "ExpandWildcards" }
};

public override IDictionary<string, string> ObsoleteQueryStringParams { get; set; } = new Dictionary<string, string>
{
Expand Down
12 changes: 1 addition & 11 deletions src/ApiGenerator/Domain/ApiRequestParametersPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,7 @@ private static string CreateCSharpName(string queryStringKey, string endpointNam
if (queryStringKey == "format" && endpointName == "text_structure.find_structure")
return "TextStructureFindStructureFormat";

var cased = queryStringKey.ToPascalCase();
switch (cased)
{
case "Type":
case "Index":
case "Source":
case "Script":
return cased + "QueryString";
default:
return cased;
}
return queryStringKey.ToPascalCase();
}

private static IList<string> CreateSkipList(IEndpointOverrides local, ICollection<string> declaredKeys) =>
Expand Down
9 changes: 9 additions & 0 deletions src/ApiGenerator/Domain/Code/CsharpNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Collections.Generic;
using System.Linq;
using ApiGenerator.Configuration;
using ApiGenerator.Configuration.Overrides;
using ApiGenerator.Generator;

namespace ApiGenerator.Domain.Code
Expand Down Expand Up @@ -103,6 +104,7 @@ public string ResponseName
public const string LowLevelClientNamespacePrefix = "LowLevel";
public const string HighLevelClientNamespacePrefix = "";
public const string ClientNamespaceSuffix = "Namespace";

private static string CreateCSharpNamespace(string endpointNamespace)
{
switch (endpointNamespace)
Expand Down Expand Up @@ -203,5 +205,12 @@ public string GenericOrNonGenericResponseName
: RequestName;

public bool CustomResponseBuilderPerRequestOverride(out string call) => CodeConfiguration.ResponseBuilderInClientCalls.TryGetValue(RequestName, out call);

public static string GetEnumName(string schemaKey)
{
var enumName = schemaKey.Replace("_common", "").SplitPascalCase().ToPascalCase();
if (GlobalOverrides.Instance.RenameEnums.TryGetValue(enumName, out var renamed)) enumName = renamed;
return enumName;
}
}
}
45 changes: 2 additions & 43 deletions src/ApiGenerator/Domain/RestApiSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace ApiGenerator.Domain
public class EnumDescription
{
public string Name { get; set; }
public bool IsFlag { get; set; }
public IEnumerable<string> Options { get; set; }
}

Expand All @@ -55,48 +56,6 @@ public class RestApiSpec
.GroupBy(e => e.CsharpNames.Namespace)
.ToImmutableSortedDictionary(kv => kv.Key, kv => kv.ToList().AsReadOnly());


private IEnumerable<EnumDescription> _enumDescriptions;
public IEnumerable<EnumDescription> EnumsInTheSpec
{
get
{
if (_enumDescriptions != null) return _enumDescriptions;

var urlParameterEnums = Endpoints
.Values
.SelectMany(e => e.Url.Params.Values)
.Where(p => !p.Skip && p.Options != null && p.Options.Any())
.Select(p => new EnumDescription
{
Name = p.ClsName,
Options = p.Options
})
.ToList();

var urlPartEnums = Endpoints
.Values
.SelectMany(e => e.Url.Parts, (e, part) => new { e, part })
.Where(p => p.part.Options != null && p.part.Options.Any())
.Select(p =>
{
var ns = p.e.CsharpNames.Namespace;
var m = p.e.CsharpNames.MethodName;
return new EnumDescription
{
Name = (!m.StartsWith(ns) ? ns : string.Empty) + m + p.part.Name.ToPascalCase(),
Options = p.part.Options
};
}).
ToList();

_enumDescriptions = urlPartEnums
.Concat(urlParameterEnums)
.DistinctBy(e => e.Name)
.ToList();

return _enumDescriptions;
}
}
public ImmutableList<EnumDescription> EnumsInTheSpec { get; set; }
}
}
Loading
Loading