Skip to content

Commit

Permalink
Set 'id' field when deserializing a PutPipelineRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Schlindwein <[email protected]>
Signed-off-by: Patrick Schlindwein <[email protected]>
  • Loading branch information
patschl authored and Patrick Schlindwein committed Dec 31, 2023
1 parent 5239303 commit ab53a74
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
- Fix PutTemplateRequest field deserialization ([#723](https://github.com/opensearch-project/opensearch-java/pull/723))
- Fix PutIndexTemplateRequest field deserialization ([#765](https://github.com/opensearch-project/opensearch-java/pull/765))
- Fix InnerHits storedFields deserialization/serialization ([#781](https://github.com/opensearch-project/opensearch-java/pull/781)
- Fix PutPipelineRequest field deserialization ([#789](https://github.com/opensearch-project/opensearch-java/issues/789)

### Security

Expand Down Expand Up @@ -258,4 +259,4 @@ This section is for maintaining a changelog for all breaking changes for the cli
[2.5.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.4.0...v2.5.0
[2.4.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0
[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ protected static void setupPutPipelineRequestDeserializer(ObjectDeserializer<Put

op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::description, JsonpDeserializer.stringDeserializer(), "description");
op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id");
op.add(Builder::onFailure, JsonpDeserializer.arrayDeserializer(Processor._DESERIALIZER), "on_failure");
op.add(Builder::processors, JsonpDeserializer.arrayDeserializer(Processor._DESERIALIZER), "processors");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.opensearch.client.opensearch.indices.IndexSettingsSearch;
import org.opensearch.client.opensearch.indices.Translog;
import org.opensearch.client.opensearch.indices.get_field_mapping.TypeFieldMappings;
import org.opensearch.client.opensearch.ingest.ConvertType;
import org.opensearch.client.opensearch.ingest.PutPipelineRequest;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class ParsingTests extends ModelTestCase {
Expand Down Expand Up @@ -357,4 +359,29 @@ public void testIndexSettingsSearch() {
assertEquals(search.idle().after().time(), deserialized.idle().after().time());

}

@Test
public void testPutPipelineRequestDeserialization() {
var putPipelineRequest = PutPipelineRequest.of(
b -> b.id("test-pipeline")
.description("pipeline desc")
.processors(p -> p.convert(c -> c.field("age").targetField("age").type(ConvertType.Integer)))
);

var input = "{\"id\":\"test-pipeline\",\"description\":\"pipeline desc\","
+ "\"processors\":[{\"convert\":{\"field\":\"age\",\"target_field\":\"age\",\"type\":\"integer\"}}]}";

var deserialized = fromJson(input, PutPipelineRequest._DESERIALIZER);

assertEquals(putPipelineRequest.id(), deserialized.id());
assertEquals(putPipelineRequest.description(), deserialized.description());
assertEquals(putPipelineRequest.processors().size(), deserialized.processors().size());

var processor = putPipelineRequest.processors().get(0);
var deserializedProcessor = deserialized.processors().get(0);
assertEquals(processor._kind(), deserializedProcessor._kind());
assertEquals(processor.convert().field(), deserializedProcessor.convert().field());
assertEquals(processor.convert().targetField(), deserializedProcessor.convert().targetField());
assertEquals(processor.convert().type(), deserializedProcessor.convert().type());
}
}

0 comments on commit ab53a74

Please sign in to comment.