Skip to content

Commit e4ad2b1

Browse files
russcamStuart Cam
authored and
Stuart Cam
committed
Correct serialized property name on AsciiFoldingTokenFilter (#2893)
Closes #2892
1 parent 0fed683 commit e4ad2b1

File tree

5 files changed

+72
-14
lines changed

5 files changed

+72
-14
lines changed

src/Nest/Analysis/Analyzers/AnalyzerBase.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public abstract class AnalyzerBase : IAnalyzer
1616
{
1717
internal AnalyzerBase() { }
1818

19-
protected AnalyzerBase(string type)
20-
{
21-
Type = type;
22-
}
19+
protected AnalyzerBase(string type) => Type = type;
2320

2421
public string Version { get; set; }
2522

src/Nest/Analysis/Normalizers/NormalizerBase.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public abstract class NormalizerBase : INormalizer
1616
{
1717
internal NormalizerBase() { }
1818

19-
protected NormalizerBase(string type)
20-
{
21-
Type = type;
22-
}
19+
protected NormalizerBase(string type) => Type = type;
2320

2421
public string Version { get; set; }
2522

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
namespace Nest
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
24
{
35

46
/// <summary>
5-
/// A token filter of type asciifolding that converts alphabetic, numeric, and symbolic Unicode characters which are
7+
/// A token filter of type asciifolding that converts alphabetic, numeric, and symbolic Unicode characters which are
68
/// <para> not in the first 127 ASCII characters (the “Basic Latin” Unicode block) into their ASCII equivalents, if one exists.</para>
79
/// </summary>
810
public interface IAsciiFoldingTokenFilter : ITokenFilter
911
{
12+
[JsonProperty("preserve_original")]
1013
bool? PreserveOriginal { get; set; }
1114
}
1215

1316
///<inheritdoc/>
1417
public class AsciiFoldingTokenFilter : TokenFilterBase, IAsciiFoldingTokenFilter
1518
{
16-
public AsciiFoldingTokenFilter() : base("asciifolding") { }
19+
public AsciiFoldingTokenFilter() : base("asciifolding") { }
1720

1821
public bool? PreserveOriginal { get; set; }
1922
}
2023

2124
///<inheritdoc/>
22-
public class AsciiFoldingTokenFilterDescriptor
25+
public class AsciiFoldingTokenFilterDescriptor
2326
: TokenFilterDescriptorBase<AsciiFoldingTokenFilterDescriptor, IAsciiFoldingTokenFilter>, IAsciiFoldingTokenFilter
2427
{
2528
protected override string Type => "asciifolding";
@@ -30,4 +33,4 @@ public class AsciiFoldingTokenFilterDescriptor
3033
public AsciiFoldingTokenFilterDescriptor PreserveOriginal(bool? preserve = true) => Assign(a => a.PreserveOriginal = preserve);
3134
}
3235

33-
}
36+
}

src/Tests/Analysis/TokenFilters/TokenFilterUsageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TokenFilterUsageTests : PromiseUsageTestBase<IIndexSettings, IndexS
1818
myAscii = new
1919
{
2020
type = "asciifolding",
21-
preserveOriginal = true
21+
preserve_original = true
2222
},
2323
myCommonGrams = new
2424
{

src/Tests/CodeStandards/Analysis.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using FluentAssertions;
5+
using Nest;
6+
using Newtonsoft.Json;
7+
using Tests.Framework;
8+
9+
namespace Tests.CodeStandards
10+
{
11+
public class Analysis
12+
{
13+
/**
14+
* Every analyzer interface should attribute properties with JsonPropertyAttribute
15+
*/
16+
[U]
17+
public void AnalyzerPropertiesAreAttributedWithJsonPropertyAttribute() =>
18+
PropertiesOfTypeAreAttributedWithJsonPropertyAttribute(typeof(IAnalyzer));
19+
20+
/**
21+
* Every normalizer interface should attribute properties with JsonPropertyAttribute
22+
*/
23+
[U]
24+
public void NormalizerPropertiesAreAttributedWithJsonPropertyAttribute() =>
25+
PropertiesOfTypeAreAttributedWithJsonPropertyAttribute(typeof(INormalizer));
26+
27+
/**
28+
* Every char filter interface should attribute properties with JsonPropertyAttribute
29+
*/
30+
[U]
31+
public void CharFilterPropertiesAreAttributedWithJsonPropertyAttribute() =>
32+
PropertiesOfTypeAreAttributedWithJsonPropertyAttribute(typeof(ICharFilter));
33+
34+
/**
35+
* Every tokenizer interface should attribute properties with JsonPropertyAttribute
36+
*/
37+
[U]
38+
public void TokenizerPropertiesAreAttributedWithJsonPropertyAttribute() =>
39+
PropertiesOfTypeAreAttributedWithJsonPropertyAttribute(typeof(ITokenizer));
40+
41+
/**
42+
* Every token filter interface should attribute properties with JsonPropertyAttribute
43+
*/
44+
[U]
45+
public void TokenFilterPropertiesAreAttributedWithJsonPropertyAttribute() =>
46+
PropertiesOfTypeAreAttributedWithJsonPropertyAttribute(typeof(ITokenFilter));
47+
48+
private static void PropertiesOfTypeAreAttributedWithJsonPropertyAttribute(Type type)
49+
{
50+
var types =
51+
from t in type.Assembly().Types()
52+
where t.IsInterface() && type.IsAssignableFrom(t)
53+
let properties = t.GetProperties()
54+
from p in properties
55+
where p.GetCustomAttribute(typeof(JsonPropertyAttribute)) == null
56+
select $"{p.Name} on {t.Name} does not have {nameof(JsonPropertyAttribute)} applied";
57+
58+
types.Should().BeEmpty();
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)