Skip to content

Commit

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

Signed-off-by: Thomas Farr <[email protected]>

* Re-generate `dangling_indices` namespace

Signed-off-by: Thomas Farr <[email protected]>

* Add remarks about when cluster_manager_timeout is supported

Signed-off-by: Thomas Farr <[email protected]>

* Delete missed old file

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Dec 3, 2023
1 parent d4c6a15 commit b80dfe2
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 116 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

0 comments on commit b80dfe2

Please sign in to comment.