Skip to content

Commit 2966103

Browse files
committed
Final fixes
1 parent 22a2fac commit 2966103

File tree

4 files changed

+104
-9
lines changed

4 files changed

+104
-9
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ public IndexRequest(Elastic.Clients.Elasticsearch.IndexName index) : base(r => r
168168
{
169169
}
170170

171-
//[JsonConstructor]
172-
//internal IndexRequest()
173-
//{
174-
//}
171+
[JsonConstructor]
172+
public IndexRequest() : this(typeof(TDocument))
173+
{
174+
}
175175

176176
internal override ApiUrls ApiUrls => ApiUrlLookup.NoNamespaceIndex;
177177

@@ -352,4 +352,4 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
352352
{
353353
settings.SourceSerializer.Serialize(DocumentValue, writer);
354354
}
355-
}
355+
}

src/Elastic.Clients.Elasticsearch/_Generated/Api/TermVectorsRequest.g.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public TermVectorsRequest(Elastic.Clients.Elasticsearch.IndexName index) : base(
202202
}
203203

204204
[JsonConstructor]
205-
internal TermVectorsRequest()
205+
public TermVectorsRequest() : this(typeof(TDocument))
206206
{
207207
}
208208

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

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ namespace Elastic.Clients.Elasticsearch;
1010

1111
public partial class IndexRequest<TDocument>
1212
{
13-
[JsonConstructor]
14-
public IndexRequest() : this(typeof(TDocument)) { }
15-
1613
public IndexRequest(TDocument document, Id id) : this(typeof(TDocument), id) => Document = document;
1714

1815
protected override HttpMethod? DynamicHttpMethod => GetHttpMethod(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
using System;
6+
using System.Collections.Generic;
7+
using System.Text.Json;
8+
9+
namespace Elastic.Clients.Elasticsearch.Serialization;
10+
11+
/// <summary>
12+
/// A delegate that selects a union variant (e.g. based on the current JSON token type).
13+
/// </summary>
14+
/// <param name="reader">A reference to a <see cref="Utf8JsonReader"/> instance.</param>
15+
/// <param name="options">The <see cref="JsonSerializerOptions"/> to use.</param>
16+
/// <returns>The selected <see cref="UnionTag"/> value.</returns>
17+
/// <remarks>
18+
/// IMPORTANT:
19+
/// The <see cref="Utf8JsonReader"/> is passed by reference for best performance. If the selector function
20+
/// implementation needs to advance the reader position, it must always operate on a copy of the original
21+
/// <paramref name="reader"/> or restore the reader state before returning.
22+
/// </remarks>
23+
internal delegate UnionTag JsonUnionSelectorFunc(ref Utf8JsonReader reader, JsonSerializerOptions options);
24+
25+
[Flags]
26+
internal enum JsonTokenTypes
27+
{
28+
None = 0,
29+
StartObject = 1 << JsonTokenType.StartObject,
30+
EndObject = 1 << JsonTokenType.EndObject,
31+
StartArray = 1 << JsonTokenType.StartArray,
32+
EndArray = 1 << JsonTokenType.EndArray,
33+
String = 1 << JsonTokenType.String | 1 << JsonTokenType.PropertyName,
34+
Number = 1 << JsonTokenType.Number,
35+
True = 1 << JsonTokenType.True,
36+
False = 1 << JsonTokenType.False
37+
}
38+
39+
internal static class JsonUnionSelector
40+
{
41+
public static UnionTag ByTokenType(ref Utf8JsonReader reader, JsonSerializerOptions options, JsonTokenTypes first, JsonTokenTypes second)
42+
{
43+
_ = reader;
44+
_ = options;
45+
46+
if (((int)first & (1 << (int)reader.TokenType)) is not 0)
47+
{
48+
return UnionTag.T1;
49+
}
50+
51+
if (((int)second & (1 << (int)reader.TokenType)) is not 0)
52+
{
53+
return UnionTag.T2;
54+
}
55+
56+
return UnionTag.None;
57+
}
58+
59+
public static UnionTag ByPropertyOfT1(ref Utf8JsonReader reader, JsonSerializerOptions options, string name)
60+
{
61+
reader.ValidateToken(JsonTokenType.StartObject);
62+
63+
var internalReader = reader;
64+
65+
while (internalReader.Read() && (internalReader.TokenType is JsonTokenType.PropertyName))
66+
{
67+
if (internalReader.ValueTextEquals(name))
68+
{
69+
return UnionTag.T1;
70+
}
71+
72+
internalReader.Read();
73+
internalReader.Skip();
74+
}
75+
76+
return UnionTag.T2;
77+
}
78+
79+
public static UnionTag ByPropertyOfT2(ref Utf8JsonReader reader, JsonSerializerOptions options, string name)
80+
{
81+
reader.ValidateToken(JsonTokenType.StartObject);
82+
83+
var internalReader = reader;
84+
85+
while (internalReader.Read() && (internalReader.TokenType is JsonTokenType.PropertyName))
86+
{
87+
if (internalReader.ValueTextEquals(name))
88+
{
89+
return UnionTag.T2;
90+
}
91+
92+
internalReader.Read();
93+
internalReader.Skip();
94+
}
95+
96+
return UnionTag.T1;
97+
}
98+
}

0 commit comments

Comments
 (0)