Skip to content

Commit a9b2fb1

Browse files
authored
Clear up Name and Id parameters (#3810)
1 parent 2ced72f commit a9b2fb1

File tree

25 files changed

+213
-366
lines changed

25 files changed

+213
-366
lines changed

src/CodeGeneration/ApiGenerator/Domain/Specification/UrlPart.cs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Transactions;
23

34
namespace ApiGenerator.Domain.Specification
45
{
@@ -36,49 +37,56 @@ public string ClrTypeName
3637

3738
switch (Name)
3839
{
40+
case "category_id": return "LongId";
41+
case "timestamp": return "Timestamp";
42+
case "index_metric": return "IndexMetrics";
43+
case "metric": return "Metrics";
44+
45+
case "node_id" when Type == "list":
46+
return "NodeIds";
47+
48+
case "fields" when Type == "list":
49+
return "Fields";
50+
51+
case "parent_task_id":
52+
case "task_id":
53+
return "TaskId";
54+
55+
case "forecast_id":
56+
case "action_id":
57+
return "Ids";
58+
3959
case "index":
4060
case "new_index":
61+
case "target":
4162
return Type == "string" ? "IndexName" : "Indices";
42-
case "target":
43-
return "IndexName";
44-
case "type": return Type == "string" ? "Name" : "Names";
63+
4564
case "watch_id":
4665
case "job_id":
4766
case "calendar_id":
4867
case "event_id":
4968
case "datafeed_id":
5069
case "snapshot_id":
5170
case "filter_id":
52-
case "id": return Type == "string" ? "Id" : "Ids";
53-
case "category_id": return "CategoryId";
54-
case "policy_id": return "PolicyId";
55-
case "forecast_id": return "ForecastIds";
56-
case "nodes":
57-
case "node_id": return Type == "string" ? "NodeId" : "NodeIds";
58-
case "field":
59-
case "fields": return Type == "string" ? "Field" : "Fields";
60-
case "index_metric": return "IndexMetrics";
61-
case "metric":
62-
return "Metrics";
63-
case "feature": return "Features";
64-
case "action_id": return "ActionIds";
71+
case "policy_id":
72+
case "id":
73+
return "Id";
74+
6575
case "application":
6676
case "repository":
6777
case "snapshot":
68-
case "lang":
78+
case "user":
6979
case "username":
70-
case "usernames":
71-
case "realm":
7280
case "realms":
7381
case "alias":
7482
case "context":
7583
case "name":
76-
case "user":
7784
case "thread_pool_patterns":
85+
case "type":
7886
return Type == "string" ? "Name" : "Names";
79-
case "parent_task_id":
80-
case "task_id": return "TaskId";
81-
case "timestamp": return "Timestamp";
87+
88+
89+
//This forces a compilation error post code generation as intended
8290
default: return Type + "_";
8391
}
8492
}

src/Elasticsearch.Net/Serialization/IUrlParameter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using System.Globalization;
3+
14
namespace Elasticsearch.Net
25
{
36
public interface IUrlParameter

src/Nest/CommonAbstractions/Infer/ActionIds/ActionIds.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/Nest/CommonAbstractions/Infer/CategoryId/CategoryId.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Nest/CommonAbstractions/Infer/ForecastIds/ForecastIds.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using Elasticsearch.Net;
6+
7+
namespace Nest
8+
{
9+
[DebuggerDisplay("{DebugDisplay,nq}")]
10+
public class Ids : IUrlParameter, IEquatable<Ids>
11+
{
12+
private readonly List<string> _ids;
13+
14+
public Ids(IEnumerable<string> value) => _ids = value?.ToList();
15+
16+
public Ids(string value)
17+
{
18+
if (!value.IsNullOrEmptyCommaSeparatedList(out var arr))
19+
_ids = arr.ToList();
20+
}
21+
22+
private string DebugDisplay => ((IUrlParameter)this).GetString(null);
23+
24+
public bool Equals(Ids other)
25+
{
26+
if (other == null) return false;
27+
if (_ids == null && other._ids == null) return true;
28+
if (_ids == null || other._ids == null) return false;
29+
30+
return _ids.Count == other._ids.Count &&
31+
_ids.OrderBy(id => id).SequenceEqual(other._ids.OrderBy(id => id));
32+
}
33+
34+
string IUrlParameter.GetString(IConnectionConfigurationValues settings) =>
35+
string.Join(",", _ids ?? Enumerable.Empty<string>());
36+
37+
public static implicit operator Ids(string value) =>
38+
value.IsNullOrEmptyCommaSeparatedList(out var arr) ? null : new Ids(arr);
39+
40+
public static implicit operator Ids(string[] value) =>
41+
value.IsEmpty() ? null : new Ids(value);
42+
43+
public override bool Equals(object obj) => obj is Ids other && Equals(other);
44+
45+
public override int GetHashCode()
46+
{
47+
if (_ids == null) return 0;
48+
unchecked
49+
{
50+
var hc = 0;
51+
foreach (var id in _ids.OrderBy(id => id))
52+
hc = hc * 17 + id.GetHashCode();
53+
return hc;
54+
}
55+
}
56+
57+
public static bool operator ==(Ids left, Ids right) => Equals(left, right);
58+
59+
public static bool operator !=(Ids left, Ids right) => !Equals(left, right);
60+
}
61+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Globalization;
3+
using Elasticsearch.Net;
4+
5+
namespace Nest
6+
{
7+
public class LongId : IUrlParameter, IEquatable<LongId>
8+
{
9+
internal readonly long Value;
10+
11+
public LongId(long value) => Value = value;
12+
13+
public bool Equals(LongId other) => Value == other.Value;
14+
15+
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
16+
public string GetString(IConnectionConfigurationValues settings) => Value.ToString(CultureInfo.InvariantCulture);
17+
18+
public static implicit operator LongId(long value) => new LongId(value);
19+
20+
public static implicit operator long(LongId value) => value.Value;
21+
22+
public override bool Equals(object obj)
23+
{
24+
switch (obj)
25+
{
26+
case int l: return Value == l;
27+
case long l: return Value == l;
28+
case LongId i: return Value == i.Value;
29+
default: return false;
30+
}
31+
}
32+
33+
public override int GetHashCode() => Value.GetHashCode();
34+
35+
public static bool operator ==(LongId left, LongId right) => Equals(left, right);
36+
37+
public static bool operator !=(LongId left, LongId right) => !Equals(left, right);
38+
}
39+
}

src/Nest/CommonAbstractions/Infer/Policy/Policy.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)