Skip to content

Commit

Permalink
Fix #3316 allow generated enum members to be obsoleted (#3369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored and russcam committed Aug 20, 2018
1 parent 40731a9 commit 9211d5d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
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

0 comments on commit 9211d5d

Please sign in to comment.