Skip to content

Commit 71bf7c7

Browse files
committed
Improve serialization
1 parent 5245d06 commit 71bf7c7

File tree

1,132 files changed

+65658
-21977
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,132 files changed

+65658
-21977
lines changed

src/Elastic.Clients.Elasticsearch/Elastic.Clients.Elasticsearch.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
1717
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1818
<Nullable>annotations</Nullable>
19+
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
1920
</PropertyGroup>
2021
<ItemGroup>
2122
<PackageReference Include="Elastic.Transport" Version="0.5.7" />
23+
<PackageReference Include="PolySharp" Version="1.15.0">
24+
<PrivateAssets>all</PrivateAssets>
25+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
26+
</PackageReference>
2227
</ItemGroup>
2328
<ItemGroup>
2429
<InternalsVisibleTo Include="Tests" Key="$(ExposedPublicKey)" />

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public AsyncSearchStatusRequest(Elastic.Clients.Elasticsearch.Id id) : base(r =>
6464

6565
internal override string OperationName => "async_search.status";
6666

67+
/// <summary>
68+
/// <para>
69+
/// A unique identifier for the async search.
70+
/// </para>
71+
/// </summary>
72+
[JsonIgnore]
73+
public Elastic.Clients.Elasticsearch.Id Id { get => P<Elastic.Clients.Elasticsearch.Id>("id"); set => PR("id", value); }
74+
6775
/// <summary>
6876
/// <para>
6977
/// Specifies how long the async search needs to be available.

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

Lines changed: 147 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,161 @@
1818
#nullable restore
1919

2020
using Elastic.Clients.Elasticsearch.Fluent;
21+
using Elastic.Clients.Elasticsearch.Next;
2122
using Elastic.Clients.Elasticsearch.Serialization;
2223
using Elastic.Transport.Products.Elasticsearch;
2324
using System;
2425
using System.Collections.Generic;
26+
using System.Linq.Expressions;
27+
using System.Text.Json;
2528
using System.Text.Json.Serialization;
2629

2730
namespace Elastic.Clients.Elasticsearch.AsyncSearch;
2831

32+
internal sealed partial class AsyncSearchStatusResponseConverter : System.Text.Json.Serialization.JsonConverter<AsyncSearchStatusResponse>
33+
{
34+
private static readonly System.Text.Json.JsonEncodedText PropClusters = System.Text.Json.JsonEncodedText.Encode("_clusters");
35+
private static readonly System.Text.Json.JsonEncodedText PropCompletionStatus = System.Text.Json.JsonEncodedText.Encode("completion_status");
36+
private static readonly System.Text.Json.JsonEncodedText PropCompletionTime = System.Text.Json.JsonEncodedText.Encode("completion_time");
37+
private static readonly System.Text.Json.JsonEncodedText PropCompletionTimeInMillis = System.Text.Json.JsonEncodedText.Encode("completion_time_in_millis");
38+
private static readonly System.Text.Json.JsonEncodedText PropExpirationTime = System.Text.Json.JsonEncodedText.Encode("expiration_time");
39+
private static readonly System.Text.Json.JsonEncodedText PropExpirationTimeInMillis = System.Text.Json.JsonEncodedText.Encode("expiration_time_in_millis");
40+
private static readonly System.Text.Json.JsonEncodedText PropId = System.Text.Json.JsonEncodedText.Encode("id");
41+
private static readonly System.Text.Json.JsonEncodedText PropIsPartial = System.Text.Json.JsonEncodedText.Encode("is_partial");
42+
private static readonly System.Text.Json.JsonEncodedText PropIsRunning = System.Text.Json.JsonEncodedText.Encode("is_running");
43+
private static readonly System.Text.Json.JsonEncodedText PropShards = System.Text.Json.JsonEncodedText.Encode("_shards");
44+
private static readonly System.Text.Json.JsonEncodedText PropStartTime = System.Text.Json.JsonEncodedText.Encode("start_time");
45+
private static readonly System.Text.Json.JsonEncodedText PropStartTimeInMillis = System.Text.Json.JsonEncodedText.Encode("start_time_in_millis");
46+
47+
public override AsyncSearchStatusResponse Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
48+
{
49+
reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject);
50+
LocalJsonProperty<Elastic.Clients.Elasticsearch.ClusterStatistics?> propClusters = default;
51+
LocalJsonProperty<int?> propCompletionStatus = default;
52+
LocalJsonProperty<DateTimeOffset?> propCompletionTime = default;
53+
LocalJsonProperty<long?> propCompletionTimeInMillis = default;
54+
LocalJsonProperty<DateTimeOffset?> propExpirationTime = default;
55+
LocalJsonProperty<long> propExpirationTimeInMillis = default;
56+
LocalJsonProperty<string?> propId = default;
57+
LocalJsonProperty<bool> propIsPartial = default;
58+
LocalJsonProperty<bool> propIsRunning = default;
59+
LocalJsonProperty<Elastic.Clients.Elasticsearch.ShardStatistics> propShards = default;
60+
LocalJsonProperty<DateTimeOffset?> propStartTime = default;
61+
LocalJsonProperty<long> propStartTimeInMillis = default;
62+
while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName)
63+
{
64+
if (propClusters.TryRead(ref reader, options, PropClusters))
65+
{
66+
continue;
67+
}
68+
69+
if (propCompletionStatus.TryRead(ref reader, options, PropCompletionStatus))
70+
{
71+
continue;
72+
}
73+
74+
if (propCompletionTime.TryRead(ref reader, options, PropCompletionTime))
75+
{
76+
continue;
77+
}
78+
79+
if (propCompletionTimeInMillis.TryRead(ref reader, options, PropCompletionTimeInMillis))
80+
{
81+
continue;
82+
}
83+
84+
if (propExpirationTime.TryRead(ref reader, options, PropExpirationTime))
85+
{
86+
continue;
87+
}
88+
89+
if (propExpirationTimeInMillis.TryRead(ref reader, options, PropExpirationTimeInMillis))
90+
{
91+
continue;
92+
}
93+
94+
if (propId.TryRead(ref reader, options, PropId))
95+
{
96+
continue;
97+
}
98+
99+
if (propIsPartial.TryRead(ref reader, options, PropIsPartial))
100+
{
101+
continue;
102+
}
103+
104+
if (propIsRunning.TryRead(ref reader, options, PropIsRunning))
105+
{
106+
continue;
107+
}
108+
109+
if (propShards.TryRead(ref reader, options, PropShards))
110+
{
111+
continue;
112+
}
113+
114+
if (propStartTime.TryRead(ref reader, options, PropStartTime))
115+
{
116+
continue;
117+
}
118+
119+
if (propStartTimeInMillis.TryRead(ref reader, options, PropStartTimeInMillis))
120+
{
121+
continue;
122+
}
123+
124+
throw new System.Text.Json.JsonException($"Unknown JSON property '{reader.GetString()}' for type '{typeToConvert.Name}'.");
125+
}
126+
127+
reader.ValidateToken(System.Text.Json.JsonTokenType.EndObject);
128+
return new AsyncSearchStatusResponse
129+
{
130+
Clusters = propClusters.Value
131+
,
132+
CompletionStatus = propCompletionStatus.Value
133+
,
134+
CompletionTime = propCompletionTime.Value
135+
,
136+
CompletionTimeInMillis = propCompletionTimeInMillis.Value
137+
,
138+
ExpirationTime = propExpirationTime.Value
139+
,
140+
ExpirationTimeInMillis = propExpirationTimeInMillis.Value
141+
,
142+
Id = propId.Value
143+
,
144+
IsPartial = propIsPartial.Value
145+
,
146+
IsRunning = propIsRunning.Value
147+
,
148+
Shards = propShards.Value
149+
,
150+
StartTime = propStartTime.Value
151+
,
152+
StartTimeInMillis = propStartTimeInMillis.Value
153+
};
154+
}
155+
156+
public override void Write(System.Text.Json.Utf8JsonWriter writer, AsyncSearchStatusResponse value, System.Text.Json.JsonSerializerOptions options)
157+
{
158+
writer.WriteStartObject();
159+
writer.WriteProperty(options, PropClusters, value.Clusters);
160+
writer.WriteProperty(options, PropCompletionStatus, value.CompletionStatus);
161+
writer.WriteProperty(options, PropCompletionTime, value.CompletionTime);
162+
writer.WriteProperty(options, PropCompletionTimeInMillis, value.CompletionTimeInMillis);
163+
writer.WriteProperty(options, PropExpirationTime, value.ExpirationTime);
164+
writer.WriteProperty(options, PropExpirationTimeInMillis, value.ExpirationTimeInMillis);
165+
writer.WriteProperty(options, PropId, value.Id);
166+
writer.WriteProperty(options, PropIsPartial, value.IsPartial);
167+
writer.WriteProperty(options, PropIsRunning, value.IsRunning);
168+
writer.WriteProperty(options, PropShards, value.Shards);
169+
writer.WriteProperty(options, PropStartTime, value.StartTime);
170+
writer.WriteProperty(options, PropStartTimeInMillis, value.StartTimeInMillis);
171+
writer.WriteEndObject();
172+
}
173+
}
174+
175+
[JsonConverter(typeof(AsyncSearchStatusResponseConverter))]
29176
public sealed partial class AsyncSearchStatusResponse : ElasticsearchResponse
30177
{
31178
/// <summary>
@@ -34,7 +181,6 @@ public sealed partial class AsyncSearchStatusResponse : ElasticsearchResponse
34181
/// Not shown for local-only searches.
35182
/// </para>
36183
/// </summary>
37-
[JsonInclude, JsonPropertyName("_clusters")]
38184
public Elastic.Clients.Elasticsearch.ClusterStatistics? Clusters { get; init; }
39185

40186
/// <summary>
@@ -44,7 +190,6 @@ public sealed partial class AsyncSearchStatusResponse : ElasticsearchResponse
44190
/// 503 indicates that the async search was completed with an error.
45191
/// </para>
46192
/// </summary>
47-
[JsonInclude, JsonPropertyName("completion_status")]
48193
public int? CompletionStatus { get; init; }
49194

50195
/// <summary>
@@ -53,21 +198,16 @@ public sealed partial class AsyncSearchStatusResponse : ElasticsearchResponse
53198
/// when the search has completed.
54199
/// </para>
55200
/// </summary>
56-
[JsonInclude, JsonPropertyName("completion_time")]
57201
public DateTimeOffset? CompletionTime { get; init; }
58-
[JsonInclude, JsonPropertyName("completion_time_in_millis")]
59202
public long? CompletionTimeInMillis { get; init; }
60203

61204
/// <summary>
62205
/// <para>
63206
/// Indicates when the async search will expire.
64207
/// </para>
65208
/// </summary>
66-
[JsonInclude, JsonPropertyName("expiration_time")]
67209
public DateTimeOffset? ExpirationTime { get; init; }
68-
[JsonInclude, JsonPropertyName("expiration_time_in_millis")]
69210
public long ExpirationTimeInMillis { get; init; }
70-
[JsonInclude, JsonPropertyName("id")]
71211
public string? Id { get; init; }
72212

73213
/// <summary>
@@ -76,7 +216,6 @@ public sealed partial class AsyncSearchStatusResponse : ElasticsearchResponse
76216
/// While the query is running, <c>is_partial</c> is always set to <c>true</c>.
77217
/// </para>
78218
/// </summary>
79-
[JsonInclude, JsonPropertyName("is_partial")]
80219
public bool IsPartial { get; init; }
81220

82221
/// <summary>
@@ -85,18 +224,14 @@ public sealed partial class AsyncSearchStatusResponse : ElasticsearchResponse
85224
/// NOTE: If the search failed after some shards returned their results or the node that is coordinating the async search dies, results may be partial even though <c>is_running</c> is <c>false</c>.
86225
/// </para>
87226
/// </summary>
88-
[JsonInclude, JsonPropertyName("is_running")]
89227
public bool IsRunning { get; init; }
90228

91229
/// <summary>
92230
/// <para>
93231
/// Indicates how many shards have run the query so far.
94232
/// </para>
95233
/// </summary>
96-
[JsonInclude, JsonPropertyName("_shards")]
97234
public Elastic.Clients.Elasticsearch.ShardStatistics Shards { get; init; }
98-
[JsonInclude, JsonPropertyName("start_time")]
99235
public DateTimeOffset? StartTime { get; init; }
100-
[JsonInclude, JsonPropertyName("start_time_in_millis")]
101236
public long StartTimeInMillis { get; init; }
102237
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ public DeleteAsyncSearchRequest(Elastic.Clients.Elasticsearch.Id id) : base(r =>
5757
internal override bool SupportsBody => false;
5858

5959
internal override string OperationName => "async_search.delete";
60+
61+
/// <summary>
62+
/// <para>
63+
/// A unique identifier for the async search.
64+
/// </para>
65+
/// </summary>
66+
[JsonIgnore]
67+
public Elastic.Clients.Elasticsearch.Id Id { get => P<Elastic.Clients.Elasticsearch.Id>("id"); set => PR("id", value); }
6068
}
6169

6270
/// <summary>

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,57 @@
1818
#nullable restore
1919

2020
using Elastic.Clients.Elasticsearch.Fluent;
21+
using Elastic.Clients.Elasticsearch.Next;
2122
using Elastic.Clients.Elasticsearch.Serialization;
2223
using Elastic.Transport.Products.Elasticsearch;
2324
using System;
2425
using System.Collections.Generic;
26+
using System.Linq.Expressions;
27+
using System.Text.Json;
2528
using System.Text.Json.Serialization;
2629

2730
namespace Elastic.Clients.Elasticsearch.AsyncSearch;
2831

32+
internal sealed partial class DeleteAsyncSearchResponseConverter : System.Text.Json.Serialization.JsonConverter<DeleteAsyncSearchResponse>
33+
{
34+
private static readonly System.Text.Json.JsonEncodedText PropAcknowledged = System.Text.Json.JsonEncodedText.Encode("acknowledged");
35+
36+
public override DeleteAsyncSearchResponse Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
37+
{
38+
reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject);
39+
LocalJsonProperty<bool> propAcknowledged = default;
40+
while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName)
41+
{
42+
if (propAcknowledged.TryRead(ref reader, options, PropAcknowledged))
43+
{
44+
continue;
45+
}
46+
47+
throw new System.Text.Json.JsonException($"Unknown JSON property '{reader.GetString()}' for type '{typeToConvert.Name}'.");
48+
}
49+
50+
reader.ValidateToken(System.Text.Json.JsonTokenType.EndObject);
51+
return new DeleteAsyncSearchResponse
52+
{
53+
Acknowledged = propAcknowledged.Value
54+
};
55+
}
56+
57+
public override void Write(System.Text.Json.Utf8JsonWriter writer, DeleteAsyncSearchResponse value, System.Text.Json.JsonSerializerOptions options)
58+
{
59+
writer.WriteStartObject();
60+
writer.WriteProperty(options, PropAcknowledged, value.Acknowledged);
61+
writer.WriteEndObject();
62+
}
63+
}
64+
65+
[JsonConverter(typeof(DeleteAsyncSearchResponseConverter))]
2966
public sealed partial class DeleteAsyncSearchResponse : ElasticsearchResponse
3067
{
3168
/// <summary>
3269
/// <para>
3370
/// For a successful response, this value is always true. On failure, an exception is returned instead.
3471
/// </para>
3572
/// </summary>
36-
[JsonInclude, JsonPropertyName("acknowledged")]
3773
public bool Acknowledged { get; init; }
3874
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public GetAsyncSearchRequest(Elastic.Clients.Elasticsearch.Id id) : base(r => r.
8383

8484
internal override string OperationName => "async_search.get";
8585

86+
/// <summary>
87+
/// <para>
88+
/// A unique identifier for the async search.
89+
/// </para>
90+
/// </summary>
91+
[JsonIgnore]
92+
public Elastic.Clients.Elasticsearch.Id Id { get => P<Elastic.Clients.Elasticsearch.Id>("id"); set => PR("id", value); }
93+
8694
/// <summary>
8795
/// <para>
8896
/// Specifies how long the async search should be available in the cluster.

0 commit comments

Comments
 (0)