Skip to content

Commit

Permalink
Re-generate dangling_indices namespace (#333)
Browse files Browse the repository at this point in the history
* Correct handling of deprecated parameters

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Re-generate `dangling_indices` namespace

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Add remarks about when cluster_manager_timeout is supported

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Delete missed old file

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

---------

Signed-off-by: Thomas Farr <tsfarr@amazon.com>
  • Loading branch information
Xtansia committed Aug 28, 2023
1 parent b6d7b9d commit 2521af9
Show file tree
Hide file tree
Showing 30 changed files with 1,171 additions and 854 deletions.
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("dangling_indices.*"),
new("tasks.*")
};

Expand Down
6 changes: 4 additions & 2 deletions src/ApiGenerator/Domain/Specification/QueryParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class QueryParameters

public string Description { get; set; }

public string VersionAdded { get; set; }

public IEnumerable<string> DescriptionHighLevel
{
get
Expand Down Expand Up @@ -191,8 +193,8 @@ public string TypeLowLevel
}


public string InitializerGenerator(string @namespace, string type, string name, string key, string setter, params string[] doc) =>
CodeGenerator.Property(@namespace, type, name, key, setter, Obsolete, doc);
public string InitializerGenerator(string @namespace, string type, string name, string key, string setter, string versionAdded, params string[] doc) =>
CodeGenerator.Property(@namespace, type, name, key, setter, Obsolete, versionAdded, doc);
}

public class QueryParameterDeprecation
Expand Down
13 changes: 12 additions & 1 deletion src/ApiGenerator/Generator/ApiEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public static ApiEndpoint From(string name, List<(string HttpPath, OpenApiPathIt
Type = GetOpenSearchType(p.Schema),
Description = p.Description,
Options = GetEnumOptions(p.Schema),
Deprecated = p.IsDeprecated ? new QueryParameterDeprecation { Description = p.DeprecatedMessage } : null
Deprecated = GetDeprecation(p.Schema),
VersionAdded = p.Schema.GetExtension("x-version-added") as string,
});

var endpoint = new ApiEndpoint
Expand Down Expand Up @@ -159,6 +160,16 @@ private static IEnumerable<string> GetEnumOptions(JsonSchema schema)
return schema.Enumeration?.Select(e => e.ToString()) ?? Enumerable.Empty<string>();
}

private static QueryParameterDeprecation GetDeprecation(IJsonExtensionObject schema)
{
var message = schema.GetExtension("x-deprecation-message") as string;
var version = schema.GetExtension("x-version-deprecated") as string;

return message != null || version != null
? new QueryParameterDeprecation { Description = message, Version = version }
: null;
}

