Skip to content

Commit

Permalink
Remove deserializing of path params in request objects
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Dec 18, 2024
1 parent 3a63740 commit a1c5c09
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ protected static void setupAnalyzeRequestDeserializer(ObjectDeserializer<Analyze
op.add(Builder::explain, JsonpDeserializer.booleanDeserializer(), "explain");
op.add(Builder::field, JsonpDeserializer.stringDeserializer(), "field");
op.add(Builder::filter, JsonpDeserializer.arrayDeserializer(TokenFilter._DESERIALIZER), "filter");
op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index");
op.add(Builder::normalizer, JsonpDeserializer.stringDeserializer(), "normalizer");
op.add(Builder::text, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "text");
op.add(Builder::tokenizer, Tokenizer._DESERIALIZER, "tokenizer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ public CreateIndexRequest build() {

protected static void setupCreateIndexRequestDeserializer(ObjectDeserializer<CreateIndexRequest.Builder> op) {
op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(Alias._DESERIALIZER), "aliases");
op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index");
op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings");
op.add(Builder::settings, IndexSettings._DESERIALIZER, "settings");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,9 @@ public PutAliasRequest build() {
protected static void setupPutAliasRequestDeserializer(ObjectDeserializer<PutAliasRequest.Builder> op) {
op.add(Builder::alias, JsonpDeserializer.stringDeserializer(), "alias");
op.add(Builder::filter, Query._DESERIALIZER, "filter");
op.add(Builder::index, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index");
op.add(Builder::indexRouting, JsonpDeserializer.stringDeserializer(), "index_routing");
op.add(Builder::isHidden, JsonpDeserializer.booleanDeserializer(), "is_hidden");
op.add(Builder::isWriteIndex, JsonpDeserializer.booleanDeserializer(), "is_write_index");
op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name");
op.add(Builder::routing, JsonpDeserializer.stringDeserializer(), "routing");
op.add(Builder::searchRouting, JsonpDeserializer.stringDeserializer(), "search_routing");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ protected static void setupPutIndexTemplateRequestDeserializer(ObjectDeserialize
op.add(Builder::dataStream, IndexTemplateDataStreamConfiguration._DESERIALIZER, "data_stream");
op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index_patterns");
op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name");
op.add(Builder::priority, JsonpDeserializer.integerDeserializer(), "priority");
op.add(Builder::template, IndexTemplateMapping._DESERIALIZER, "template");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ protected static void setupPutMappingRequestDeserializer(ObjectDeserializer<PutM
"dynamic_templates"
);
op.add(Builder::fieldNames, FieldNamesField._DESERIALIZER, "_field_names");
op.add(Builder::index, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index");
op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::numericDetection, JsonpDeserializer.booleanDeserializer(), "numeric_detection");
op.add(Builder::properties, JsonpDeserializer.stringMapDeserializer(Property._DESERIALIZER), "properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ protected static void setupPutTemplateRequestDeserializer(ObjectDeserializer<Put
op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(Alias._DESERIALIZER), "aliases");
op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index_patterns");
op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings");
op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name");
op.add(Builder::order, JsonpDeserializer.integerDeserializer(), "order");
op.add(Builder::settings, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "settings");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ protected static void setupSimulateIndexTemplateRequestDeserializer(ObjectDeseri
op.add(Builder::dataStream, IndexTemplateDataStreamConfiguration._DESERIALIZER, "data_stream");
op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index_patterns");
op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name");
op.add(Builder::priority, JsonpDeserializer.integerDeserializer(), "priority");
op.add(Builder::template, IndexTemplateMapping._DESERIALIZER, "template");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,6 @@ public CloneSnapshotRequest build() {

protected static void setupCloneSnapshotRequestDeserializer(ObjectDeserializer<CloneSnapshotRequest.Builder> op) {
op.add(Builder::indices, JsonpDeserializer.stringDeserializer(), "indices");
op.add(Builder::repository, JsonpDeserializer.stringDeserializer(), "repository");
op.add(Builder::snapshot, JsonpDeserializer.stringDeserializer(), "snapshot");
op.add(Builder::targetSnapshot, JsonpDeserializer.stringDeserializer(), "target_snapshot");
}

// ---------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ public CreateRepositoryRequest build() {
);

protected static void setupCreateRepositoryRequestDeserializer(ObjectDeserializer<CreateRepositoryRequest.Builder> op) {
op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name");
op.add(Builder::repository, Repository._DESERIALIZER, "repository");
op.add(Builder::settings, RepositorySettings._DESERIALIZER, "settings");
op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,6 @@ protected static void setupCreateSnapshotRequestDeserializer(ObjectDeserializer<
op.add(Builder::indices, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "indices");
op.add(Builder::metadata, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "metadata");
op.add(Builder::partial, JsonpDeserializer.booleanDeserializer(), "partial");
op.add(Builder::repository, JsonpDeserializer.stringDeserializer(), "repository");
op.add(Builder::snapshot, JsonpDeserializer.stringDeserializer(), "snapshot");
}

// ---------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,6 @@ protected static void setupRestoreSnapshotRequestDeserializer(ObjectDeserializer
op.add(Builder::renameAliasReplacement, JsonpDeserializer.stringDeserializer(), "rename_alias_replacement");
op.add(Builder::renamePattern, JsonpDeserializer.stringDeserializer(), "rename_pattern");
op.add(Builder::renameReplacement, JsonpDeserializer.stringDeserializer(), "rename_replacement");
op.add(Builder::repository, JsonpDeserializer.stringDeserializer(), "repository");
op.add(Builder::snapshot, JsonpDeserializer.stringDeserializer(), "snapshot");
op.add(Builder::sourceRemoteStoreRepository, JsonpDeserializer.stringDeserializer(), "source_remote_store_repository");
op.add(Builder::storageType, JsonpDeserializer.stringDeserializer(), "storage_type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.jsonb.JsonbJsonpMapper;
import org.opensearch.client.opensearch.indices.PutIndexTemplateRequest;

public class PutIndexTemplateRequestTest extends Assert {

// TODO: Allow constructing requests from JSON with required path params
@Ignore
@Test
public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException {
final JsonpMapper mapper = new JsonbJsonpMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.jsonb.JsonbJsonpMapper;
import org.opensearch.client.opensearch.indices.PutTemplateRequest;

public class PutTemplateRequestTest extends Assert {

// TODO: Allow constructing requests from JSON with required path params
@Ignore
@Test
public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException {
final JsonpMapper mapper = new JsonbJsonpMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -104,19 +103,6 @@ public boolean canBeSingleton() {
return !hasRequestBody() && !hasQueryParams() && hasSinglePath() && !getFirstPath().hasParams();
}

@Override
public Collection<Field> getFieldsToDeserialize() {
var fields = new TreeMap<>(bodyFields);
var wireNameSet = bodyFields.values().stream().map(Field::getWireName).collect(Collectors.toSet());
pathParams.forEach((k, v) -> {
if (wireNameSet.contains(v.getWireName())) {
v = v.toBuilder().withWireName(v.getName()).build();
}
fields.put(k, v);
});
return fields.values();
}

@Override
public boolean hasFieldsToSerialize() {
return hasRequestBody();
Expand Down

0 comments on commit a1c5c09

Please sign in to comment.