From 2fa5d0371bd83d7f6acb733835a76adb7a9ec333 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Wed, 9 Oct 2024 18:56:08 +1300 Subject: [PATCH] Generate indices.exists Signed-off-by: Thomas Farr --- .../opensearch/indices/ExistsRequest.java | 211 ++++++++++++------ .../OpenSearchIndicesAsyncClientBase.java | 20 ++ .../indices/OpenSearchIndicesClientBase.java | 20 ++ .../opensearch/indices/ExistsResponse.java | 49 ---- .../indices/OpenSearchIndicesAsyncClient.java | 32 --- .../indices/OpenSearchIndicesClient.java | 32 --- .../transport/endpoints/BooleanEndpoint.java | 9 + .../client/codegen/CodeGenerator.java | 2 +- .../client/codegen/model/RequestShape.java | 13 +- .../client/codegen/model/SpecTransformer.java | 16 +- .../client/codegen/model/Types.java | 134 ++++++----- .../codegen/templates/RequestShape.mustache | 7 +- .../client/samples/knn/KnnScriptScore.java | 1 - 13 files changed, 293 insertions(+), 253 deletions(-) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/indices/ExistsRequest.java (58%) delete mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/indices/ExistsResponse.java diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/ExistsRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/ExistsRequest.java similarity index 58% rename from java-client/src/main/java/org/opensearch/client/opensearch/indices/ExistsRequest.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/indices/ExistsRequest.java index 5cd06ef799..f1427c1225 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/ExistsRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/ExistsRequest.java @@ -30,17 +30,25 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch.indices; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; +import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.opensearch._types.ErrorResponse; import org.opensearch.client.opensearch._types.ExpandWildcard; import org.opensearch.client.opensearch._types.RequestBase; +import org.opensearch.client.opensearch._types.Time; import org.opensearch.client.transport.Endpoint; import org.opensearch.client.transport.endpoints.BooleanEndpoint; import org.opensearch.client.transport.endpoints.BooleanResponse; @@ -53,13 +61,17 @@ /** * Returns information about whether a particular index exists. - * */ - +@Generated("org.opensearch.client.codegen.CodeGenerator") public class ExistsRequest extends RequestBase { + @Nullable private final Boolean allowNoIndices; + @Nullable + private final Time clusterManagerTimeout; + + @Nonnull private final List expandWildcards; @Nullable @@ -71,6 +83,7 @@ public class ExistsRequest extends RequestBase { @Nullable private final Boolean includeDefaults; + @Nonnull private final List index; @Nullable @@ -79,26 +92,26 @@ public class ExistsRequest extends RequestBase { // --------------------------------------------------------------------------------------------- private ExistsRequest(Builder builder) { - this.allowNoIndices = builder.allowNoIndices; + this.clusterManagerTimeout = builder.clusterManagerTimeout; this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards); this.flatSettings = builder.flatSettings; this.ignoreUnavailable = builder.ignoreUnavailable; this.includeDefaults = builder.includeDefaults; this.index = ApiTypeHelper.unmodifiableRequired(builder.index, this, "index"); this.local = builder.local; - } - public static ExistsRequest of(Function> fn) { + public static ExistsRequest of(Function> fn) { return fn.apply(new Builder()).build(); } /** - * Ignore if a wildcard expression resolves to no concrete indices (default: - * false) + * If false, the request returns an error if any wildcard expression, index alias, or _all value targets only + * missing or closed indices. This behavior applies even if the request targets other open indices. *

* API name: {@code allow_no_indices} + *

*/ @Nullable public final Boolean allowNoIndices() { @@ -106,19 +119,34 @@ public final Boolean allowNoIndices() { } /** - * Whether wildcard expressions should get expanded to open or closed indices - * (default: open) + * Operation timeout for connection to cluster-manager node. + *

+ * API name: {@code cluster_manager_timeout} + *

+ */ + @Nullable + public final Time clusterManagerTimeout() { + return this.clusterManagerTimeout; + } + + /** + * Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard + * expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: + * all, open, closed, hidden, none. *

* API name: {@code expand_wildcards} + *

*/ + @Nonnull public final List expandWildcards() { return this.expandWildcards; } /** - * Return settings in flat format (default: false) + * If true, returns settings in flat format. *

* API name: {@code flat_settings} + *

*/ @Nullable public final Boolean flatSettings() { @@ -126,9 +154,10 @@ public final Boolean flatSettings() { } /** - * Ignore unavailable indexes (default: false) + * If false, the request returns an error if it targets a missing or closed index. *

* API name: {@code ignore_unavailable} + *

*/ @Nullable public final Boolean ignoreUnavailable() { @@ -136,9 +165,10 @@ public final Boolean ignoreUnavailable() { } /** - * Whether to return all default setting for each of the indices. + * If true, return all default settings in the response. *

* API name: {@code include_defaults} + *

*/ @Nullable public final Boolean includeDefaults() { @@ -146,19 +176,21 @@ public final Boolean includeDefaults() { } /** - * Required - A comma-separated list of index names + * Required - Comma-separated list of data streams, indices, and aliases. Supports wildcards (*). *

* API name: {@code index} + *

*/ + @Nonnull public final List index() { return this.index; } /** - * Return local information, do not retrieve the state from cluster-manager node - * (default: false) + * If true, the request retrieves information from the local node only. *

* API name: {@code local} + *

*/ @Nullable public final Boolean local() { @@ -170,33 +202,29 @@ public final Boolean local() { /** * Builder for {@link ExistsRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { @Nullable private Boolean allowNoIndices; - + @Nullable + private Time clusterManagerTimeout; @Nullable private List expandWildcards; - @Nullable private Boolean flatSettings; - @Nullable private Boolean ignoreUnavailable; - @Nullable private Boolean includeDefaults; - private List index; - @Nullable private Boolean local; /** - * Ignore if a wildcard expression resolves to no concrete indices (default: - * false) + * If false, the request returns an error if any wildcard expression, index alias, or _all value targets + * only missing or closed indices. This behavior applies even if the request targets other open indices. *

* API name: {@code allow_no_indices} + *

*/ public final Builder allowNoIndices(@Nullable Boolean value) { this.allowNoIndices = value; @@ -204,12 +232,37 @@ public final Builder allowNoIndices(@Nullable Boolean value) { } /** - * Whether wildcard expressions should get expanded to open or closed indices - * (default: open) + * Operation timeout for connection to cluster-manager node. + *

+ * API name: {@code cluster_manager_timeout} + *

+ */ + public final Builder clusterManagerTimeout(@Nullable Time value) { + this.clusterManagerTimeout = value; + return this; + } + + /** + * Operation timeout for connection to cluster-manager node. + *

+ * API name: {@code cluster_manager_timeout} + *

+ */ + public final Builder clusterManagerTimeout(Function> fn) { + return clusterManagerTimeout(fn.apply(new Time.Builder()).build()); + } + + /** + * Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard + * expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: + * all, open, closed, hidden, none. *

* API name: {@code expand_wildcards} + *

+ * *

* Adds all elements of list to expandWildcards. + *

*/ public final Builder expandWildcards(List list) { this.expandWildcards = _listAddAll(this.expandWildcards, list); @@ -217,12 +270,16 @@ public final Builder expandWildcards(List list) { } /** - * Whether wildcard expressions should get expanded to open or closed indices - * (default: open) + * Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard + * expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are: + * all, open, closed, hidden, none. *

* API name: {@code expand_wildcards} + *

+ * *

* Adds one or more values to expandWildcards. + *

*/ public final Builder expandWildcards(ExpandWildcard value, ExpandWildcard... values) { this.expandWildcards = _listAdd(this.expandWildcards, value, values); @@ -230,9 +287,10 @@ public final Builder expandWildcards(ExpandWildcard value, ExpandWildcard... val } /** - * Return settings in flat format (default: false) + * If true, returns settings in flat format. *

* API name: {@code flat_settings} + *

*/ public final Builder flatSettings(@Nullable Boolean value) { this.flatSettings = value; @@ -240,9 +298,10 @@ public final Builder flatSettings(@Nullable Boolean value) { } /** - * Ignore unavailable indexes (default: false) + * If false, the request returns an error if it targets a missing or closed index. *

* API name: {@code ignore_unavailable} + *

*/ public final Builder ignoreUnavailable(@Nullable Boolean value) { this.ignoreUnavailable = value; @@ -250,9 +309,10 @@ public final Builder ignoreUnavailable(@Nullable Boolean value) { } /** - * Whether to return all default setting for each of the indices. + * If true, return all default settings in the response. *

* API name: {@code include_defaults} + *

*/ public final Builder includeDefaults(@Nullable Boolean value) { this.includeDefaults = value; @@ -260,11 +320,14 @@ public final Builder includeDefaults(@Nullable Boolean value) { } /** - * Required - A comma-separated list of index names + * Required - Comma-separated list of data streams, indices, and aliases. Supports wildcards (*). *

* API name: {@code index} + *

+ * *

* Adds all elements of list to index. + *

*/ public final Builder index(List list) { this.index = _listAddAll(this.index, list); @@ -272,11 +335,14 @@ public final Builder index(List list) { } /** - * Required - A comma-separated list of index names + * Required - Comma-separated list of data streams, indices, and aliases. Supports wildcards (*). *

* API name: {@code index} + *

+ * *

* Adds one or more values to index. + *

*/ public final Builder index(String value, String... values) { this.index = _listAdd(this.index, value, values); @@ -284,10 +350,10 @@ public final Builder index(String value, String... values) { } /** - * Return local information, do not retrieve the state from cluster-manager node - * (default: false) + * If true, the request retrieves information from the local node only. *

* API name: {@code local} + *

*/ public final Builder local(@Nullable Boolean value) { this.local = value; @@ -297,8 +363,7 @@ public final Builder local(@Nullable Boolean value) { /** * Builds a {@link ExistsRequest}. * - * @throws NullPointerException - * if some of the required fields are null. + * @throws NullPointerException if some of the required fields are null. */ public ExistsRequest build() { _checkSingleUse(); @@ -313,47 +378,33 @@ public ExistsRequest build() { * Endpoint "{@code indices.exists}". */ public static final Endpoint _ENDPOINT = new BooleanEndpoint<>( - "opensearch/indices.exists", - // Request method - request -> { - return "HEAD"; - - }, - + request -> "HEAD", // Request path request -> { - final int _index = 1 << 0; - - int propsSet = 0; - - propsSet |= _index; - - if (propsSet == (_index)) { - StringBuilder buf = new StringBuilder(); - buf.append("/"); - SimpleEndpoint.pathEncode(request.index.stream().map(v -> v).collect(Collectors.joining(",")), buf); - return buf.toString(); - } - throw SimpleEndpoint.noPathTemplateFound("path"); - + StringBuilder buf = new StringBuilder(); + buf.append("/"); + SimpleEndpoint.pathEncode(String.join(",", request.index), buf); + return buf.toString(); }, - // Request parameters request -> { Map params = new HashMap<>(); - if (request.flatSettings != null) { - params.put("flat_settings", String.valueOf(request.flatSettings)); + if (request.allowNoIndices != null) { + params.put("allow_no_indices", String.valueOf(request.allowNoIndices)); + } + if (request.clusterManagerTimeout != null) { + params.put("cluster_manager_timeout", request.clusterManagerTimeout._toJsonString()); } if (ApiTypeHelper.isDefined(request.expandWildcards)) { params.put("expand_wildcards", request.expandWildcards.stream().map(v -> v.jsonValue()).collect(Collectors.joining(","))); } + if (request.flatSettings != null) { + params.put("flat_settings", String.valueOf(request.flatSettings)); + } if (request.ignoreUnavailable != null) { params.put("ignore_unavailable", String.valueOf(request.ignoreUnavailable)); } - if (request.allowNoIndices != null) { - params.put("allow_no_indices", String.valueOf(request.allowNoIndices)); - } if (request.includeDefaults != null) { params.put("include_defaults", String.valueOf(request.includeDefaults)); } @@ -361,10 +412,34 @@ public ExistsRequest build() { params.put("local", String.valueOf(request.local)); } return params; - }, - SimpleEndpoint.emptyMap(), - false, - null + SimpleEndpoint.emptyMap() ); + + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.allowNoIndices); + result = 31 * result + Objects.hashCode(this.clusterManagerTimeout); + result = 31 * result + Objects.hashCode(this.expandWildcards); + result = 31 * result + Objects.hashCode(this.flatSettings); + result = 31 * result + Objects.hashCode(this.ignoreUnavailable); + result = 31 * result + Objects.hashCode(this.includeDefaults); + result = 31 * result + this.index.hashCode(); + result = 31 * result + Objects.hashCode(this.local); + return result; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + ExistsRequest other = (ExistsRequest) o; + return Objects.equals(this.allowNoIndices, other.allowNoIndices) + && Objects.equals(this.clusterManagerTimeout, other.clusterManagerTimeout) + && Objects.equals(this.expandWildcards, other.expandWildcards) + && Objects.equals(this.flatSettings, other.flatSettings) + && Objects.equals(this.ignoreUnavailable, other.ignoreUnavailable) + && Objects.equals(this.includeDefaults, other.includeDefaults) + && this.index.equals(other.index) + && Objects.equals(this.local, other.local); + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClientBase.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClientBase.java index c2c8de6ef6..960b374709 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClientBase.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClientBase.java @@ -45,6 +45,7 @@ import org.opensearch.client.opensearch._types.OpenSearchException; import org.opensearch.client.transport.OpenSearchTransport; import org.opensearch.client.transport.TransportOptions; +import org.opensearch.client.transport.endpoints.BooleanResponse; import org.opensearch.client.util.ObjectBuilder; /** @@ -58,6 +59,25 @@ public OpenSearchIndicesAsyncClientBase(OpenSearchTransport transport, @Nullable super(transport, transportOptions); } + // ----- Endpoint: indices.exists + + /** + * Returns information about whether a particular index exists. + */ + public CompletableFuture exists(ExistsRequest request) throws IOException, OpenSearchException { + return this.transport.performRequestAsync(request, ExistsRequest._ENDPOINT, this.transportOptions); + } + + /** + * Returns information about whether a particular index exists. + * + * @param fn a function that initializes a builder to create the {@link ExistsRequest} + */ + public final CompletableFuture exists(Function> fn) + throws IOException, OpenSearchException { + return exists(fn.apply(new ExistsRequest.Builder()).build()); + } + // ----- Endpoint: indices.get /** diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClientBase.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClientBase.java index b0d7e141b6..9c2fc174c3 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClientBase.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClientBase.java @@ -44,6 +44,7 @@ import org.opensearch.client.opensearch._types.OpenSearchException; import org.opensearch.client.transport.OpenSearchTransport; import org.opensearch.client.transport.TransportOptions; +import org.opensearch.client.transport.endpoints.BooleanResponse; import org.opensearch.client.util.ObjectBuilder; /** @@ -57,6 +58,25 @@ public OpenSearchIndicesClientBase(OpenSearchTransport transport, @Nullable Tran super(transport, transportOptions); } + // ----- Endpoint: indices.exists + + /** + * Returns information about whether a particular index exists. + */ + public BooleanResponse exists(ExistsRequest request) throws IOException, OpenSearchException { + return this.transport.performRequest(request, ExistsRequest._ENDPOINT, this.transportOptions); + } + + /** + * Returns information about whether a particular index exists. + * + * @param fn a function that initializes a builder to create the {@link ExistsRequest} + */ + public final BooleanResponse exists(Function> fn) throws IOException, + OpenSearchException { + return exists(fn.apply(new ExistsRequest.Builder()).build()); + } + // ----- Endpoint: indices.get /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/ExistsResponse.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/ExistsResponse.java deleted file mode 100644 index 1c51f63584..0000000000 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/ExistsResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -package org.opensearch.client.opensearch.indices; - -import org.opensearch.client.json.JsonpDeserializer; - -// typedef: indices.exists.Response - -public class ExistsResponse { - public ExistsResponse() {} - - /** - * Singleton instance for {@link ExistsResponse}. - */ - public static final ExistsResponse _INSTANCE = new ExistsResponse(); - - public static final JsonpDeserializer _DESERIALIZER = JsonpDeserializer.fixedValue(ExistsResponse._INSTANCE); - -} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClient.java index 0755cbd356..ba06a2da13 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesAsyncClient.java @@ -506,38 +506,6 @@ public final CompletableFuture diskUsage(Function exists(ExistsRequest request) throws IOException, OpenSearchException { - @SuppressWarnings("unchecked") - JsonEndpoint endpoint = (JsonEndpoint< - ExistsRequest, - BooleanResponse, - ErrorResponse>) ExistsRequest._ENDPOINT; - - return this.transport.performRequestAsync(request, endpoint, this.transportOptions); - } - - /** - * Returns information about whether a particular index exists. - * - * @param fn - * a function that initializes a builder to create the - * {@link ExistsRequest} - * - */ - - public final CompletableFuture exists(Function> fn) - throws IOException, OpenSearchException { - return exists(fn.apply(new ExistsRequest.Builder()).build()); - } - // ----- Endpoint: indices.exists_alias /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClient.java index 43e61e0c08..19c6a3c383 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/OpenSearchIndicesClient.java @@ -488,38 +488,6 @@ public final DiskUsageResponse diskUsage(Function endpoint = (JsonEndpoint< - ExistsRequest, - BooleanResponse, - ErrorResponse>) ExistsRequest._ENDPOINT; - - return this.transport.performRequest(request, endpoint, this.transportOptions); - } - - /** - * Returns information about whether a particular index exists. - * - * @param fn - * a function that initializes a builder to create the - * {@link ExistsRequest} - * - */ - - public final BooleanResponse exists(Function> fn) throws IOException, - OpenSearchException { - return exists(fn.apply(new ExistsRequest.Builder()).build()); - } - // ----- Endpoint: indices.exists_alias /** diff --git a/java-client/src/main/java/org/opensearch/client/transport/endpoints/BooleanEndpoint.java b/java-client/src/main/java/org/opensearch/client/transport/endpoints/BooleanEndpoint.java index a6969671ac..70200eaab4 100644 --- a/java-client/src/main/java/org/opensearch/client/transport/endpoints/BooleanEndpoint.java +++ b/java-client/src/main/java/org/opensearch/client/transport/endpoints/BooleanEndpoint.java @@ -38,6 +38,15 @@ public class BooleanEndpoint extends SimpleEndpoint { + public BooleanEndpoint( + Function method, + Function requestUrl, + Function> queryParameters, + Function> headers + ) { + super(method, requestUrl, queryParameters, headers, false, null); + } + public BooleanEndpoint( String id, Function method, diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java b/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java index 8aaa9eb50d..49f222f0d9 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java @@ -43,7 +43,7 @@ public class CodeGenerator { private static final OperationGroupMatcher OPERATION_MATCHER = or( and(namespace(""), named("info")), namespace("dangling_indices"), - and(namespace("indices"), named("get")), + and(namespace("indices"), named("exists", "get")), and(namespace("ml"), not(named("search_models"))), // TODO: search_models is complex and ideally should re-use the search structures and(namespace("snapshot"), named("cleanup_repository", "clone", "verify_repository")), and(namespace("tasks")) 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 f8d270e772..8215e444c9 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 @@ -35,6 +35,7 @@ public class RequestShape extends ObjectShape { private final Map pathParams = new TreeMap<>(); @Nonnull private final Map fields = new TreeMap<>(); + private boolean isBooleanRequest; public RequestShape(@Nonnull Namespace parent, @Nonnull OperationGroup operationGroup, @Nullable String description) { super(parent, requestClassName(operationGroup), operationGroup.asTypedefPrefix() + ".Request", description); @@ -72,8 +73,18 @@ public void addSupportedHttpMethod(String method) { httpMethods.add(method); } + public void setIsBooleanRequest() { + isBooleanRequest = true; + } + + public boolean isBooleanRequest() { + return isBooleanRequest; + } + public Type getResponseType() { - return Type.builder().withPackage(getPackageName()).withName(responseClassName(operationGroup)).build(); + return !isBooleanRequest + ? Type.builder().withPackage(getPackageName()).withName(responseClassName(operationGroup)).build() + : Types.Client.Transport.Endpoints.BooleanResponse; } public boolean canBeSingleton() { diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java index 55203856fb..a631254623 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java @@ -123,10 +123,14 @@ private void visit(@Nonnull OperationGroup group, @Nonnull List c.get(MimeType.Json)) .flatMap(OpenApiMediaType::getSchema) .map(OpenApiSchema::resolve) - .orElse(OpenApiSchema.ANONYMOUS_OBJECT); - - visitInto(bodySchema, shape); + .ifPresent(s -> visitInto(s, shape)); if (shape.getExtendsType() == null) { shape.setExtendsType(Types.Client.OpenSearch._Types.RequestBase); 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 79d82cc30c..aab2d65e5f 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 @@ -39,12 +39,20 @@ private static Map asMap(Class clazz) { return map; } + private static Type type(String name) { + return Type.builder().withName(name).build(); + } + + private static Type type(String packageName, String name) { + return Type.builder().withPackage(packageName).withName(name).build(); + } + public static final class Primitive { - public static final Type Boolean = Type.builder().withName("boolean").build(); - public static final Type Int = Type.builder().withName("int").build(); - public static final Type Long = Type.builder().withName("long").build(); - public static final Type Float = Type.builder().withName("float").build(); - public static final Type Double = Type.builder().withName("double").build(); + public static final Type Boolean = type("boolean"); + public static final Type Int = type("int"); + public static final Type Long = type("long"); + public static final Type Float = type("float"); + public static final Type Double = type("double"); } public static final class Java { @@ -52,59 +60,65 @@ public static final class Java { public static final class Io { public static final String PACKAGE = Java.PACKAGE + ".io"; - public static final Type IOException = Type.builder().withPackage(PACKAGE).withName("IOException").build(); + public static final Type IOException = type(PACKAGE, "IOException"); } public static final class Lang { public static final String PACKAGE = Java.PACKAGE + ".lang"; - public static final Type String = Type.builder().withPackage(PACKAGE).withName("String").build(); - public static final Type Character = Type.builder().withPackage(PACKAGE).withName("Character").build(); - public static final Type Boolean = Type.builder().withPackage(PACKAGE).withName("Boolean").build(); - public static final Type Byte = Type.builder().withPackage(PACKAGE).withName("Byte").build(); - public static final Type Short = Type.builder().withPackage(PACKAGE).withName("Short").build(); - public static final Type Integer = Type.builder().withPackage(PACKAGE).withName("Integer").build(); - public static final Type Long = Type.builder().withPackage(PACKAGE).withName("Long").build(); - public static final Type Float = Type.builder().withPackage(PACKAGE).withName("Float").build(); - public static final Type Double = Type.builder().withPackage(PACKAGE).withName("Double").build(); - public static final Type Object = Type.builder().withPackage(PACKAGE).withName("Object").build(); - public static final Type Number = Type.builder().withPackage(PACKAGE).withName("Number").build(); + public static final Type String = type(PACKAGE, "String"); + public static final Type Character = type(PACKAGE, "Character"); + public static final Type Boolean = type(PACKAGE, "Boolean"); + public static final Type Byte = type(PACKAGE, "Byte"); + public static final Type Short = type(PACKAGE, "Short"); + public static final Type Integer = type(PACKAGE, "Integer"); + public static final Type Long = type(PACKAGE, "Long"); + public static final Type Float = type(PACKAGE, "Float"); + public static final Type Double = type(PACKAGE, "Double"); + public static final Type Object = type(PACKAGE, "Object"); + public static final Type Number = type(PACKAGE, "Number"); } 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 final Type Objects = type(PACKAGE, "Objects"); + public static final Type HashMap = type(PACKAGE, "HashMap"); public static Type Map(Type keyType, Type valueType) { - return Map.toBuilder().withTypeParameters(keyType, valueType).build(); + return Map.withTypeParameters(keyType, valueType); } - public static final Type Map = Type.builder().withPackage(PACKAGE).withName("Map").build(); + public static final Type Map = type(PACKAGE, "Map"); public static Type MapEntry(Type keyType, Type valueType) { - return Type.builder().withPackage(PACKAGE).withName("Map.Entry").withTypeParameters(keyType, valueType).build(); + return MapEntry.withTypeParameters(keyType, valueType); } + public static final Type MapEntry = type(PACKAGE, "Map.Entry"); + public static Type List(Type valueType) { - return Type.builder().withPackage(PACKAGE).withName("List").withTypeParameters(valueType).build(); + return List.withTypeParameters(valueType); } + public static final Type List = type(PACKAGE, "List"); + public static final class Concurrent { public static final String PACKAGE = Util.PACKAGE + ".concurrent"; - public static final Type CompletableFuture = Type.builder().withPackage(PACKAGE).withName("CompletableFuture").build(); + public static final Type CompletableFuture = type(PACKAGE, "CompletableFuture"); } public static final class Function { public static final String PACKAGE = Util.PACKAGE + ".function"; public static Type Function(Type argType, Type returnType) { - return Type.builder().withPackage(PACKAGE).withName("Function").withTypeParameters(argType, returnType).build(); + return Function.withTypeParameters(argType, returnType); } + + public static final Type Function = type(PACKAGE, "Function"); } public static final class Stream { public static final String PACKAGE = Util.PACKAGE + ".stream"; - public static final Type Collectors = Type.builder().withPackage(PACKAGE).withName("Collectors").build(); + public static final Type Collectors = type(PACKAGE, "Collectors"); } } } @@ -114,9 +128,9 @@ 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(); + public static final Type Generated = type(PACKAGE, "Generated"); + public static final Type Nonnull = type(PACKAGE, "Nonnull"); + public static final Type Nullable = type(PACKAGE, "Nullable"); } } @@ -127,24 +141,21 @@ public static Type ApiClient(Type transport, Type client) { return ApiClient.withTypeParameters(transport, client); } - public static final Type ApiClient = Type.builder().withPackage(PACKAGE).withName("ApiClient").build(); + public static final Type ApiClient = type(PACKAGE, "ApiClient"); public static final class Json { public static final String PACKAGE = Client.PACKAGE + ".json"; - public static final Type JsonData = Type.builder().withPackage(PACKAGE).withName("JsonData").build(); - public static final Type JsonpDeserializable = Type.builder().withPackage(PACKAGE).withName("JsonpDeserializable").build(); - public static final Type JsonpDeserializer = Type.builder().withPackage(PACKAGE).withName("JsonpDeserializer").build(); - public static final Type JsonEnum = Type.builder().withPackage(PACKAGE).withName("JsonEnum").build(); - public static final Type JsonpMapper = Type.builder().withPackage(PACKAGE).withName("JsonpMapper").build(); - public static final Type JsonpSerializable = Type.builder().withPackage(PACKAGE).withName("JsonpSerializable").build(); - public static final Type ObjectBuilderDeserializer = Type.builder() - .withPackage(PACKAGE) - .withName("ObjectBuilderDeserializer") - .build(); - public static final Type ObjectDeserializer = Type.builder().withPackage(PACKAGE).withName("ObjectDeserializer").build(); - public static final Type PlainDeserializable = Type.builder().withPackage(PACKAGE).withName("PlainDeserializable").build(); - public static final Type PlainJsonSerializable = Type.builder().withPackage(PACKAGE).withName("PlainJsonSerializable").build(); - public static final Type UnionDeserializer = Type.builder().withPackage(PACKAGE).withName("UnionDeserializer").build(); + public static final Type JsonData = type(PACKAGE, "JsonData"); + public static final Type JsonpDeserializable = type(PACKAGE, "JsonpDeserializable"); + public static final Type JsonpDeserializer = type(PACKAGE, "JsonpDeserializer"); + public static final Type JsonEnum = type(PACKAGE, "JsonEnum"); + public static final Type JsonpMapper = type(PACKAGE, "JsonpMapper"); + public static final Type JsonpSerializable = type(PACKAGE, "JsonpSerializable"); + public static final Type ObjectBuilderDeserializer = type(PACKAGE, "ObjectBuilderDeserializer"); + public static final Type ObjectDeserializer = type(PACKAGE, "ObjectDeserializer"); + public static final Type PlainDeserializable = type(PACKAGE, "PlainDeserializable"); + public static final Type PlainJsonSerializable = type(PACKAGE, "PlainJsonSerializable"); + public static final Type UnionDeserializer = type(PACKAGE, "UnionDeserializer"); } public static final class OpenSearch { @@ -152,54 +163,57 @@ public static final class OpenSearch { public static final class _Types { public static final String PACKAGE = OpenSearch.PACKAGE + "._types"; - public static final Type ErrorResponse = Type.builder().withPackage(PACKAGE).withName("ErrorResponse").build(); - public static final Type OpenSearchException = Type.builder().withPackage(PACKAGE).withName("OpenSearchException").build(); - public static final Type RequestBase = Type.builder().withPackage(PACKAGE).withName("RequestBase").build(); - public static final Type Time = Type.builder().withPackage(PACKAGE).withName("Time").build(); + public static final Type ErrorResponse = type(PACKAGE, "ErrorResponse"); + public static final Type OpenSearchException = type(PACKAGE, "OpenSearchException"); + public static final Type RequestBase = type(PACKAGE, "RequestBase"); + public static final Type Time = type(PACKAGE, "Time"); } } public static final class Transport { public static final String PACKAGE = Client.PACKAGE + ".transport"; - public static final Type Endpoint = Type.builder().withPackage(PACKAGE).withName("Endpoint").build(); + public static final Type Endpoint = type(PACKAGE, "Endpoint"); public static Type JsonEndpoint(Type requestType, Type responseType, Type errorType) { return JsonEndpoint.withTypeParameters(requestType, responseType, errorType); } - public static final Type JsonEndpoint = Type.builder().withPackage(PACKAGE).withName("JsonEndpoint").build(); - public static final Type OpenSearchTransport = Type.builder().withPackage(PACKAGE).withName("OpenSearchTransport").build(); - public static final Type TransportOptions = Type.builder().withPackage(PACKAGE).withName("TransportOptions").build(); + public static final Type JsonEndpoint = type(PACKAGE, "JsonEndpoint"); + public static final Type OpenSearchTransport = type(PACKAGE, "OpenSearchTransport"); + public static final Type TransportOptions = type(PACKAGE, "TransportOptions"); public static final class Endpoints { public static final String PACKAGE = Transport.PACKAGE + ".endpoints"; + public static final Type BooleanEndpoint = type(PACKAGE, "BooleanEndpoint"); + public static final Type BooleanResponse = type(PACKAGE, "BooleanResponse"); + public static Type DictionaryResponse(Type keyType, Type valueType) { return DictionaryResponse.withTypeParameters(keyType, valueType); } - public static final Type DictionaryResponse = Type.builder().withPackage(PACKAGE).withName("DictionaryResponse").build(); - public static final Type SimpleEndpoint = Type.builder().withPackage(PACKAGE).withName("SimpleEndpoint").build(); + public static final Type DictionaryResponse = type(PACKAGE, "DictionaryResponse"); + public static final Type SimpleEndpoint = type(PACKAGE, "SimpleEndpoint"); } } public static final class Util { public static final String PACKAGE = Client.PACKAGE + ".util"; - public static final Type ApiTypeHelper = Type.builder().withPackage(PACKAGE).withName("ApiTypeHelper").build(); + public static final Type ApiTypeHelper = type(PACKAGE, "ApiTypeHelper"); public static Type ObjectBuilder(Type type) { return ObjectBuilder.withTypeParameters(type); } - public static final Type ObjectBuilder = Type.builder().withPackage(PACKAGE).withName("ObjectBuilder").build(); - public static final Type ObjectBuilderBase = Type.builder().withPackage(PACKAGE).withName("ObjectBuilderBase").build(); + public static final Type ObjectBuilder = type(PACKAGE, "ObjectBuilder"); + public static final Type ObjectBuilderBase = type(PACKAGE, "ObjectBuilderBase"); public static Type TaggedUnion(Type tagType, Type baseType) { return TaggedUnion.withTypeParameters(tagType, baseType); } - public static final Type TaggedUnion = Type.builder().withPackage(PACKAGE).withName("TaggedUnion").build(); - public static final Type TaggedUnionUtils = Type.builder().withPackage(PACKAGE).withName("TaggedUnionUtils").build(); + public static final Type TaggedUnion = type(PACKAGE, "TaggedUnion"); + public static final Type TaggedUnionUtils = type(PACKAGE, "TaggedUnionUtils"); } } @@ -211,7 +225,7 @@ public static final class Json { public static final class Stream { public static final String PACKAGE = Json.PACKAGE + ".stream"; - public static final Type JsonGenerator = Type.builder().withPackage(PACKAGE).withName("JsonGenerator").build(); + public static final Type JsonGenerator = type(PACKAGE, "JsonGenerator"); } } } 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 f73f6dd4a2..f73e867c2f 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 @@ -35,7 +35,7 @@ /** * Endpoint "{@code {{operationGroup}}}". */ - public static final {{TYPES.Client.Transport.Endpoint}}<{{className}}, {{responseType}}, {{TYPES.Client.OpenSearch._Types.ErrorResponse}}> _ENDPOINT = new {{TYPES.Client.Transport.Endpoints.SimpleEndpoint}}<>( + public static final {{TYPES.Client.Transport.Endpoint}}<{{className}}, {{responseType}}, {{TYPES.Client.OpenSearch._Types.ErrorResponse}}> _ENDPOINT = new {{#isBooleanRequest}}{{TYPES.Client.Transport.Endpoints.BooleanEndpoint}}{{/isBooleanRequest}}{{^isBooleanRequest}}{{TYPES.Client.Transport.Endpoints.SimpleEndpoint}}{{/isBooleanRequest}}<>( // Request method request -> {{#quoted}}{{httpMethod}}{{/quoted}}, // Request path @@ -92,9 +92,12 @@ {{^hasQueryParams}} {{TYPES.Client.Transport.Endpoints.SimpleEndpoint}}.emptyMap(), {{/hasQueryParams}} - {{TYPES.Client.Transport.Endpoints.SimpleEndpoint}}.emptyMap(), + {{TYPES.Client.Transport.Endpoints.SimpleEndpoint}}.emptyMap() + {{^isBooleanRequest}} + , {{hasRequestBody}}, {{responseType}}._DESERIALIZER + {{/isBooleanRequest}} ); {{>ObjectShape/HashCode}} diff --git a/samples/src/main/java/org/opensearch/client/samples/knn/KnnScriptScore.java b/samples/src/main/java/org/opensearch/client/samples/knn/KnnScriptScore.java index c5bef4e365..2277db6d13 100644 --- a/samples/src/main/java/org/opensearch/client/samples/knn/KnnScriptScore.java +++ b/samples/src/main/java/org/opensearch/client/samples/knn/KnnScriptScore.java @@ -12,7 +12,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.json.JsonData; -import org.opensearch.client.opensearch._types.ScriptLanguage; import org.opensearch.client.opensearch.core.BulkRequest; import org.opensearch.client.samples.SampleClient; import org.opensearch.client.samples.util.RandUtil;