Skip to content

Commit 5692fed

Browse files
committed
fix char pattern replace by making replcement optional
Signed-off-by: Grouh <[email protected]>
1 parent 0742ae2 commit 5692fed

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
4545
### Fixed
4646
- Fix integer overflow for variables in indices stats response ([#877](https://github.com/opensearch-project/opensearch-java/pull/877))
4747
- Support weight function in function score query ([#880](https://github.com/opensearch-project/opensearch-java/pull/880))
48-
- Fix pattern replace by making flag optional as on api ([#895](https://github.com/opensearch-project/opensearch-java/pull/895))
48+
- Fix pattern replace by making flag and replacement optional as on api ([#895](https://github.com/opensearch-project/opensearch-java/pull/895))
4949

5050
### Security
5151

java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/PatternReplaceCharFilter.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class PatternReplaceCharFilter extends CharFilterBase implements CharFilt
5252

5353
private final String pattern;
5454

55+
@Nullable
5556
private final String replacement;
5657

5758
// ---------------------------------------------------------------------------------------------
@@ -61,8 +62,7 @@ private PatternReplaceCharFilter(Builder builder) {
6162

6263
this.flags = builder.flags;
6364
this.pattern = ApiTypeHelper.requireNonNull(builder.pattern, this, "pattern");
64-
this.replacement = ApiTypeHelper.requireNonNull(builder.replacement, this, "replacement");
65-
65+
this.replacement = builder.replacement;
6666
}
6767

6868
public static PatternReplaceCharFilter of(Function<Builder, ObjectBuilder<PatternReplaceCharFilter>> fn) {
@@ -93,7 +93,7 @@ public final String pattern() {
9393
}
9494

9595
/**
96-
* Required - API name: {@code replacement}
96+
* API name: {@code replacement}
9797
*/
9898
public final String replacement() {
9999
return this.replacement;
@@ -104,17 +104,18 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
104104
generator.write("type", "pattern_replace");
105105
super.serializeInternal(generator, mapper);
106106

107-
if (this.flags != null) {
108-
generator.writeKey("flags");
109-
generator.write(this.flags);
110-
}
111-
112107
generator.writeKey("pattern");
113108
generator.write(this.pattern);
114109

115-
generator.writeKey("replacement");
116-
generator.write(this.replacement);
110+
if (this.replacement != null) {
111+
generator.writeKey("replacement");
112+
generator.write(this.replacement);
113+
}
117114

115+
if (this.flags != null) {
116+
generator.writeKey("flags");
117+
generator.write(this.flags);
118+
}
118119
}
119120

120121
// ---------------------------------------------------------------------------------------------
@@ -129,6 +130,7 @@ public static class Builder extends CharFilterBase.AbstractBuilder<Builder> impl
129130

130131
private String pattern;
131132

133+
@Nullable
132134
private String replacement;
133135

134136
/**
@@ -148,9 +150,9 @@ public final Builder pattern(String value) {
148150
}
149151

150152
/**
151-
* Required - API name: {@code replacement}
153+
* API name: {@code replacement}
152154
*/
153-
public final Builder replacement(String value) {
155+
public final Builder replacement(@Nullable String value) {
154156
this.replacement = value;
155157
return this;
156158
}

java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/PatternReplaceCharFilterTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
public class PatternReplaceCharFilterTest {
1919
@Test
2020
public void testCreatePatternReplaceCharFilter() {
21+
PatternReplaceCharFilter patternReplaceCharFilter = new PatternReplaceCharFilter.Builder().pattern("pattern").build();
22+
assertEquals("pattern", patternReplaceCharFilter.pattern());
23+
}
24+
25+
@Test
26+
public void testCreatePatternReplaceCharFilterWithReplacement() {
2127
PatternReplaceCharFilter patternReplaceCharFilter = new PatternReplaceCharFilter.Builder().pattern("pattern")
2228
.replacement("replacement")
2329
.build();

0 commit comments

Comments
 (0)