Skip to content

Fix #3316 allow generated enum members to be obsoleted #3369

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

Merged
merged 1 commit into from
Aug 20, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class EndpointOverridesBase: IEndpointOverrides

public virtual IDictionary<string, string> ObsoleteQueryStringParams { get; set; } = new Dictionary<string, string>();


public virtual CsharpMethod PatchMethod(CsharpMethod method) => method;
}
}
6 changes: 6 additions & 0 deletions src/CodeGeneration/ApiGenerator/Overrides/GlobalOverrides.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using ApiGenerator.Overrides.Descriptors;

Expand All @@ -11,6 +12,11 @@ public class GlobalOverrides : EndpointOverridesBase
"script_fields",
"docvalue_fields"
};
public IDictionary<string, Dictionary<string, string>> ObsoleteEnumMembers { get; set; } = new Dictionary<string, Dictionary<string, string>>
{
{ "NodesStatsIndexMetric", new Dictionary<string, string>{{"suggest", "As of 5.0 this option always returned an empty object in the response"}}},
{ "IndicesStatsMetric", new Dictionary<string, string>{{"suggest", "Suggest stats have folded under the search stats, this alias will be removed"}}}
};

public override IDictionary<string, string> RenameQueryStringParams { get; } = new Dictionary<string, string>
{
Expand Down
9 changes: 8 additions & 1 deletion src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
@using System.Linq
@using ApiGenerator.Domain
@using ApiGenerator
@using ApiGenerator.Overrides
@functions {
private const string RawSize = "Raw";
private const string SizeEnum = "Size";
private static GlobalOverrides GlobalOverrides = new GlobalOverrides();

private string CreateEnum(string enumName, string value, int? i)
{
var enumValue = (enumName == SizeEnum && value == string.Empty) ? RawSize : value.ToPascalCase(true);
return string.Format("[EnumMember(Value = \"{0}\")] {1}{2}", value, enumValue, i.HasValue ? " = 1 << " + i.Value : null);
var enumCsharp = string.Format("[EnumMember(Value = \"{0}\")] {1}{2}", value, enumValue, i.HasValue ? " = 1 << " + i.Value : null);
if (GlobalOverrides.ObsoleteEnumMembers.TryGetValue(enumName, out var d) && d.TryGetValue(value, out var obsolete))
{
return string.Format("[Obsolete(\"{0}\")]\r\n\t\t{1}", obsolete, enumCsharp);
}
return enumCsharp;
}
private string CreateCase(string e, string o)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Elasticsearch.Net/Domain/Enums.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ [Flags]public enum IndicesStatsMetric
[EnumMember(Value = "segments")] Segments = 1 << 11,
[EnumMember(Value = "store")] Store = 1 << 12,
[EnumMember(Value = "warmer")] Warmer = 1 << 13,
[Obsolete("Suggest stats have folded under the search stats, this alias will be removed")]
[EnumMember(Value = "suggest")] Suggest = 1 << 14,
[EnumMember(Value = "_all")] All = 1 << 15
}
Expand Down Expand Up @@ -197,6 +198,7 @@ [Flags]public enum NodesStatsIndexMetric
[EnumMember(Value = "segments")] Segments = 1 << 11,
[EnumMember(Value = "store")] Store = 1 << 12,
[EnumMember(Value = "warmer")] Warmer = 1 << 13,
[Obsolete("As of 5.0 this option always returned an empty object in the response")]
[EnumMember(Value = "suggest")] Suggest = 1 << 14,
[EnumMember(Value = "_all")] All = 1 << 15
}
Expand Down