Skip to content

Commit

Permalink
Fix codegen (#860)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Nov 25, 2024
1 parent 274e12b commit cb4eaa7
Show file tree
Hide file tree
Showing 65 changed files with 21,717 additions and 17,424 deletions.
2 changes: 1 addition & 1 deletion src/ApiGenerator/Domain/Code/CsharpNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public string GenericOrNonGenericResponseName

public static string GetEnumName(string schemaKey)
{
var enumName = schemaKey.Replace("_common", "").SplitPascalCase().ToPascalCase();
var enumName = schemaKey.Replace("_common", "").Replace("___", " ").SplitPascalCase().ToPascalCase();
if (GlobalOverrides.Instance.RenameEnums.TryGetValue(enumName, out var renamed)) enumName = renamed;
return enumName;
}
Expand Down
10 changes: 8 additions & 2 deletions src/ApiGenerator/Generator/ApiEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ private static string GetOpenSearchType(JsonSchema schema, Action<string, bool>

if (oneOf.Length != 2) throw new Exception("Unable to determine type of oneOf");

if (oneOf[0].Type == JsonObjectType.Boolean && oneOf[1].IsEnum())
{
trackEnumToGenerate(schemaKey, isListContext);
return CsharpNames.GetEnumName(schemaKey) + "?";
}

var first = GetOpenSearchType(oneOf[0], trackEnumToGenerate);
var second = GetOpenSearchType(oneOf[1], trackEnumToGenerate);
if (first.EndsWith("?")) return first;
Expand All @@ -256,7 +262,7 @@ private static string GetOpenSearchType(JsonSchema schema, Action<string, bool>
_ = GetOpenSearchType(schema.Item, trackEnumToGenerate, true);

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

var type = types.Count switch
Expand All @@ -271,7 +277,7 @@ 2 when types.Contains(JsonObjectType.Boolean) && types.Contains(JsonObjectType.S
{
JsonObjectType.Integer => "number",
JsonObjectType.Array => "list",
JsonObjectType.String when schema.Pattern == @"^([0-9\.]+)(?:d|h|m|s|ms|micros|nanos)$" => "time",
JsonObjectType.String when schema.Pattern == @"^(?:(-1)|([0-9\.]+)(?:d|h|m|s|ms|micros|nanos))$" => "time",
var t => t.ToString().ToLowerInvariant()
};
}
Expand Down
34,529 changes: 18,453 additions & 16,076 deletions src/ApiGenerator/opensearch-openapi.yaml

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,14 @@ internal static partial class ApiUrlsLookups
new(["_cluster/state", "_cluster/state/{metric}", "_cluster/state/{metric}/{index}"]);

internal static readonly ApiUrls ClusterStats =
new(["_cluster/stats", "_cluster/stats/nodes/{node_id}"]);
new(
[
"_cluster/stats",
"_cluster/stats/{metric}/{index_metric}/nodes/{node_id}",
"_cluster/stats/{metric}/nodes/{node_id}",
"_cluster/stats/nodes/{node_id}",
]
);

internal static readonly ApiUrls NoNamespaceCount = new(["_count", "{index}/_count"]);

Expand Down
130 changes: 65 additions & 65 deletions src/OpenSearch.Client/_Generated/Descriptors.Cat.cs

Large diffs are not rendered by default.

112 changes: 70 additions & 42 deletions src/OpenSearch.Client/_Generated/Descriptors.Cluster.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public DeleteDanglingIndexDescriptor AcceptDataLoss(bool? acceptdataloss = true)
public DeleteDanglingIndexDescriptor ClusterManagerTimeout(Time clustermanagertimeout) =>
Qs("cluster_manager_timeout", clustermanagertimeout);

/// <summary>Specify timeout for connection to master.</summary>
/// <summary>Specify timeout for connection to cluster manager.</summary>
[Obsolete(
"Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead."
"Deprecated as of: 2.0.0, reason: To promote inclusive language, use `cluster_manager_timeout` instead."
)]
public DeleteDanglingIndexDescriptor MasterTimeout(Time mastertimeout) =>
Qs("master_timeout", mastertimeout);
Expand Down Expand Up @@ -138,9 +138,9 @@ public ImportDanglingIndexDescriptor AcceptDataLoss(bool? acceptdataloss = true)
public ImportDanglingIndexDescriptor ClusterManagerTimeout(Time clustermanagertimeout) =>
Qs("cluster_manager_timeout", clustermanagertimeout);

/// <summary>Specify timeout for connection to master.</summary>
/// <summary>Specify timeout for connection to cluster manager.</summary>
[Obsolete(
"Deprecated as of: 2.0.0, reason: To promote inclusive language, use 'cluster_manager_timeout' instead."
"Deprecated as of: 2.0.0, reason: To promote inclusive language, use `cluster_manager_timeout` instead."
)]
public ImportDanglingIndexDescriptor MasterTimeout(Time mastertimeout) =>
Qs("master_timeout", mastertimeout);
Expand Down
Loading

0 comments on commit cb4eaa7

Please sign in to comment.