From f37df1e37d7ceacac9d201a9abbdaef880750349 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Thu, 14 Nov 2024 11:17:01 +1300 Subject: [PATCH] Allow deserializing path params from JSON Signed-off-by: Thomas Farr --- .../client/opensearch/indices/CreateIndexRequest.java | 1 + .../opensearch/indices/PutIndexTemplateRequest.java | 1 + .../opensearch/indices/SimulateIndexTemplateRequest.java | 1 + .../client/opensearch/snapshot/CloneSnapshotRequest.java | 3 +++ .../org/opensearch/client/codegen/model/ObjectShape.java | 8 ++++++++ .../org/opensearch/client/codegen/model/RequestShape.java | 7 +++++++ .../codegen/templates/ObjectShape/Deserialize.mustache | 4 ++-- .../codegen/templates/ObjectShape/Serialize.mustache | 4 ++-- 8 files changed, 25 insertions(+), 4 deletions(-) diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java index 492a2f3931..f6676b3bf2 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java @@ -449,6 +449,7 @@ public CreateIndexRequest build() { protected static void setupCreateIndexRequestDeserializer(ObjectDeserializer 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"); } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java index 6167ed059f..a407a4ab5a 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java @@ -576,6 +576,7 @@ 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"); diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/SimulateIndexTemplateRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/SimulateIndexTemplateRequest.java index 65c378fcff..432d06be65 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/SimulateIndexTemplateRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/SimulateIndexTemplateRequest.java @@ -625,6 +625,7 @@ 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"); diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java index e4ffc8d46a..01a0d9ab0b 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java @@ -304,6 +304,9 @@ public CloneSnapshotRequest build() { protected static void setupCloneSnapshotRequestDeserializer(ObjectDeserializer 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"); } // --------------------------------------------------------------------------------------------- diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java index 558ab68886..12fab62b95 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java @@ -72,10 +72,18 @@ public void setShortcutProperty(String shortcutProperty) { this.shortcutProperty = shortcutProperty; } + public Collection getFieldsToSerialize() { + return getBodyFields(); + } + public boolean hasFieldsToSerialize() { return !bodyFields.isEmpty() || additionalPropertiesField != null; } + public Collection getFieldsToDeserialize() { + return getBodyFields(); + } + public Collection getReferencingDiscriminatedUnions() { return getIncomingReference(ReferenceKind.UnionVariant).stream() .map(s -> (TaggedUnionShape) s) diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java index 2fc4414159..0877974e78 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java @@ -98,6 +98,13 @@ public boolean canBeSingleton() { return !hasRequestBody() && !hasQueryParams() && hasSinglePath() && !getFirstPath().hasParams(); } + @Override + public Collection getFieldsToDeserialize() { + var fields = new TreeMap<>(bodyFields); + fields.putAll(pathParams); + return fields.values(); + } + public boolean hasRequestBody() { return !getBodyFields().isEmpty(); } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Deserialize.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Deserialize.mustache index 4d37bb6a2f..6d3e14591b 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Deserialize.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Deserialize.mustache @@ -14,9 +14,9 @@ {{#extendsOtherShape}} setup{{extendsType.name}}Deserializer(op{{#extendsType.typeParams}}, {{>Type/deserializer}}{{/extendsType.typeParams}}); {{/extendsOtherShape}} - {{#bodyFields}} + {{#fieldsToDeserialize}} op.add({{#extendedByOtherShape}}Abstract{{/extendedByOtherShape}}Builder::{{name}}, {{#type}}{{>Type/deserializer}}{{/type}}, {{#quoted}}{{wireName}}{{/quoted}}{{#aliases}}, {{#quoted}}{{.}}{{/quoted}}{{/aliases}}); - {{/bodyFields}} + {{/fieldsToDeserialize}} {{#additionalPropertiesField}} op.setUnknownFieldHandler((builder, name, parser, mapper) -> { if (builder.{{name}} == null) { diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Serialize.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Serialize.mustache index 130c94bcec..36f3b13dcd 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Serialize.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Serialize.mustache @@ -20,7 +20,7 @@ {{#additionalPropertiesField}} {{#type.directSerializer}}this.{{name}}{{/type.directSerializer}} {{/additionalPropertiesField}} -{{#bodyFields}} +{{#fieldsToSerialize}} {{^required}} if ({{#type.isDefined}}this.{{name}}{{/type.isDefined}}) { {{/required}} @@ -32,5 +32,5 @@ {{^-last}} {{/-last}} -{{/bodyFields}} +{{/fieldsToSerialize}} } \ No newline at end of file