Skip to content

Commit c47b09a

Browse files
floberndgithub-actions[bot]
authored andcommitted
Fix BucketsPath (de-)serialization (#8164)
1 parent f1e234d commit c47b09a

File tree

2 files changed

+43
-149
lines changed
  • src
    • Elastic.Clients.Elasticsearch.Serverless/_Generated/Types/Aggregations
    • Elastic.Clients.Elasticsearch.Shared/Types/Aggregations

2 files changed

+43
-149
lines changed

Diff for: src/Elastic.Clients.Elasticsearch.Serverless/_Generated/Types/Aggregations/BucketsPath.g.cs

-122
This file was deleted.

Diff for: src/Elastic.Clients.Elasticsearch/_Generated/Types/Aggregations/BucketsPath.g.cs renamed to src/Elastic.Clients.Elasticsearch.Shared/Types/Aggregations/BucketsPath.cs

+43-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
// Licensed to Elasticsearch B.V under one or more agreements.
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
4-
//
5-
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6-
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7-
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8-
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9-
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10-
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11-
// ------------------------------------------------
12-
//
13-
// This file is automatically generated.
14-
// Please do not edit these files manually.
15-
//
16-
// ------------------------------------------------
17-
18-
#nullable restore
194

5+
#nullable enable
6+
7+
#if ELASTICSEARCH_SERVERLESS
8+
using Elastic.Clients.Elasticsearch.Serverless.Core;
9+
#else
2010
using Elastic.Clients.Elasticsearch.Core;
21-
using Elastic.Clients.Elasticsearch.Fluent;
22-
using Elastic.Clients.Elasticsearch.Serialization;
23-
using Elastic.Transport;
11+
#endif
12+
2413
using System;
2514
using System.Collections.Generic;
2615
using System.Diagnostics.CodeAnalysis;
27-
using System.Linq.Expressions;
2816
using System.Text.Json;
2917
using System.Text.Json.Serialization;
3018

19+
#if ELASTICSEARCH_SERVERLESS
20+
namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;
21+
#else
3122
namespace Elastic.Clients.Elasticsearch.Aggregations;
23+
#endif
3224

3325
/// <summary>
3426
/// <para>Buckets path can be expressed in different ways, and an aggregation may accept some or all of these<br/>forms depending on its type. Please refer to each aggregation's documentation to know what buckets<br/>path forms they accept.</para>
@@ -43,8 +35,8 @@ public enum Kind
4335
Dictionary
4436
}
4537

46-
private readonly Kind _kind;
47-
private readonly object _value;
38+
internal readonly Kind _kind;
39+
internal readonly object _value;
4840

4941
Kind IComplexUnion<Kind>.ValueKind => _kind;
5042

@@ -111,12 +103,36 @@ public bool TryGetDictionary([NotNullWhen(true)] out Dictionary<string, string>?
111103
public static implicit operator BucketsPath(Dictionary<string, string> dictionary) => BucketsPath.Dictionary(dictionary);
112104
}
113105

114-
internal sealed class BucketsPathConverter : MultiItemUnionConverter<BucketsPath, BucketsPath.Kind>
106+
internal sealed class BucketsPathConverter : JsonConverter<BucketsPath>
115107
{
116-
public BucketsPathConverter()
108+
public override BucketsPath? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
109+
(reader.TokenType) switch
110+
{
111+
JsonTokenType.Null => null,
112+
JsonTokenType.String => BucketsPath.Single(JsonSerializer.Deserialize<string>(ref reader, options)!),
113+
JsonTokenType.StartArray => BucketsPath.Array(JsonSerializer.Deserialize<string[]>(ref reader, options)!),
114+
JsonTokenType.StartObject => BucketsPath.Dictionary(JsonSerializer.Deserialize<Dictionary<string, string>>(ref reader, options)!),
115+
_ => throw new JsonException($"Unexpected token '{reader.TokenType}'.")
116+
};
117+
118+
public override void Write(Utf8JsonWriter writer, BucketsPath value, JsonSerializerOptions options)
117119
{
118-
_types = new Dictionary<BucketsPath.Kind, Type> { { BucketsPath.Kind.Single, typeof(string) }, { BucketsPath.Kind.Array, typeof(IReadOnlyCollection<string>) }, { BucketsPath.Kind.Dictionary, typeof(IReadOnlyDictionary<string, string>) } };
119-
_factories = new Dictionary<Type, Func<object, BucketsPath>> { { typeof(string), o => BucketsPath.Single((string)o) }, { typeof(string[]), o => BucketsPath.Array((string[])o) }, { typeof(Dictionary<string, string>), o => BucketsPath.Dictionary((Dictionary<string, string>)o) } };
120-
_uniquePropertyToType = new Dictionary<string, Type> { { "", typeof(string) }, { "", typeof(IReadOnlyCollection<string>) }, { "", typeof(IReadOnlyDictionary<string, string>) } };
120+
switch (value._kind)
121+
{
122+
case BucketsPath.Kind.Single:
123+
writer.WriteStringValue((string)value._value);
124+
break;
125+
126+
case BucketsPath.Kind.Array:
127+
JsonSerializer.Serialize(writer, (string[])value._value, options);
128+
break;
129+
130+
case BucketsPath.Kind.Dictionary:
131+
JsonSerializer.Serialize(writer, (Dictionary<string, string>)value._value, options);
132+
break;
133+
134+
default:
135+
throw new ArgumentOutOfRangeException();
136+
}
121137
}
122-
}
138+
}

0 commit comments

Comments
 (0)