Skip to content

Commit 6d6da7c

Browse files
Remove inheritance for code-generated types (#6611) (#6612)
* Remove inheritence for code gen of classes * Seal request types * Update serialization after inheritance removal * Prevent parallel tests which seem to hang * Fix search API test assertion * Fix multi search test * Rename and move some files * Queries derive from Query type * Update tests * Update test file Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
1 parent 07cc9c4 commit 6d6da7c

File tree

1,452 files changed

+9514
-13050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,452 files changed

+9514
-13050
lines changed

src/Elastic.Clients.Elasticsearch/Api/BulkRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Elastic.Clients.Elasticsearch
1313
{
1414
public partial class BulkRequest : IStreamSerializable
1515
{
16-
protected IRequest Self => this;
16+
internal IRequest Self => this;
1717

1818
public BulkOperationsCollection Operations { get; set; }
1919

src/Elastic.Clients.Elasticsearch/Api/CountRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Elastic.Clients.Elasticsearch
99
{
10-
public partial class CountRequest<TDocument> : CountRequest
10+
public sealed partial class CountRequest<TDocument> : CountRequest
1111
{
1212
//protected CountRequest<TDocument> TypedSelf => this;
1313

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch.Aggregations;
6+
7+
public interface IAggregate { }
8+
9+
/// <summary>
10+
/// Base class for all aggregates.
11+
/// </summary>
12+
public abstract class Aggregate : IAggregate
13+
{
14+
}
15+
16+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Elastic.Clients.Elasticsearch.Aggregations;
6+
7+
public interface IAggregation
8+
{
9+
string? Name { get; }
10+
}
11+
12+
/// <summary>
13+
/// Base class for all aggregations.
14+
/// </summary>
15+
public abstract class Aggregation : IAggregation
16+
{
17+
public abstract string? Name { get; internal set; }
18+
19+
//always evaluate to false so that each side of && equation is evaluated
20+
public static bool operator false(Aggregation _) => false;
21+
22+
//always evaluate to false so that each side of && equation is evaluated
23+
public static bool operator true(Aggregation _) => false;
24+
25+
public static Aggregation operator &(Aggregation left, Aggregation right) =>
26+
new AggregationCombinator(null, left, right);
27+
}

src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationBase.cs

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

src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationCombinator.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ namespace Elastic.Clients.Elasticsearch.Aggregations;
1010
/// <summary>
1111
/// Combines aggregations into a single list of aggregations.
1212
/// </summary>
13-
internal class AggregationCombinator : AggregationBase
13+
internal class AggregationCombinator : Aggregation
1414
{
15-
public AggregationCombinator(string name, AggregationBase left, AggregationBase right) : base(name)
15+
public AggregationCombinator(string name, Aggregation left, Aggregation right)
1616
{
1717
AddAggregation(left);
1818
AddAggregation(right);
19+
Name = name;
1920
}
2021

21-
internal List<AggregationBase> Aggregations { get; } = new List<AggregationBase>();
22+
public override string? Name { get; internal set; }
2223

23-
//internal override void WrapInContainer(AggregationContainer container) { }
24+
internal List<Aggregation> Aggregations { get; } = new List<Aggregation>();
2425

25-
private void AddAggregation(AggregationBase agg)
26+
private void AddAggregation(Aggregation agg)
2627
{
2728
switch (agg)
2829
{

src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationDictionary.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Elastic.Clients.Elasticsearch.Aggregations;
1010

1111
/// <summary>
12-
/// Describes aggregations that we would like to execute on Elasticsearch.
12+
/// Describes aggregations to execute as part of a search.
1313
/// </summary>
1414
public sealed class AggregationDictionary : IsADictionaryBase<string, AggregationContainer>
1515
{
@@ -24,9 +24,9 @@ public AggregationDictionary(Dictionary<string, AggregationContainer> dictionary
2424
public static implicit operator AggregationDictionary(Dictionary<string, AggregationContainer> dictionary) =>
2525
new(dictionary);
2626

27-
public static implicit operator AggregationDictionary(AggregationBase aggregator)
27+
public static implicit operator AggregationDictionary(Aggregation aggregator)
2828
{
29-
AggregationBase b;
29+
Aggregation b;
3030
if (aggregator is AggregationCombinator combinator)
3131
{
3232
var dict = new AggregationDictionary();

src/Elastic.Clients.Elasticsearch/Common/Query/QueryBase.cs renamed to src/Elastic.Clients.Elasticsearch/Common/Query/Query.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77

88
namespace Elastic.Clients.Elasticsearch.QueryDsl
99
{
10-
// TODO: FieldNameQueryConvertor (see FieldNameQueryFormatter)
11-
public interface IFieldNameQuery
12-
{
13-
Field Field { get; set; }
14-
}
15-
16-
public abstract class FieldNameQueryBase : QueryBase, IFieldNameQuery
17-
{
18-
[JsonIgnore]
19-
public Field Field { get; set; }
20-
}
21-
2210
public interface IQuery
2311
{
2412
/// <summary>
@@ -53,19 +41,19 @@ public interface IQuery
5341
/// <summary>
5442
/// Whether the query should be treated as writable. Used when determining how to combine queries.
5543
/// </summary>
56-
[JsonIgnore]
57-
bool IsWritable { get; }
44+
//[JsonIgnore]
45+
//bool IsWritable { get; }
5846

5947
/// <summary>
6048
/// The name of the query. Allows you to retrieve for each document what part of the query it matched on.
6149
/// </summary>
6250
//string Name { get; set; }
6351
}
6452

65-
public abstract partial class QueryBase : IQuery
53+
public abstract partial class Query : IQuery
6654
{
67-
[JsonIgnore]
68-
public bool IsWritable => throw new NotImplementedException();
55+
//[JsonIgnore]
56+
//public bool IsWritable => throw new NotImplementedException();
6957

7058
////protected abstract bool Conditionless { get; }
7159
//[JsonIgnore]
@@ -80,10 +68,10 @@ public abstract partial class QueryBase : IQuery
8068
//bool IQuery.Conditionless => Conditionless;
8169

8270
//always evaluate to false so that each side of && equation is evaluated
83-
public static bool operator false(QueryBase a) => false;
71+
public static bool operator false(Query a) => false;
8472

8573
//always evaluate to false so that each side of && equation is evaluated
86-
public static bool operator true(QueryBase a) => false;
74+
public static bool operator true(Query a) => false;
8775

8876
//public static QueryBase operator &(QueryBase leftQuery, QueryBase rightQuery) => Combine(leftQuery, rightQuery, (l, r) => l && r);
8977

src/Elastic.Clients.Elasticsearch/Serialization/AggregationContainerSerializationHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Elastic.Clients.Elasticsearch
1010

1111
internal static class AggregationContainerSerializationHelper
1212
{
13-
public static AggregationContainer ReadContainer<T>(ref Utf8JsonReader reader, JsonSerializerOptions options) where T : AggregationBase
13+
public static AggregationContainer ReadContainer<T>(ref Utf8JsonReader reader, JsonSerializerOptions options) where T : Aggregation
1414
{
1515
var variant = JsonSerializer.Deserialize<T?>(ref reader, options);
1616

@@ -19,7 +19,7 @@ public static AggregationContainer ReadContainer<T>(ref Utf8JsonReader reader, J
1919
return container;
2020
}
2121

22-
public static AggregationContainer ReadContainer<T>(string variantName, ref Utf8JsonReader reader, JsonSerializerOptions options) where T : AggregationBase
22+
public static AggregationContainer ReadContainer<T>(string variantName, ref Utf8JsonReader reader, JsonSerializerOptions options) where T : Aggregation
2323
{
2424
var variant = JsonSerializer.Deserialize<T?>(ref reader, options);
2525

src/Elastic.Clients.Elasticsearch/Serialization/FieldNameQueryConverterBase.cs

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

0 commit comments

Comments
 (0)