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

Generate all missing low-level methods #813

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
4 changes: 4 additions & 0 deletions .github/actions/run-released-opensearch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
secured:
description: Whether to enable the security plugin
required: true
opensearch_args:
description: Additional arguments to pass to the OpenSearch process
default: ''
outputs:
opensearch_url:
description: The URL where the OpenSearch node is accessible
Expand Down Expand Up @@ -49,4 +52,5 @@ runs:
id: opensearch
uses: ./client/.github/actions/start-opensearch
with:
opensearch_args: ${{ inputs.opensearch_args }}
secured: ${{ inputs.secured }}
8 changes: 6 additions & 2 deletions .github/actions/start-opensearch/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Start OpenSearch
description: Configures and starts an OpenSearch daemon
inputs:
opensearch_args:
description: Additional arguments to pass to the OpenSearch process
default: ''
secured:
description: Whether to enable the security plugin
default: 'false'
Expand Down Expand Up @@ -74,9 +77,9 @@ runs:
fi

if [[ "$RUNNER_OS" != "Windows" ]]; then
$OPENSEARCH_HOME/bin/opensearch &
$OPENSEARCH_HOME/bin/opensearch ${OPENSEARCH_ARGS} &
else
$OPENSEARCH_HOME/bin/opensearch.bat -d &
$OPENSEARCH_HOME/bin/opensearch.bat ${OPENSEARCH_ARGS} -d &
fi

for attempt in {1..20}; do
Expand All @@ -91,3 +94,4 @@ runs:
env:
SECURED: ${{ inputs.secured }}
RUNNER_OS: ${{ runner.os }}
OPENSEARCH_ARGS: ${{ inputs.opensearch_args }}
1 change: 1 addition & 0 deletions .github/workflows/integration-yaml-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
with:
version: ${{ matrix.version }}
secured: true
opensearch_args: ${{ matrix.version == '2.8.0' && '-Eopensearch.experimental.feature.search_pipeline.enabled=true' || '' }}

- name: Run YAML tests
working-directory: client
Expand Down
11 changes: 2 additions & 9 deletions src/ApiGenerator/Configuration/CodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,10 @@ public static class CodeConfiguration
{
private static readonly Glob[] OperationsToInclude =
[
new("cat.*"),
new("cluster.*"),
new("dangling_indices.*"),
new("indices.*"),
new("ingest.*"),
new("nodes.*"),
new("snapshot.*"),
new("tasks.*")
new("*")
];

public static bool IncludeOperation(string name) => !name.Contains('.') || OperationsToInclude.Any(g => g.IsMatch(name));
public static bool IncludeOperation(string name) => OperationsToInclude.Any(g => g.IsMatch(name));

/// <summary>
/// Map API default names for API's we are only supporting on the low level client first
Expand Down
5 changes: 4 additions & 1 deletion src/ApiGenerator/Domain/Code/CsharpNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ public string PerPathMethodName(string path)
var method = MethodName;
// This is temporary for transition period
// TODO: remove in branch once it in opensearch is scrubbed
if (path.Contains("{type}") && !method.Contains("Type")) method += "UsingType";
if (pc("{type}") && !method.Contains("Type")) method += "UsingType";

if (ms("Indices") && !pc("{index}"))
return (method + "ForAll").Replace("AsyncForAll", "ForAllAsync");

if (ms("Nodes") && !pc("{node_id}"))
return (method + "ForAll").Replace("AsyncForAll", "ForAllAsync");

if (Namespace == "Knn" && method.StartsWith("Stats") && !pc("{node_id}"))
return method.Replace("Stats", "StatsForAll");

return method;
}

Expand Down
29 changes: 22 additions & 7 deletions src/ApiGenerator/Generator/ApiEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,17 @@ private static string GetOpenSearchType(JsonSchema schema, Action<string, bool>
if (first.EndsWith("?")) return first;
if (first == second) return first;

switch (first, second)
return (first, second) switch
{
case ("string", "list"): return second;
case ("boolean", "string"): return first;
case ("number", _): return "string";
case (_,"number"): return "string";
}
(_, "list") => second,
("boolean", "string") => first,
("number", _) => "string",
(_, "number") => "string",
(_, _) => throw new Exception($"Unable to determine type of: {first} and {second}")
};
}

