Skip to content

Commit 13dc11a

Browse files
committed
fix #2188, get template with alias would throw json read exception because it can't create an instance of the interface
1 parent 409804c commit 13dc11a

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

src/Nest/Domain/Alias/CreateAliasDescriptor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Nest
66
{
7+
[JsonConverter(typeof(ReadAsTypeConverter<CreateAliasOperation>))]
78
public interface ICreateAliasOperation
89
{
910
[JsonProperty("filter")]

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@
415415
<None Include="Core\Update\UpdateDetectNoop.json">
416416
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
417417
</None>
418+
<None Include="ObjectInitializer\Template\TemplateWithEmptyAliasResponse.json">
419+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
420+
</None>
421+
<None Include="ObjectInitializer\Template\TemplateWithAliasResponse.json">
422+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
423+
</None>
418424
<None Include="Reproduce\Issue1528_ExplicitTypeAndIndex.json">
419425
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
420426
</None>

src/Tests/Nest.Tests.Unit/ObjectInitializer/Template/GetTemplateRequestTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reflection;
45
using Elasticsearch.Net;
56
using FluentAssertions;
67
using NUnit.Framework;
@@ -25,6 +26,33 @@ public void Url()
2526
this._status.RequestUrl.Should().EndWith("/_template/me-templ");
2627
this._status.RequestMethod.Should().Be("GET");
2728
}
29+
2830
}
31+
[TestFixture]
32+
public class GetTemplateResponseTests : BaseJsonTests
33+
{
34+
[Test]
35+
public void HandlesResponseWithAlias()
36+
{
37+
38+
var client = this.GetFixedReturnClient(MethodInfo.GetCurrentMethod(), "TemplateWithAliasResponse");
39+
var response = client.GetTemplate("employees");
40+
response.TemplateMapping.Aliases.Should().NotBeNull().And.NotBeEmpty();
41+
var alias = response.TemplateMapping.Aliases.First();
42+
alias.Key.Should().Be("employees");
43+
alias.Value.Routing.Should().Be("name");
2944

45+
}
46+
47+
[Test]
48+
public void HandlesResponseWithEmptyAlias()
49+
{
50+
51+
var client = this.GetFixedReturnClient(MethodInfo.GetCurrentMethod(), "TemplateWithEmptyAliasResponse");
52+
var response = client.GetTemplate("employees");
53+
response.TemplateMapping.Aliases.Should().NotBeNull().And.NotBeEmpty();
54+
var alias = response.TemplateMapping.Aliases.First();
55+
alias.Key.Should().Be("employees");
56+
}
57+
}
3058
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"employees": {
3+
"order": 0,
4+
"template": "employees-v1-*",
5+
"settings": {},
6+
"mappings": {},
7+
"warmers": {},
8+
"aliases": {
9+
"employees": { "routing" : "name" }
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"employees": {
3+
"order": 0,
4+
"template": "employees-v1-*",
5+
"settings": {},
6+
"mappings": {},
7+
"warmers": {},
8+
"aliases": {
9+
"employees": {}
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)