From 329fa95a0f9caa2e30df2504c16da70314eecae6 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Wed, 2 Oct 2024 10:31:33 +1300 Subject: [PATCH] [Backport 2.x] Codegen equals & hashCode (#1217) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Generate hashCode and equals (#1201) * Generate hashCode and equals , wip Signed-off-by: miguel-vila * add changelog entry Signed-off-by: miguel-vila * remove change Signed-off-by: miguel-vila * take into account primitives Signed-off-by: miguel-vila * refactor and format Signed-off-by: miguel-vila * use Object.equals Co-authored-by: Thomas Farr Signed-off-by: Miguel Vilá * use `&&` chain Signed-off-by: miguel-vila * adjust last line Signed-off-by: miguel-vila * use fqn Signed-off-by: miguel-vila * use fqn for Objects.hashCode, take into account parent Signed-off-by: miguel-vila * remove unused var definition Signed-off-by: miguel-vila * codegen equals/hashCode for request shapes Signed-off-by: miguel-vila * add hashCode/equals to TaggedUnion Signed-off-by: miguel-vila * use import Signed-off-by: miguel-vila * fix equals for request shapes Signed-off-by: miguel-vila * codegen latest from main Signed-off-by: miguel-vila --------- Signed-off-by: miguel-vila Signed-off-by: Miguel Vilá Co-authored-by: Thomas Farr Signed-off-by: Thomas Farr (cherry picked from commit 18a84604c74c945c2a08e1228b89b04d64d0db5e) * Re-run codegen (#1216) * Re-run codegen Signed-off-by: Thomas Farr * Improve null handling Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr (cherry picked from commit 897cc9bb34d05dd852b1a0b2fcd5621d9bd81628) --- CHANGELOG.md | 1 + .../client/opensearch/_types/ErrorCause.java | 35 ++++++++++++++++ .../opensearch/_types/ShardFailure.java | 25 +++++++++++ .../opensearch/_types/ShardStatistics.java | 31 ++++++++++++++ .../opensearch/_types/WriteResponseBase.java | 37 +++++++++++++++++ .../client/opensearch/ml/Action.java | 26 ++++++++++++ .../client/opensearch/ml/ClientConfig.java | 26 ++++++++++++ .../opensearch/ml/CreateConnectorRequest.java | 41 +++++++++++++++++++ .../ml/CreateConnectorResponse.java | 14 +++++++ .../client/opensearch/ml/Credential.java | 23 +++++++++++ .../opensearch/ml/DeleteAgentRequest.java | 16 ++++++++ .../opensearch/ml/DeleteAgentResponse.java | 14 +++++++ .../opensearch/ml/DeleteConnectorRequest.java | 16 ++++++++ .../ml/DeleteConnectorResponse.java | 14 +++++++ .../ml/DeleteModelGroupRequest.java | 16 ++++++++ .../ml/DeleteModelGroupResponse.java | 14 +++++++ .../opensearch/ml/DeleteModelRequest.java | 16 ++++++++ .../opensearch/ml/DeleteModelResponse.java | 14 +++++++ .../opensearch/ml/DeleteTaskRequest.java | 16 ++++++++ .../opensearch/ml/DeleteTaskResponse.java | 14 +++++++ .../opensearch/ml/DeployModelRequest.java | 16 ++++++++ .../opensearch/ml/DeployModelResponse.java | 21 ++++++++++ .../opensearch/ml/GetModelGroupRequest.java | 16 ++++++++ .../opensearch/ml/GetModelGroupResponse.java | 31 ++++++++++++++ .../client/opensearch/ml/GetTaskRequest.java | 16 ++++++++ .../client/opensearch/ml/GetTaskResponse.java | 37 +++++++++++++++++ .../client/opensearch/ml/Headers.java | 18 ++++++++ .../opensearch/client/opensearch/ml/LLM.java | 18 ++++++++ .../client/opensearch/ml/Memory.java | 14 +++++++ .../opensearch/ml/RegisterAgentsRequest.java | 37 +++++++++++++++++ .../opensearch/ml/RegisterAgentsResponse.java | 14 +++++++ .../ml/RegisterModelGroupRequest.java | 27 ++++++++++++ .../ml/RegisterModelGroupResponse.java | 19 +++++++++ .../opensearch/ml/RegisterModelRequest.java | 29 +++++++++++++ .../opensearch/ml/RegisterModelResponse.java | 19 +++++++++ .../client/opensearch/ml/ToolItems.java | 25 +++++++++++ .../opensearch/ml/UndeployModelNode.java | 17 ++++++++ .../opensearch/ml/UndeployModelRequest.java | 16 ++++++++ .../opensearch/ml/UndeployModelResponse.java | 17 ++++++++ .../client/codegen/model/ObjectShape.java | 4 ++ .../client/codegen/model/RequestShape.java | 4 ++ .../opensearch/client/codegen/model/Type.java | 25 ++++++----- .../client/codegen/model/Types.java | 2 + .../codegen/templates/ObjectShape.mustache | 6 ++- .../templates/ObjectShape/Equals.mustache | 32 +++++++++++++++ .../ObjectShape/FieldNullability.mustache | 13 ++++++ .../templates/ObjectShape/Fields.mustache | 6 +-- .../templates/ObjectShape/Getters.mustache | 6 +-- .../templates/ObjectShape/HashCode.mustache | 23 +++++++++++ .../codegen/templates/RequestShape.mustache | 6 ++- .../templates/TaggedUnionShape.mustache | 4 ++ .../TaggedUnionShape/Equals.mustache | 6 +++ .../TaggedUnionShape/HashCode.mustache | 6 +++ .../templates/Type/deserializer.mustache | 20 ++++++--- .../templates/Type/directSerializer.mustache | 17 +++++--- .../templates/Type/queryParamify.mustache | 8 ++-- 56 files changed, 964 insertions(+), 40 deletions(-) create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/FieldNullability.mustache create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Equals.mustache create mode 100644 java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/HashCode.mustache diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d3fd71b5..4687e56ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased 2.x] ### Added +- Add `hashCode` and `equals` implementations ([#312](https://github.com/opensearch-project/opensearch-java/pull/312)). ### Dependencies - Bumps `org.junit:junit-bom` from 5.10.3 to 5.11.1 diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java index c029456c39..36a0c74b71 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ErrorCause.java @@ -40,8 +40,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonpDeserializable; @@ -66,15 +68,19 @@ public class ErrorCause implements PlainJsonSerializable { @Nullable private final String reason; + @Nonnull private final List rootCause; @Nullable private final String stackTrace; + @Nonnull private final List suppressed; + @Nonnull private final String type; + @Nonnull private final Map metadata; // --------------------------------------------------------------------------------------------- @@ -115,6 +121,7 @@ public final String reason() { /** * API name: {@code root_cause} */ + @Nonnull public final List rootCause() { return this.rootCause; } @@ -133,6 +140,7 @@ public final String stackTrace() { /** * API name: {@code suppressed} */ + @Nonnull public final List suppressed() { return this.suppressed; } @@ -143,6 +151,7 @@ public final List suppressed() { * API name: {@code type} *

*/ + @Nonnull public final String type() { return this.type; } @@ -150,6 +159,7 @@ public final String type() { /** * Additional details about the error. */ + @Nonnull public final Map metadata() { return this.metadata; } @@ -404,4 +414,29 @@ protected static void setupErrorCauseDeserializer(ObjectDeserializer failures; @Nullable private final Number skipped; + @Nonnull private final Number successful; + @Nonnull private final Number total; // --------------------------------------------------------------------------------------------- @@ -85,6 +91,7 @@ public static ShardStatistics of(Function failures() { return this.failures; } @@ -107,6 +115,7 @@ public final Number skipped() { /** * Required - API name: {@code successful} */ + @Nonnull public final Number successful() { return this.successful; } @@ -114,6 +123,7 @@ public final Number successful() { /** * Required - API name: {@code total} */ + @Nonnull public final Number total() { return this.total; } @@ -263,4 +273,25 @@ protected static void setupShardStatisticsDeserializer(ObjectDeserializer> void setupWriteRes op.add(AbstractBuilder::shards, ShardStatistics._DESERIALIZER, "_shards"); op.add(AbstractBuilder::version, JsonpDeserializer.longDeserializer(), "_version"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.forcedRefresh); + result = 31 * result + this.id.hashCode(); + result = 31 * result + this.index.hashCode(); + result = 31 * result + Long.hashCode(this.primaryTerm); + result = 31 * result + this.result.hashCode(); + result = 31 * result + Long.hashCode(this.seqNo); + result = 31 * result + this.shards.hashCode(); + result = 31 * result + Long.hashCode(this.version); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + WriteResponseBase other = (WriteResponseBase) o; + return Objects.equals(this.forcedRefresh, other.forcedRefresh) + && this.id.equals(other.id) + && this.index.equals(other.index) + && this.primaryTerm == other.primaryTerm + && this.result.equals(other.result) + && this.seqNo == other.seqNo + && this.shards.equals(other.shards) + && this.version == other.version; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java index e9912634cc..38e6fa54af 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Action.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -286,4 +287,29 @@ protected static void setupActionDeserializer(ObjectDeserializer op.add(Builder::requestBody, JsonpDeserializer.stringDeserializer(), "request_body"); op.add(Builder::url, JsonpDeserializer.stringDeserializer(), "url"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.actionType); + result = 31 * result + Objects.hashCode(this.headers); + result = 31 * result + Objects.hashCode(this.method); + result = 31 * result + Objects.hashCode(this.postProcessFunction); + result = 31 * result + Objects.hashCode(this.preProcessFunction); + result = 31 * result + Objects.hashCode(this.requestBody); + result = 31 * result + Objects.hashCode(this.url); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + Action other = (Action) o; + return Objects.equals(this.actionType, other.actionType) + && Objects.equals(this.headers, other.headers) + && Objects.equals(this.method, other.method) + && Objects.equals(this.postProcessFunction, other.postProcessFunction) + && Objects.equals(this.preProcessFunction, other.preProcessFunction) + && Objects.equals(this.requestBody, other.requestBody) + && Objects.equals(this.url, other.url); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java index e3907e7f59..bd03b5ec22 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/ClientConfig.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -279,4 +280,29 @@ protected static void setupClientConfigDeserializer(ObjectDeserializer actions; @Nullable private final ClientConfig clientConfig; + @Nonnull private final Credential credential; + @Nonnull private final String description; + @Nonnull private final String name; + @Nonnull private final Map parameters; + @Nonnull private final String protocol; private final int version; @@ -79,6 +87,7 @@ public static CreateConnectorRequest of(Function actions() { return this.actions; } @@ -94,6 +103,7 @@ public final ClientConfig clientConfig() { /** * Required - API name: {@code credential} */ + @Nonnull public final Credential credential() { return this.credential; } @@ -101,6 +111,7 @@ public final Credential credential() { /** * Required - API name: {@code description} */ + @Nonnull public final String description() { return this.description; } @@ -108,6 +119,7 @@ public final String description() { /** * Required - API name: {@code name} */ + @Nonnull public final String name() { return this.name; } @@ -115,6 +127,7 @@ public final String name() { /** * Required - API name: {@code parameters} */ + @Nonnull public final Map parameters() { return this.parameters; } @@ -122,6 +135,7 @@ public final Map parameters() { /** * Required - API name: {@code protocol} */ + @Nonnull public final String protocol() { return this.protocol; } @@ -365,4 +379,31 @@ protected static void setupCreateConnectorRequestDeserializer(ObjectDeserializer true, CreateConnectorResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + this.actions.hashCode(); + result = 31 * result + Objects.hashCode(this.clientConfig); + result = 31 * result + this.credential.hashCode(); + result = 31 * result + this.description.hashCode(); + result = 31 * result + this.name.hashCode(); + result = 31 * result + this.parameters.hashCode(); + result = 31 * result + this.protocol.hashCode(); + result = 31 * result + Integer.hashCode(this.version); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + CreateConnectorRequest other = (CreateConnectorRequest) o; + return this.actions.equals(other.actions) + && Objects.equals(this.clientConfig, other.clientConfig) + && this.credential.equals(other.credential) + && this.description.equals(other.description) + && this.name.equals(other.name) + && this.parameters.equals(other.parameters) + && this.protocol.equals(other.protocol) + && this.version == other.version; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/CreateConnectorResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/CreateConnectorResponse.java index 5bed16c40a..bed71edbbc 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/CreateConnectorResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/CreateConnectorResponse.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -111,4 +112,17 @@ public CreateConnectorResponse build() { protected static void setupCreateConnectorResponseDeserializer(ObjectDeserializer op) { op.add(Builder::connectorId, JsonpDeserializer.stringDeserializer(), "connector_id"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.connectorId); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + CreateConnectorResponse other = (CreateConnectorResponse) o; + return Objects.equals(this.connectorId, other.connectorId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java index 8e32830e5e..ef7dfb84ad 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Credential.java @@ -15,8 +15,10 @@ import jakarta.json.stream.JsonGenerator; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonpDeserializable; @@ -44,6 +46,7 @@ public class Credential implements PlainJsonSerializable { @Nullable private final String sessionToken; + @Nonnull private final Map metadata; // --------------------------------------------------------------------------------------------- @@ -85,6 +88,7 @@ public final String sessionToken() { /** */ + @Nonnull public final Map metadata() { return this.metadata; } @@ -214,4 +218,23 @@ protected static void setupCredentialDeserializer(ObjectDeserializer op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java index 30e0f7d202..eba26ddd93 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteConnectorRequest.java @@ -14,6 +14,7 @@ import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -30,6 +31,7 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class DeleteConnectorRequest extends RequestBase { + @Nonnull private final String connectorId; // --------------------------------------------------------------------------------------------- @@ -45,6 +47,7 @@ public static DeleteConnectorRequest of(Function op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java index 181a605275..e62ba1c38a 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java @@ -14,6 +14,7 @@ import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -30,6 +31,7 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class DeleteModelGroupRequest extends RequestBase { + @Nonnull private final String modelGroupId; // --------------------------------------------------------------------------------------------- @@ -45,6 +47,7 @@ public static DeleteModelGroupRequest of(Function op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java index f9be99c118..70bbbde1ea 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java @@ -14,6 +14,7 @@ import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -30,6 +31,7 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class DeleteModelRequest extends RequestBase { + @Nonnull private final String modelId; // --------------------------------------------------------------------------------------------- @@ -45,6 +47,7 @@ public static DeleteModelRequest of(Function op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java index a378f83fde..24cc8996a9 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java @@ -14,6 +14,7 @@ import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -30,6 +31,7 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class DeleteTaskRequest extends RequestBase { + @Nonnull private final String taskId; // --------------------------------------------------------------------------------------------- @@ -45,6 +47,7 @@ public static DeleteTaskRequest of(Function op) { WriteResponseBase.setupWriteResponseBaseDeserializer(op); } + + public int hashCode() { + int result = super.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + return true; + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java index 2230cb1d82..bf5ec056be 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java @@ -14,6 +14,7 @@ import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -30,6 +31,7 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class DeployModelRequest extends RequestBase { + @Nonnull private final String modelId; // --------------------------------------------------------------------------------------------- @@ -45,6 +47,7 @@ public static DeployModelRequest of(Function */ + @Nonnull public final String access() { return this.access; } @@ -85,6 +91,7 @@ public final Long createdTime() { * API name: {@code description} *

*/ + @Nonnull public final String description() { return this.description; } @@ -113,6 +120,7 @@ public final int latestVersion() { * API name: {@code name} *

*/ + @Nonnull public final String name() { return this.name; } @@ -256,4 +264,27 @@ protected static void setupGetModelGroupResponseDeserializer(ObjectDeserializer< op.add(Builder::latestVersion, JsonpDeserializer.integerDeserializer(), "latest_version"); op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); } + + public int hashCode() { + int result = 17; + result = 31 * result + this.access.hashCode(); + result = 31 * result + Objects.hashCode(this.createdTime); + result = 31 * result + this.description.hashCode(); + result = 31 * result + Objects.hashCode(this.lastUpdatedTime); + result = 31 * result + Integer.hashCode(this.latestVersion); + result = 31 * result + this.name.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + GetModelGroupResponse other = (GetModelGroupResponse) o; + return this.access.equals(other.access) + && Objects.equals(this.createdTime, other.createdTime) + && this.description.equals(other.description) + && Objects.equals(this.lastUpdatedTime, other.lastUpdatedTime) + && this.latestVersion == other.latestVersion + && this.name.equals(other.name); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java index 55f09a5df6..664c9b3d31 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java @@ -14,6 +14,7 @@ import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -30,6 +31,7 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class GetTaskRequest extends RequestBase { + @Nonnull private final String taskId; // --------------------------------------------------------------------------------------------- @@ -45,6 +47,7 @@ public static GetTaskRequest of(Function> workerNode; // --------------------------------------------------------------------------------------------- @@ -131,6 +135,7 @@ public final String modelId() { /** * Required - API name: {@code state} */ + @Nonnull public final String state() { return this.state; } @@ -157,6 +162,7 @@ public final String taskType() { /** * API name: {@code worker_node} */ + @Nonnull public final List> workerNode() { return this.workerNode; } @@ -392,4 +398,35 @@ protected static void setupGetTaskResponseDeserializer(ObjectDeserializer metadata; // --------------------------------------------------------------------------------------------- @@ -61,6 +64,7 @@ public final String contentType() { /** */ + @Nonnull public final Map metadata() { return this.metadata; } @@ -158,4 +162,18 @@ protected static void setupHeadersDeserializer(ObjectDeserializer parameters; // --------------------------------------------------------------------------------------------- @@ -61,6 +64,7 @@ public final String modelId() { /** * API name: {@code parameters} */ + @Nonnull public final Map parameters() { return this.parameters; } @@ -158,4 +162,18 @@ protected static void setupLLMDeserializer(ObjectDeserializer op) { op.add(Builder::modelId, JsonpDeserializer.stringDeserializer(), "model_id"); op.add(Builder::parameters, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "parameters"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.modelId); + result = 31 * result + Objects.hashCode(this.parameters); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + LLM other = (LLM) o; + return Objects.equals(this.modelId, other.modelId) && Objects.equals(this.parameters, other.parameters); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java index dfc0a9083c..0660178e13 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/Memory.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -111,4 +112,17 @@ public Memory build() { protected static void setupMemoryDeserializer(ObjectDeserializer op) { op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.type); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + Memory other = (Memory) o; + return Objects.equals(this.type, other.type); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java index 155e0de881..2c2e560a6d 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsRequest.java @@ -15,8 +15,10 @@ import jakarta.json.stream.JsonGenerator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonpDeserializable; @@ -54,12 +56,16 @@ public class RegisterAgentsRequest extends RequestBase implements PlainJsonSeria @Nullable private final Memory memory; + @Nonnull private final String name; + @Nonnull private final Map parameters; + @Nonnull private final List tools; + @Nonnull private final String type; // --------------------------------------------------------------------------------------------- @@ -114,6 +120,7 @@ public final Memory memory() { /** * Required - API name: {@code name} */ + @Nonnull public final String name() { return this.name; } @@ -121,6 +128,7 @@ public final String name() { /** * API name: {@code parameters} */ + @Nonnull public final Map parameters() { return this.parameters; } @@ -128,6 +136,7 @@ public final Map parameters() { /** * API name: {@code tools} */ + @Nonnull public final List tools() { return this.tools; } @@ -135,6 +144,7 @@ public final List tools() { /** * Required - API name: {@code type} */ + @Nonnull public final String type() { return this.type; } @@ -386,4 +396,31 @@ protected static void setupRegisterAgentsRequestDeserializer(ObjectDeserializer< true, RegisterAgentsResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.appType); + result = 31 * result + Objects.hashCode(this.description); + result = 31 * result + Objects.hashCode(this.llm); + result = 31 * result + Objects.hashCode(this.memory); + result = 31 * result + this.name.hashCode(); + result = 31 * result + Objects.hashCode(this.parameters); + result = 31 * result + Objects.hashCode(this.tools); + result = 31 * result + this.type.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + RegisterAgentsRequest other = (RegisterAgentsRequest) o; + return Objects.equals(this.appType, other.appType) + && Objects.equals(this.description, other.description) + && Objects.equals(this.llm, other.llm) + && Objects.equals(this.memory, other.memory) + && this.name.equals(other.name) + && Objects.equals(this.parameters, other.parameters) + && Objects.equals(this.tools, other.tools) + && this.type.equals(other.type); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java index e69ff9e0de..b15475a2aa 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterAgentsResponse.java @@ -13,6 +13,7 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nullable; @@ -111,4 +112,17 @@ public RegisterAgentsResponse build() { protected static void setupRegisterAgentsResponseDeserializer(ObjectDeserializer op) { op.add(Builder::agentId, JsonpDeserializer.stringDeserializer(), "agent_id"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.agentId); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + RegisterAgentsResponse other = (RegisterAgentsResponse) o; + return Objects.equals(this.agentId, other.agentId); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java index 2cf102fca7..e7bc41bb13 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java @@ -14,8 +14,10 @@ import jakarta.json.stream.JsonGenerator; import java.util.List; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -46,11 +48,13 @@ public class RegisterModelGroupRequest extends RequestBase implements PlainJsonS @Nullable private final Boolean addAllBackendRoles; + @Nonnull private final List backendRoles; @Nullable private final String description; + @Nonnull private final String name; // --------------------------------------------------------------------------------------------- @@ -95,6 +99,7 @@ public final Boolean addAllBackendRoles() { * API name: {@code backend_roles} *

*/ + @Nonnull public final List backendRoles() { return this.backendRoles; } @@ -116,6 +121,7 @@ public final String description() { * API name: {@code name} *

*/ + @Nonnull public final String name() { return this.name; } @@ -294,4 +300,25 @@ protected static void setupRegisterModelGroupRequestDeserializer(ObjectDeseriali true, RegisterModelGroupResponse._DESERIALIZER ); + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.accessMode); + result = 31 * result + Objects.hashCode(this.addAllBackendRoles); + result = 31 * result + Objects.hashCode(this.backendRoles); + result = 31 * result + Objects.hashCode(this.description); + result = 31 * result + this.name.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + RegisterModelGroupRequest other = (RegisterModelGroupRequest) o; + return Objects.equals(this.accessMode, other.accessMode) + && Objects.equals(this.addAllBackendRoles, other.addAllBackendRoles) + && Objects.equals(this.backendRoles, other.backendRoles) + && Objects.equals(this.description, other.description) + && this.name.equals(other.name); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java index 240993a8c8..ac99154507 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java @@ -15,6 +15,7 @@ import jakarta.json.stream.JsonGenerator; import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; @@ -31,8 +32,10 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class RegisterModelGroupResponse implements PlainJsonSerializable { + @Nonnull private final String modelGroupId; + @Nonnull private final String status; // --------------------------------------------------------------------------------------------- @@ -54,6 +57,7 @@ public static RegisterModelGroupResponse of( * API name: {@code model_group_id} *

*/ + @Nonnull public final String modelGroupId() { return this.modelGroupId; } @@ -64,6 +68,7 @@ public final String modelGroupId() { * API name: {@code status} *

*/ + @Nonnull public final String status() { return this.status; } @@ -143,4 +148,18 @@ protected static void setupRegisterModelGroupResponseDeserializer(ObjectDeserial op.add(Builder::modelGroupId, JsonpDeserializer.stringDeserializer(), "model_group_id"); op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status"); } + + public int hashCode() { + int result = 17; + result = 31 * result + this.modelGroupId.hashCode(); + result = 31 * result + this.status.hashCode(); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + RegisterModelGroupResponse other = (RegisterModelGroupResponse) o; + return this.modelGroupId.equals(other.modelGroupId) && this.status.equals(other.status); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java index 98fb7909fd..5261601622 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java @@ -13,8 +13,10 @@ package org.opensearch.client.opensearch.ml; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -42,13 +44,16 @@ public class RegisterModelRequest extends RequestBase implements PlainJsonSerial @Nullable private final String description; + @Nonnull private final String modelFormat; @Nullable private final String modelGroupId; + @Nonnull private final String name; + @Nonnull private final String version; // --------------------------------------------------------------------------------------------- @@ -82,6 +87,7 @@ public final String description() { * API name: {@code model_format} *

*/ + @Nonnull public final String modelFormat() { return this.modelFormat; } @@ -103,6 +109,7 @@ public final String modelGroupId() { * API name: {@code name} *

*/ + @Nonnull public final String name() { return this.name; } @@ -113,6 +120,7 @@ public final String name() { * API name: {@code version} *

*/ + @Nonnull public final String version() { return this.version; } @@ -262,4 +270,25 @@ protected static void setupRegisterModelRequestDeserializer(ObjectDeserializer parameters; @Nullable private final String type; + @Nonnull private final Map metadata; // --------------------------------------------------------------------------------------------- @@ -69,6 +73,7 @@ public final String name() { /** * API name: {@code parameters} */ + @Nonnull public final Map parameters() { return this.parameters; } @@ -83,6 +88,7 @@ public final String type() { /** */ + @Nonnull public final Map metadata() { return this.metadata; } @@ -233,4 +239,23 @@ protected static void setupToolItemsDeserializer(ObjectDeserializer stats; // --------------------------------------------------------------------------------------------- @@ -49,6 +52,7 @@ public static UndeployModelNode of(Function stats() { return this.stats; } @@ -133,4 +137,17 @@ public UndeployModelNode build() { protected static void setupUndeployModelNodeDeserializer(ObjectDeserializer op) { op.add(Builder::stats, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "stats"); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.stats); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + UndeployModelNode other = (UndeployModelNode) o; + return Objects.equals(this.stats, other.stats); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java index 4ae83cb5b5..5c5a4a4eed 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java @@ -14,6 +14,7 @@ import java.util.function.Function; import javax.annotation.Generated; +import javax.annotation.Nonnull; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.RequestBase; import org.opensearch.client.transport.Endpoint; @@ -30,6 +31,7 @@ @Generated("org.opensearch.client.codegen.CodeGenerator") public class UndeployModelRequest extends RequestBase { + @Nonnull private final String modelId; // --------------------------------------------------------------------------------------------- @@ -45,6 +47,7 @@ public static UndeployModelRequest of(Function nodes; // --------------------------------------------------------------------------------------------- @@ -48,6 +51,7 @@ public static UndeployModelResponse of(Function nodes() { return this.nodes; } @@ -140,4 +144,17 @@ protected static void setupUndeployModelResponseDeserializer(ObjectDeserializer< builder.nodes.put(name, UndeployModelNode._DESERIALIZER.deserialize(parser, mapper)); }); } + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.nodes); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + UndeployModelResponse other = (UndeployModelResponse) o; + return Objects.equals(this.nodes, other.nodes); + } } 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 75b82438f1..32ba374de0 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 @@ -55,6 +55,10 @@ public boolean hasFieldsToSerialize() { return !bodyFields.isEmpty() || additionalPropertiesField != null; } + public boolean hasFields() { + return !bodyFields.isEmpty() || additionalPropertiesField != null; + } + public Collection getImplementsTypes() { return hasFieldsToSerialize() && !extendsOtherShape() ? List.of(Types.Client.Json.PlainJsonSerializable) : null; } 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 18facfd53e..d76a67d2fe 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 @@ -151,6 +151,10 @@ public boolean hasAnyRequiredFields() { return fields.values().stream().anyMatch(Field::isRequired); } + public boolean hasFields() { + return !fields.isEmpty(); + } + public Type getJsonEndpointType() { return Types.Client.Transport.JsonEndpoint(getType(), getResponseType(), Types.Client.OpenSearch._Types.ErrorResponse); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java index 2e4391b787..f46c3f0306 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java @@ -23,25 +23,16 @@ import org.opensearch.client.codegen.utils.Strings; public class Type { - private static final Set PRIMITIVES = Set.of( - "String", - "boolean", + private static final Set PRIMITIVES = Set.of("boolean", "char", "byte", "short", "int", "long", "float", "double"); + private static final Set BOXED_PRIMITIVES = Set.of( "Boolean", - "char", "Character", - "byte", "Byte", - "short", "Short", - "int", "Integer", - "long", "Long", - "float", "Float", - "double", - "Double", - "Number" + "Double" ); @Nonnull @@ -157,6 +148,14 @@ public boolean isPrimitive() { return PRIMITIVES.contains(name); } + public boolean isBoxedPrimitive() { + return BOXED_PRIMITIVES.contains(name); + } + + public boolean isPotentiallyBoxedPrimitive() { + return isPrimitive() || isBoxedPrimitive(); + } + public boolean isNumber() { return "Number".equals(name); } @@ -170,7 +169,7 @@ public boolean isTime() { } public boolean isBuiltIn() { - return isListOrMap() || isPrimitive() || "JsonData".equals(name); + return isPrimitive() || (packageName != null && packageName.startsWith("java.")) || "JsonData".equals(name); } public boolean hasBuilder() { diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java index 8d522a11f1..aff4712672 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Types.java @@ -72,6 +72,7 @@ public static final class Lang { public static final class Util { public static final String PACKAGE = Java.PACKAGE + ".util"; + public static final Type Objects = Type.builder().withPackage(PACKAGE).withName("Objects").build(); public static final Type HashMap = Type.builder().withPackage(PACKAGE).withName("HashMap").build(); public static Type Map(Type keyType, Type valueType) { @@ -122,6 +123,7 @@ public static final class Javax { public static final class Annotation { public static final String PACKAGE = Javax.PACKAGE + ".annotation"; public static final Type Generated = Type.builder().withPackage(PACKAGE).withName("Generated").build(); + public static final Type Nonnull = Type.builder().withPackage(PACKAGE).withName("Nonnull").build(); public static final Type Nullable = Type.builder().withPackage(PACKAGE).withName("Nullable").build(); } } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache index 627af1db03..0cd936e3b4 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape.mustache @@ -19,4 +19,8 @@ // --------------------------------------------------------------------------------------------- {{>ObjectShape/Deserialize}} -} \ No newline at end of file + + {{>ObjectShape/HashCode}} + + {{>ObjectShape/Equals}} +} diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache new file mode 100644 index 0000000000..1670834380 --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Equals.mustache @@ -0,0 +1,32 @@ + public boolean equals(Object o) { + {{#extendsOtherShape}} + if(!super.equals(o)) { + return false; + } + {{/extendsOtherShape}} + if(this == o) return true; + if(o == null || this.getClass() != o.getClass()) return false; + {{^hasFields}} + return true; + {{/hasFields}} + {{#hasFields}} + {{className}} other = ({{className}})o; + return + {{#fields}} + {{#required}} + {{#type.isPrimitive}} + this.{{name}} == other.{{name}} + {{/type.isPrimitive}} + {{^type.isPrimitive}} + this.{{name}}.equals(other.{{name}}) + {{/type.isPrimitive}} + {{/required}} + {{^required}} + {{TYPES.Java.Util.Objects}}.equals(this.{{name}}, other.{{name}}) + {{/required}} + {{^-last}} + && + {{/-last}} + {{/fields}}; + {{/hasFields}} + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/FieldNullability.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/FieldNullability.mustache new file mode 100644 index 0000000000..f9739563bb --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/FieldNullability.mustache @@ -0,0 +1,13 @@ +{{#type.isListOrMap}} + @{{TYPES.Javax.Annotation.Nonnull}} +{{/type.isListOrMap}} +{{^type.isListOrMap}} + {{#required}} + {{^type.isPrimitive}} + @{{TYPES.Javax.Annotation.Nonnull}} + {{/type.isPrimitive}} + {{/required}} + {{^required}} + @{{TYPES.Javax.Annotation.Nullable}} + {{/required}} +{{/type.isListOrMap}} \ No newline at end of file diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Fields.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Fields.mustache index bd320a391b..7e3bea7471 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Fields.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Fields.mustache @@ -3,10 +3,6 @@ {{/-first}} {{#deprecation}}@Deprecated{{/deprecation}} -{{^required}} -{{^type.isListOrMap}} - @{{TYPES.Javax.Annotation.Nullable}} -{{/type.isListOrMap}} -{{/required}} + {{>ObjectShape/FieldNullability}} private final {{type}} {{name}}; {{/fields}} diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Getters.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Getters.mustache index 61fea36e57..b9742a7b13 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Getters.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/Getters.mustache @@ -2,11 +2,7 @@ {{>ObjectShape/FieldDoc/Basic}} {{#deprecation}}@Deprecated{{/deprecation}} - {{^required}} - {{^type.isListOrMap}} - @{{TYPES.Javax.Annotation.Nullable}} - {{/type.isListOrMap}} - {{/required}} + {{>ObjectShape/FieldNullability}} public final {{type}} {{name}}() { return this.{{name}}; } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache new file mode 100644 index 0000000000..d14479eb81 --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/ObjectShape/HashCode.mustache @@ -0,0 +1,23 @@ + public int hashCode() { + {{#extendsOtherShape}} + int result = super.hashCode(); + {{/extendsOtherShape}} + {{^extendsOtherShape}} + int result = 17; + {{/extendsOtherShape}} + {{#fields}} + result = 31 * result + + {{#required}} + {{#type.isPrimitive}} + {{type.boxed}}.hashCode(this.{{name}}); + {{/type.isPrimitive}} + {{^type.isPrimitive}} + this.{{name}}.hashCode(); + {{/type.isPrimitive}} + {{/required}} + {{^required}} + {{TYPES.Java.Util.Objects}}.hashCode(this.{{name}}); + {{/required}} + {{/fields}} + return result; + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache index 73c0960fea..f73f6dd4a2 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/RequestShape.mustache @@ -96,4 +96,8 @@ {{hasRequestBody}}, {{responseType}}._DESERIALIZER ); -} \ No newline at end of file + + {{>ObjectShape/HashCode}} + + {{>ObjectShape/Equals}} +} diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache index 236daf9abb..8a584d6812 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache @@ -111,4 +111,8 @@ } public static final {{TYPES.Client.Json.JsonpDeserializer}}<{{className}}> _DESERIALIZER = {{TYPES.Client.Json.JsonpDeserializer}}.lazy({{className}}::build{{className}}Deserializer); + + {{>TaggedUnionShape/HashCode}} + + {{>TaggedUnionShape/Equals}} } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Equals.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Equals.mustache new file mode 100644 index 0000000000..ece94de59b --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Equals.mustache @@ -0,0 +1,6 @@ + public boolean equals(Object o) { + if(this == o) return true; + if(o == null || this.getClass() != o.getClass()) return false; + {{className}} other = ({{className}})o; + return {{TYPES.Java.Util.Objects}}.equals(this._kind, other._kind) && {{TYPES.Java.Util.Objects}}.equals(this._value, other._value); + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/HashCode.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/HashCode.mustache new file mode 100644 index 0000000000..eb7a1d39a1 --- /dev/null +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/HashCode.mustache @@ -0,0 +1,6 @@ + public int hashCode() { + int result = 17; + result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._kind); + result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._value); + return result; + } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/deserializer.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/deserializer.mustache index 61fb38b72b..25d0754571 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/deserializer.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/deserializer.mustache @@ -1,7 +1,7 @@ -{{#isPrimitive}} +{{#isPotentiallyBoxedPrimitive}} {{TYPES.Client.Json.JsonpDeserializer}}.{{#toLower}}{{boxed.name}}{{/toLower}}Deserializer() -{{/isPrimitive}} -{{^isPrimitive}} +{{/isPotentiallyBoxedPrimitive}} +{{^isPotentiallyBoxedPrimitive}} {{#isList}} {{TYPES.Client.Json.JsonpDeserializer}}.arrayDeserializer({{#listValueType}}{{>Type/deserializer}}{{/listValueType}}) {{/isList}} @@ -9,6 +9,16 @@ {{TYPES.Client.Json.JsonpDeserializer}}.stringMapDeserializer({{#mapValueType}}{{>Type/deserializer}}{{/mapValueType}}) {{/isMap}} {{^isListOrMap}} - {{name}}._DESERIALIZER + {{#isNumber}} + {{TYPES.Client.Json.JsonpDeserializer}}.numberDeserializer() + {{/isNumber}} + {{^isNumber}} + {{#isString}} + {{TYPES.Client.Json.JsonpDeserializer}}.stringDeserializer() + {{/isString}} + {{^isString}} + {{name}}._DESERIALIZER + {{/isString}} + {{/isNumber}} {{/isListOrMap}} -{{/isPrimitive}} \ No newline at end of file +{{/isPotentiallyBoxedPrimitive}} \ No newline at end of file diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/directSerializer.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/directSerializer.mustache index f8c2fb10cd..34f4345fca 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/directSerializer.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/directSerializer.mustache @@ -10,15 +10,20 @@ } {{/type.isList}} {{^type.isListOrMap}} - {{#type.isPrimitive}} + {{#type.isPotentiallyBoxedPrimitive}} + generator.write({{value}}); + {{/type.isPotentiallyBoxedPrimitive}} + {{^type.isPotentiallyBoxedPrimitive}} {{#type.isNumber}} generator.write({{value}}.doubleValue()); {{/type.isNumber}} {{^type.isNumber}} - generator.write({{value}}); + {{#type.isString}} + generator.write({{value}}); + {{/type.isString}} + {{^type.isString}} + {{value}}.serialize(generator, mapper); + {{/type.isString}} {{/type.isNumber}} - {{/type.isPrimitive}} - {{^type.isPrimitive}} - {{value}}.serialize(generator, mapper); - {{/type.isPrimitive}} + {{/type.isPotentiallyBoxedPrimitive}} {{/type.isListOrMap}} \ No newline at end of file diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/queryParamify.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/queryParamify.mustache index 1abc099c55..ebdacdc7ae 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/queryParamify.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Type/queryParamify.mustache @@ -6,10 +6,10 @@ {{value}}.jsonValue() {{/type.isEnum}} {{^type.isEnum}} - {{#type.isPrimitive}} + {{#type.isPotentiallyBoxedPrimitive}} String.valueOf({{value}}) - {{/type.isPrimitive}} - {{^type.isPrimitive}} + {{/type.isPotentiallyBoxedPrimitive}} + {{^type.isPotentiallyBoxedPrimitive}} {{#type.isList}} {{#type.listValueType.isString}} String.join(",", {{value}}) @@ -24,6 +24,6 @@ {{^type.isList}} {{value}}._toJsonString() {{/type.isList}} - {{/type.isPrimitive}} + {{/type.isPotentiallyBoxedPrimitive}} {{/type.isEnum}} {{/type.isString}}