private static object GetExtension(this IJsonExtensionObject schema, string key) =>
schema.ExtensionData?.TryGetValue(key, out var value) ?? false ? value : null;
}
Expand Down
5 changes: 3 additions & 2 deletions src/ApiGenerator/Generator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ public static string CatFormatPropertyGenerator(string type, string name, string
public static string PropertyGenerator(string type, string name, string key, string setter) =>
$"public {type} {name} {{ get => Q<{type}>(\"{key}\"); set => Q(\"{key}\", {setter}); }}";

public static string Property(string @namespace, string type, string name, string key, string setter, string obsolete, params string[] doc)
public static string Property(string @namespace, string type, string name, string key, string setter, string obsolete, string versionAdded, params string[] doc)
{
var components = new List<string>();
foreach (var d in RenderDocumentation(doc)) A(d);
if (!string.IsNullOrWhiteSpace(obsolete)) A($"[Obsolete(\"Scheduled to be removed in 8.0, {obsolete}\")]");
if (!string.IsNullOrWhiteSpace(versionAdded)) A($"///<remarks>Supported by OpenSearch servers of version {versionAdded} or greater.</remarks>");
if (!string.IsNullOrWhiteSpace(obsolete)) A($"[Obsolete(\"{obsolete}\")]");

var generated = @namespace != null && @namespace == "Cat" && name == "Format"
? CatFormatPropertyGenerator(type, name, key, setter)
Expand Down
318 changes: 212 additions & 106 deletions src/ApiGenerator/OpenSearch.openapi.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/ApiGenerator/Views/HighLevel/Descriptors/Descriptor.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@
var desc = param.DescriptionHighLevel.ToList();

await IncludeAsync("HighLevel/Descriptors/XmlDocs.cshtml", desc);
if(!string.IsNullOrWhiteSpace(param.Obsolete))

if (!string.IsNullOrWhiteSpace(param.VersionAdded))
{
<text>
///<remarks>Supported by OpenSearch servers of version @(param.VersionAdded) or greater.</remarks></text>
}

if(!string.IsNullOrWhiteSpace(param.Obsolete))
{
<text>
[Obsolete("Scheduled to be removed in 8.0, @param.Obsolete")]
[Obsolete("@Raw(param.Obsolete)")]
</text>
}
<text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace OpenSearch.Client
var propertyName = $"{endpoint.CsharpNames.Namespace}{endpoint.CsharpNames.MethodName}";
var paths = endpoint.Url.Paths.Count == 0 ? endpoint.Url.PathsWithDeprecations : endpoint.Url.Paths;
<text>
internal static ApiUrls @(Raw(propertyName)) = new ApiUrls(new [] {@Raw(string.Join(", ", paths.Select(p=>$"\"{p.Path.TrimStart('/')}\"")))});
internal static ApiUrls @(Raw(propertyName)) = new(new [] {@Raw(string.Join(", ", paths.Select(p=>$"\"{p.Path.TrimStart('/')}\"")))});
</text>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
continue;
}
var doc = param.DescriptionHighLevel.ToArray();
@Raw(param.InitializerGenerator(Model.CsharpNames.Namespace, param.TypeHighLevel, param.ClsName, original, param.SetterHighLevel, doc))
@Raw(param.InitializerGenerator(Model.CsharpNames.Namespace, param.TypeHighLevel, param.ClsName, original, param.SetterHighLevel, param.VersionAdded, doc))
}
@if (Model.CsharpNames.DescriptorNotFoundInCodebase)
{<text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace OpenSearch.Net@(ns)
public override bool SupportsBody => @(supportsBody ? "true" : "false");
@foreach (var param in r.Params)
{
<text> @Raw(param.InitializerGenerator(r.CsharpNames.Namespace, param.TypeLowLevel, param.ClsName, param.QueryStringKey, param.SetterLowLevel, param.Description))
<text> @Raw(param.InitializerGenerator(r.CsharpNames.Namespace, param.TypeLowLevel, param.ClsName, param.QueryStringKey, param.SetterLowLevel, param.VersionAdded, param.Description))
</text>
}
}</text>
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 @@ -83,9 +83,6 @@ internal static partial class ApiUrlsLookups
internal static ApiUrls ClusterStats = new ApiUrls(new[]{"_cluster/stats", "_cluster/stats/nodes/{node_id}"});
internal static ApiUrls NoNamespaceCount = new ApiUrls(new[]{"_count", "{index}/_count"});
internal static ApiUrls NoNamespaceCreate = new ApiUrls(new[]{"{index}/_create/{id}"});
internal static ApiUrls DanglingIndicesDeleteDanglingIndex = new ApiUrls(new[]{"_dangling/{index_uuid}"});
internal static ApiUrls DanglingIndicesImportDanglingIndex = new ApiUrls(new[]{"_dangling/{index_uuid}"});
internal static ApiUrls DanglingIndicesList = new ApiUrls(new[]{"_dangling"});
internal static ApiUrls NoNamespaceDelete = new ApiUrls(new[]{"{index}/_doc/{id}"});
internal static ApiUrls NoNamespaceDeleteByQuery = new ApiUrls(new[]{"{index}/_delete_by_query"});
internal static ApiUrls NoNamespaceDeleteByQueryRethrottle = new ApiUrls(new[]{"_delete_by_query/{task_id}/_rethrottle"});
Expand Down
129 changes: 0 additions & 129 deletions src/OpenSearch.Client/Descriptors.DanglingIndices.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 @@ -76,12 +76,6 @@ ClusterNamespace Cluster
get;
}

///<summary>Dangling Indices APIs</summary>
DanglingIndicesNamespace DanglingIndices
{
get;
}

///<summary>Indices APIs</summary>
IndicesNamespace Indices
{
Expand Down
Loading

0 comments on commit 2521af9

Please sign in to comment.