Skip to content

Fix code-gen for enums with aliases. #7253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
'8.3.3',
'8.4.3',
'8.5.3',
'8.6.1',
'8.6.2',
'8.7.0-SNAPSHOT',
'latest-8'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,28 @@ public override CalendarInterval Read(ref Utf8JsonReader reader, Type typeToConv
switch (enumString)
{
case "year":
case "1Y":
return CalendarInterval.Year;
case "week":
case "1w":
return CalendarInterval.Week;
case "second":
case "1s":
return CalendarInterval.Second;
case "quarter":
case "1q":
return CalendarInterval.Quarter;
case "month":
case "1M":
return CalendarInterval.Month;
case "minute":
case "1m":
return CalendarInterval.Minute;
case "hour":
case "1h":
return CalendarInterval.Hour;
case "day":
case "1d":
return CalendarInterval.Day;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,10 @@ public override SegmentSortMode Read(ref Utf8JsonReader reader, Type typeToConve
switch (enumString)
{
case "min":
case "MIN":
return SegmentSortMode.Min;
case "max":
case "MAX":
return SegmentSortMode.Max;
}

Expand Down Expand Up @@ -419,8 +421,10 @@ public override SegmentSortOrder Read(ref Utf8JsonReader reader, Type typeToConv
switch (enumString)
{
case "desc":
case "DESC":
return SegmentSortOrder.Desc;
case "asc":
case "ASC":
return SegmentSortOrder.Asc;
}

Expand Down Expand Up @@ -537,8 +541,10 @@ public override TranslogDurability Read(ref Utf8JsonReader reader, Type typeToCo
switch (enumString)
{
case "request":
case "REQUEST":
return TranslogDurability.Request;
case "async":
case "ASYNC":
return TranslogDurability.Async;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,14 @@ public override GeoOrientation Read(ref Utf8JsonReader reader, Type typeToConver
switch (enumString)
{
case "right":
case "RIGHT":
case "counterclockwise":
case "ccw":
return GeoOrientation.Right;
case "left":
case "LEFT":
case "clockwise":
case "cw":
return GeoOrientation.Left;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,13 @@ public override HealthStatus Read(ref Utf8JsonReader reader, Type typeToConvert,
switch (enumString)
{
case "yellow":
case "YELLOW":
return HealthStatus.Yellow;
case "red":
case "RED":
return HealthStatus.Red;
case "green":
case "GREEN":
return HealthStatus.Green;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,10 @@ public override Operator Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
switch (enumString)
{
case "or":
case "OR":
return Operator.Or;
case "and":
case "AND":
return Operator.And;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Linq;
using Elastic.Clients.Elasticsearch.IndexManagement;
using Tests.Serialization;

namespace Tests.IndexManagement.DataStreamManagement;

public class GetDataStreamSerializationTests : SerializerTestBase
{
[U]
public void GetIndexResponse_IsDeserializedCorrectly()
{
const string json = @"{
""data_streams"": [
{
""name"": ""logs-dev"",
""timestamp_field"": {
""name"": ""@timestamp""
},
""indices"": [
{
""index_name"": "".ds-logs-dev-2023.02.16-000001"",
""index_uuid"": ""xyWXN5T1Rm6_sOCayv7GDA""
}
],
""generation"": 1,
""_meta"": {
""description"": ""default logs template installed by x-pack"",
""managed"": true
},
""status"": ""GREEN"",
""template"": ""logs"",
""ilm_policy"": ""logs"",
""hidden"": false,
""system"": false,
""allow_custom_routing"": false,
""replicated"": false
}
]
}";

var response = DeserializeJsonString<GetDataStreamResponse>(json);

response.DataStreams.Count.Should().Be(1);

var dataStream = response.DataStreams.First();

dataStream.Name.Should().Be("logs-dev");
dataStream.TimestampField.Name.Should().Be("@timestamp");

dataStream.Indices.Count.Should().Be(1);
var indices = dataStream.Indices.First();
indices.IndexName.Should().Be(".ds-logs-dev-2023.02.16-000001");
indices.IndexUuid.Should().Be("xyWXN5T1Rm6_sOCayv7GDA");

dataStream.Generation.Should().Be(1);
dataStream.Meta["description"].Should().Be("default logs template installed by x-pack");
dataStream.Meta["managed"].Should().Be(true);
dataStream.Status.Should().Be(HealthStatus.Green);
dataStream.Template.Should().Be("logs");
dataStream.IlmPolicy.Should().Be("logs");
dataStream.Hidden.Should().Be(false);
dataStream.System.Should().Be(false);
dataStream.AllowCustomRouting.Should().Be(false);
dataStream.Replicated.Should().Be(false);
}
}