throw new Exception("Unable to determine type of oneOf");
}

var enumOptions = schema.Enumeration.Where(e => e != null).Select(e => e.ToString()).ToList();
Expand All @@ -259,7 +262,19 @@ private static string GetOpenSearchType(JsonSchema schema, Action<string, bool>
if (schema.Type == JsonObjectType.Array && (schema.Item?.HasReference ?? false))
_ = GetOpenSearchType(schema.Item, trackEnumToGenerate, true);

return schema.Type switch
var types = Enum.GetValues<JsonObjectType>()
.Where(t => t != JsonObjectType.None && schema.Type.HasFlag(t))
.ToHashSet();

var type = types.Count switch
{
0 => throw new Exception("No type specified"),
1 => types.First(),
2 when types.Contains(JsonObjectType.Boolean) && types.Contains(JsonObjectType.String) => JsonObjectType.String,
_ => throw new Exception($"Unable to determine type of: {string.Join(", ", types)}")
};

return type switch
{
JsonObjectType.Integer => "number",
JsonObjectType.Array => "list",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
@using ApiGenerator.Domain
@inherits ApiGenerator.CodeTemplatePage<RestApiSpec>
@{ await IncludeLegacyGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using OpenSearch.Net;
using OpenSearch.Net.Utf8Json;
@{ await IncludeAsync("LowLevel/Client/Usings.cshtml", Model);}

// ReSharper disable UnusedTypeParameter
namespace OpenSearch.Client
namespace OpenSearch.Client;

public abstract partial class @Raw("PlainRequestBase<TParameters>")
{
public abstract partial class @Raw("PlainRequestBase<TParameters>")
{
}
}
26 changes: 3 additions & 23 deletions src/OpenSearch.Client/_Generated/Requests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,7 @@
// Windows : build.bat codegen
//
// -----------------------------------------------
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using System.Text;
using OpenSearch.Net;
using OpenSearch.Net.Specification.CatApi;
using OpenSearch.Net.Specification.ClusterApi;
using OpenSearch.Net.Specification.DanglingIndicesApi;
using OpenSearch.Net.Specification.HttpApi;
using OpenSearch.Net.Specification.IndicesApi;
using OpenSearch.Net.Specification.IngestApi;
using OpenSearch.Net.Specification.NodesApi;
using OpenSearch.Net.Specification.SnapshotApi;
using OpenSearch.Net.Specification.TasksApi;
using OpenSearch.Net.Utf8Json;

// ReSharper disable UnusedTypeParameter
namespace OpenSearch.Client
{
public abstract partial class PlainRequestBase<TParameters> { }
}
namespace OpenSearch.Client;

public abstract partial class PlainRequestBase<TParameters> { }
116 changes: 116 additions & 0 deletions src/OpenSearch.Net/_Generated/Api/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,39 @@ public enum IndicesStatsMetric
All = 1 << 17,
}

[StringEnum]
public enum KnnDefaultOperator
{
[EnumMember(Value = "AND")]
And,

[EnumMember(Value = "OR")]
Or,
}

[StringEnum]
public enum KnnSearchType
{
[EnumMember(Value = "dfs_query_then_fetch")]
DfsQueryThenFetch,

[EnumMember(Value = "query_then_fetch")]
QueryThenFetch,
}

[StringEnum]
public enum KnnSuggestMode
{
[EnumMember(Value = "always")]
Always,

[EnumMember(Value = "missing")]
Missing,

[EnumMember(Value = "popular")]
Popular,
}

[StringEnum]
public enum Level
{
Expand Down Expand Up @@ -534,6 +567,37 @@ public enum NodesUsageMetric
All = 1 << 1,
}

[StringEnum]
public enum NotificationsNotificationConfigType
{
[EnumMember(Value = "chime")]
Chime,

[EnumMember(Value = "email")]
Email,

[EnumMember(Value = "email_group")]
EmailGroup,

[EnumMember(Value = "microsoft_teams")]
MicrosoftTeams,

[EnumMember(Value = "ses_account")]
SesAccount,

[EnumMember(Value = "slack")]
Slack,

[EnumMember(Value = "smtp_account")]
SmtpAccount,

[EnumMember(Value = "sns")]
Sns,

[EnumMember(Value = "webhook")]
Webhook,
}

[StringEnum]
public enum OpType
{
Expand Down Expand Up @@ -688,12 +752,16 @@ static partial void RegisterEnumStringResolvers()
AddEnumStringResolver<IndexApiBlock>(GetStringValue);
AddEnumStringResolver<IndicesShardStoresStatus>(GetStringValue);
AddEnumStringResolver<IndicesStatsMetric>(GetStringValue);
AddEnumStringResolver<KnnDefaultOperator>(GetStringValue);
AddEnumStringResolver<KnnSearchType>(GetStringValue);
AddEnumStringResolver<KnnSuggestMode>(GetStringValue);
AddEnumStringResolver<Level>(GetStringValue);
AddEnumStringResolver<NodesInfoMetric>(GetStringValue);
AddEnumStringResolver<NodesSampleType>(GetStringValue);
AddEnumStringResolver<NodesStatsIndexMetric>(GetStringValue);
AddEnumStringResolver<NodesStatsMetric>(GetStringValue);
AddEnumStringResolver<NodesUsageMetric>(GetStringValue);
AddEnumStringResolver<NotificationsNotificationConfigType>(GetStringValue);
AddEnumStringResolver<OpType>(GetStringValue);
AddEnumStringResolver<Refresh>(GetStringValue);
AddEnumStringResolver<SearchType>(GetStringValue);
Expand Down Expand Up @@ -900,6 +968,37 @@ public static string GetStringValue(this IndicesStatsMetric enumValue)
return string.Join(",", list);
}

public static string GetStringValue(this KnnDefaultOperator enumValue) =>
enumValue switch
{
KnnDefaultOperator.And => "AND",
KnnDefaultOperator.Or => "OR",
_ => throw new ArgumentException(
$"'{enumValue.ToString()}' is not a valid value for enum 'KnnDefaultOperator'"
),
};

public static string GetStringValue(this KnnSearchType enumValue) =>
enumValue switch
{
KnnSearchType.DfsQueryThenFetch => "dfs_query_then_fetch",
KnnSearchType.QueryThenFetch => "query_then_fetch",
_ => throw new ArgumentException(
$"'{enumValue.ToString()}' is not a valid value for enum 'KnnSearchType'"
),
};

public static string GetStringValue(this KnnSuggestMode enumValue) =>
enumValue switch
{
KnnSuggestMode.Always => "always",
KnnSuggestMode.Missing => "missing",
KnnSuggestMode.Popular => "popular",
_ => throw new ArgumentException(
$"'{enumValue.ToString()}' is not a valid value for enum 'KnnSuggestMode'"
),
};

public static string GetStringValue(this Level enumValue) =>
enumValue switch
{
Expand Down Expand Up @@ -1068,6 +1167,23 @@ public static string GetStringValue(this NodesUsageMetric enumValue)
return string.Join(",", list);
}

public static string GetStringValue(this NotificationsNotificationConfigType enumValue) =>
enumValue switch
{
NotificationsNotificationConfigType.Chime => "chime",
NotificationsNotificationConfigType.Email => "email",
NotificationsNotificationConfigType.EmailGroup => "email_group",
NotificationsNotificationConfigType.MicrosoftTeams => "microsoft_teams",
NotificationsNotificationConfigType.SesAccount => "ses_account",
NotificationsNotificationConfigType.Slack => "slack",
NotificationsNotificationConfigType.SmtpAccount => "smtp_account",
NotificationsNotificationConfigType.Sns => "sns",
NotificationsNotificationConfigType.Webhook => "webhook",
_ => throw new ArgumentException(
$"'{enumValue.ToString()}' is not a valid value for enum 'NotificationsNotificationConfigType'"
),
};

public static string GetStringValue(this OpType enumValue) =>
enumValue switch
{
Expand Down
Loading
Loading