Skip to content

Commit 12863d5

Browse files
Fix to ensure dynamic HTTP methods are used when available (#7058) (#7059)
Co-authored-by: Steve Gordon <[email protected]>
1 parent 679592e commit 12863d5

File tree

116 files changed

+342
-279
lines changed

Some content is hidden

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

116 files changed

+342
-279
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public partial class IndexRequest<TDocument> : ICustomJsonWriter
1414
{
1515
public IndexRequest() : this(typeof(TDocument)) { }
1616

17-
//public IndexRequest(TDocument document) : this(typeof(TDocument)) => Document = document;
18-
1917
public IndexRequest(TDocument document, Id id) : this(typeof(TDocument), id) => Document = document;
2018

2119
protected override HttpMethod? DynamicHttpMethod => GetHttpMethod(this);
@@ -34,7 +32,6 @@ internal static HttpMethod GetHttpMethod(IndexRequest<TDocument> request) =>
3432

3533
public sealed partial class IndexRequestDescriptor<TDocument> : ICustomJsonWriter
3634
{
37-
// TODO: Codegen
3835
public IndexRequestDescriptor<TDocument> Document(TDocument document)
3936
{
4037
DocumentValue = document;

src/Elastic.Clients.Elasticsearch/Core/Fluent/Descriptor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Elastic.Clients.Elasticsearch.Fluent;
1414

1515
public abstract class Descriptor
1616
{
17-
// This internal ctor ensures that only types defined within the client assembly can derive from this base class.
17+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
1818
// We don't expect consumers to derive from this public base class.
1919
internal Descriptor() { }
2020

@@ -49,7 +49,7 @@ public abstract class Descriptor<TDescriptor> : Descriptor
4949
{
5050
private readonly TDescriptor _self;
5151

52-
// This internal ctor ensures that only types defined within the client assembly can derive from this base class.
52+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
5353
// We don't expect consumers to derive from this public base class.
5454
internal Descriptor() : base() => _self = (TDescriptor)this;
5555

@@ -64,7 +64,7 @@ public abstract class Descriptor<TDescriptor> : Descriptor
6464
public abstract class SerializableDescriptor<TDescriptor> : Descriptor<TDescriptor>, ISelfSerializable
6565
where TDescriptor : SerializableDescriptor<TDescriptor>
6666
{
67-
// This internal ctor ensures that only types defined within the client assembly can derive from this base class.
67+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
6868
// We don't expect consumers to derive from this public base class.
6969
internal SerializableDescriptor(): base() { }
7070

src/Elastic.Clients.Elasticsearch/Core/Fluent/Promise/IsADictionaryDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract class IsADictionaryDescriptor<TDescriptor, TPromised, TKey, TVal
1111
where TDescriptor : IsADictionaryDescriptor<TDescriptor, TPromised, TKey, TValue>
1212
where TPromised : class, IIsADictionary<TKey, TValue>
1313
{
14-
// This internal ctor ensures that only types defined within the client assembly can derive from this base class.
14+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
1515
// We don't expect consumers to derive from this public base class.
1616
internal IsADictionaryDescriptor(TPromised instance) : base(instance) { }
1717

src/Elastic.Clients.Elasticsearch/Core/Fluent/Promise/PromiseDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class PromiseDescriptor<TDescriptor, TValue> : Descriptor, IProm
1212
{
1313
internal readonly TValue PromisedValue;
1414

15-
// This internal ctor ensures that only types defined within the client assembly can derive from this base class.
15+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
1616
// We don't expect consumers to derive from this public base class.
1717
internal PromiseDescriptor(TValue instance) : base()
1818
{

src/Elastic.Clients.Elasticsearch/Core/Request/PlainRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Elastic.Clients.Elasticsearch.Requests;
1111
public abstract class PlainRequest<TParameters> : Request<TParameters>
1212
where TParameters : RequestParameters, new()
1313
{
14-
// This internal ctor ensures that only types defined within the client assembly can derive from this base class.
14+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
1515
// We don't expect consumers to derive from this public base class.
1616
internal PlainRequest() { }
1717

src/Elastic.Clients.Elasticsearch/Core/Request/Request.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,43 @@
88

99
namespace Elastic.Clients.Elasticsearch.Requests;
1010

11+
/// <summary>
12+
/// Base type for requests sent by the client.
13+
/// </summary>
1114
public abstract class Request
1215
{
16+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
17+
// We don't expect consumers to derive from this public base class.
1318
internal Request() { }
1419

1520
internal virtual string? Accept { get; } = null;
1621

1722
internal virtual string? ContentType { get; } = null;
1823

19-
[JsonIgnore] internal abstract HttpMethod HttpMethod { get; }
20-
21-
[JsonIgnore] internal abstract bool SupportsBody { get; }
22-
23-
[JsonIgnore] protected RouteValues RouteValues { get; } = new();
24-
25-
[JsonIgnore] protected virtual HttpMethod? DynamicHttpMethod => null;
24+
/// <summary>
25+
/// The default HTTP method for the request which is based on the Elasticsearch Specification endpoint definition.
26+
/// </summary>
27+
[JsonIgnore]
28+
protected abstract HttpMethod StaticHttpMethod { get; }
29+
30+
[JsonIgnore]
31+
internal abstract bool SupportsBody { get; }
32+
33+
[JsonIgnore]
34+
protected RouteValues RouteValues { get; } = new();
35+
36+
/// <summary>
37+
/// Allows for per request replacement of the specified HTTP method, including scenarios such as indexing which
38+
/// require access to the document to determine the correct URL path and method combination to choose.
39+
/// </summary>
40+
[JsonIgnore]
41+
protected virtual HttpMethod? DynamicHttpMethod => null;
42+
43+
/// <summary>
44+
/// The final HTTP method used to send the request to the Elasticsearch server.
45+
/// </summary>
46+
[JsonIgnore]
47+
internal HttpMethod HttpMethod => DynamicHttpMethod ?? StaticHttpMethod;
2648

2749
internal abstract ApiUrls ApiUrls { get; }
2850

src/Elastic.Clients.Elasticsearch/Core/Request/RequestDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public abstract partial class RequestDescriptor<TDescriptor, TParameters> : Requ
2121

2222
void ISelfSerializable.Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) => Serialize(writer, options, settings);
2323

24-
// This internal ctor ensures that only types defined within the client assembly can derive from this base class.
24+
// This internal ctor ensures that only types defined within the Elastic.Clients.Elasticsearch assembly can derive from this base class.
2525
// We don't expect consumers to derive from this public base class.
2626
internal RequestDescriptor() => _descriptor = (TDescriptor)this;
2727

src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/AsyncSearchStatusRequest.g.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public AsyncSearchStatusRequest(Elastic.Clients.Elasticsearch.Id id) : base(r =>
3838
}
3939

4040
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchStatus;
41-
internal override HttpMethod HttpMethod => HttpMethod.GET;
41+
protected override HttpMethod StaticHttpMethod => HttpMethod.GET;
4242
internal override bool SupportsBody => false;
4343
}
4444

@@ -54,7 +54,7 @@ internal AsyncSearchStatusRequestDescriptor()
5454
}
5555

5656
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchStatus;
57-
internal override HttpMethod HttpMethod => HttpMethod.GET;
57+
protected override HttpMethod StaticHttpMethod => HttpMethod.GET;
5858
internal override bool SupportsBody => false;
5959
public AsyncSearchStatusRequestDescriptor<TDocument> Id(Elastic.Clients.Elasticsearch.Id id)
6060
{
@@ -79,7 +79,7 @@ internal AsyncSearchStatusRequestDescriptor()
7979
}
8080

8181
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchStatus;
82-
internal override HttpMethod HttpMethod => HttpMethod.GET;
82+
protected override HttpMethod StaticHttpMethod => HttpMethod.GET;
8383
internal override bool SupportsBody => false;
8484
public AsyncSearchStatusRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id)
8585
{

src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/DeleteAsyncSearchRequest.g.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public DeleteAsyncSearchRequest(Elastic.Clients.Elasticsearch.Id id) : base(r =>
3838
}
3939

4040
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchDelete;
41-
internal override HttpMethod HttpMethod => HttpMethod.DELETE;
41+
protected override HttpMethod StaticHttpMethod => HttpMethod.DELETE;
4242
internal override bool SupportsBody => false;
4343
}
4444

@@ -54,7 +54,7 @@ internal DeleteAsyncSearchRequestDescriptor()
5454
}
5555

5656
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchDelete;
57-
internal override HttpMethod HttpMethod => HttpMethod.DELETE;
57+
protected override HttpMethod StaticHttpMethod => HttpMethod.DELETE;
5858
internal override bool SupportsBody => false;
5959
public DeleteAsyncSearchRequestDescriptor<TDocument> Id(Elastic.Clients.Elasticsearch.Id id)
6060
{
@@ -79,7 +79,7 @@ internal DeleteAsyncSearchRequestDescriptor()
7979
}
8080

8181
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchDelete;
82-
internal override HttpMethod HttpMethod => HttpMethod.DELETE;
82+
protected override HttpMethod StaticHttpMethod => HttpMethod.DELETE;
8383
internal override bool SupportsBody => false;
8484
public DeleteAsyncSearchRequestDescriptor Id(Elastic.Clients.Elasticsearch.Id id)
8585
{

src/Elastic.Clients.Elasticsearch/_Generated/Api/AsyncSearch/GetAsyncSearchRequest.g.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public GetAsyncSearchRequest(Elastic.Clients.Elasticsearch.Id id) : base(r => r.
4646
}
4747

4848
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchGet;
49-
internal override HttpMethod HttpMethod => HttpMethod.GET;
49+
protected override HttpMethod StaticHttpMethod => HttpMethod.GET;
5050
internal override bool SupportsBody => false;
5151
[JsonIgnore]
5252
public Elastic.Clients.Elasticsearch.Duration? KeepAlive { get => Q<Elastic.Clients.Elasticsearch.Duration?>("keep_alive"); set => Q("keep_alive", value); }
@@ -70,7 +70,7 @@ internal GetAsyncSearchRequestDescriptor()
7070
}
7171

7272
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchGet;
73-
internal override HttpMethod HttpMethod => HttpMethod.GET;
73+
protected override HttpMethod StaticHttpMethod => HttpMethod.GET;
7474
internal override bool SupportsBody => false;
7575
public GetAsyncSearchRequestDescriptor<TDocument> KeepAlive(Elastic.Clients.Elasticsearch.Duration? keepAlive) => Qs("keep_alive", keepAlive);
7676
public GetAsyncSearchRequestDescriptor<TDocument> TypedKeys(bool? typedKeys = true) => Qs("typed_keys", typedKeys);
@@ -98,7 +98,7 @@ internal GetAsyncSearchRequestDescriptor()
9898
}
9999

100100
internal override ApiUrls ApiUrls => ApiUrlsLookups.AsyncSearchGet;
101-
internal override HttpMethod HttpMethod => HttpMethod.GET;
101+
protected override HttpMethod StaticHttpMethod => HttpMethod.GET;
102102
internal override bool SupportsBody => false;
103103
public GetAsyncSearchRequestDescriptor KeepAlive(Elastic.Clients.Elasticsearch.Duration? keepAlive) => Qs("keep_alive", keepAlive);
104104
public GetAsyncSearchRequestDescriptor TypedKeys(bool? typedKeys = true) => Qs("typed_keys", typedKeys);

0 commit comments

Comments
 (0)