Skip to content

Commit

Permalink
fix char pattern replace by making replcement optional
Browse files Browse the repository at this point in the history
  • Loading branch information
grouh committed Mar 15, 2024
1 parent 0742ae2 commit 6e3144e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
### Fixed
- Fix integer overflow for variables in indices stats response ([#877](https://github.com/opensearch-project/opensearch-java/pull/877))
- Support weight function in function score query ([#880](https://github.com/opensearch-project/opensearch-java/pull/880))
- Fix pattern replace by making flag optional as on api ([#895](https://github.com/opensearch-project/opensearch-java/pull/895))
- Fix pattern replace by making flag and replacement optional as on api ([#895](https://github.com/opensearch-project/opensearch-java/pull/895))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class PatternReplaceCharFilter extends CharFilterBase implements CharFilt

private final String pattern;

@Nullable
private final String replacement;

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

this.flags = builder.flags;
this.pattern = ApiTypeHelper.requireNonNull(builder.pattern, this, "pattern");
this.replacement = ApiTypeHelper.requireNonNull(builder.replacement, this, "replacement");

this.replacement = builder.replacement;
}

public static PatternReplaceCharFilter of(Function<Builder, ObjectBuilder<PatternReplaceCharFilter>> fn) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public final String pattern() {
}

/**
* Required - API name: {@code replacement}
* API name: {@code replacement}
*/
public final String replacement() {
return this.replacement;
Expand All @@ -104,17 +104,18 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.write("type", "pattern_replace");
super.serializeInternal(generator, mapper);

generator.writeKey("pattern");
generator.write(this.pattern);

if (this.flags != null) {
generator.writeKey("flags");
generator.write(this.flags);
}

generator.writeKey("pattern");
generator.write(this.pattern);

generator.writeKey("replacement");
generator.write(this.replacement);

if (this.flags != null) {
generator.writeKey("replacement");
generator.write(this.replacement);
}
}

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

private String pattern;

@Nullable
private String replacement;

/**
Expand All @@ -148,9 +150,9 @@ public final Builder pattern(String value) {
}

/**
* Required - API name: {@code replacement}
* API name: {@code replacement}
*/
public final Builder replacement(String value) {
public final Builder replacement(@Nullable String value) {
this.replacement = value;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
public class PatternReplaceCharFilterTest {
@Test
public void testCreatePatternReplaceCharFilter() {
PatternReplaceCharFilter patternReplaceCharFilter = new PatternReplaceCharFilter.Builder().pattern("pattern").build();
assertEquals("pattern", patternReplaceCharFilter.pattern());
}

@Test
public void testCreatePatternReplaceCharFilterWithReplacement() {
PatternReplaceCharFilter patternReplaceCharFilter = new PatternReplaceCharFilter.Builder().pattern("pattern")
.replacement("replacement")
.build();
Expand Down

0 comments on commit 6e3144e

Please sign in to comment.