Skip to content

Commit

Permalink
Generate indices.exists
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Oct 31, 2024
1 parent 21ca1d3 commit 98d2b4b
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 252 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<BooleanResponse> 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<BooleanResponse> exists(Function<ExistsRequest.Builder, ObjectBuilder<ExistsRequest>> fn)
throws IOException, OpenSearchException {
return exists(fn.apply(new ExistsRequest.Builder()).build());
}

// ----- Endpoint: indices.get

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<ExistsRequest.Builder, ObjectBuilder<ExistsRequest>> fn) throws IOException,
OpenSearchException {
return exists(fn.apply(new ExistsRequest.Builder()).build());
}

// ----- Endpoint: indices.get

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -506,38 +506,6 @@ public final CompletableFuture<DiskUsageResponse> diskUsage(Function<DiskUsageRe
return diskUsage(fn.apply(new DiskUsageRequest.Builder()).build());
}

// ----- Endpoint: indices.exists

/**
* Returns information about whether a particular index exists.
*
*
*/

public CompletableFuture<BooleanResponse> exists(ExistsRequest request) throws IOException, OpenSearchException {
@SuppressWarnings("unchecked")
JsonEndpoint<ExistsRequest, BooleanResponse, ErrorResponse> 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<BooleanResponse> exists(Function<ExistsRequest.Builder, ObjectBuilder<ExistsRequest>> fn)
throws IOException, OpenSearchException {
return exists(fn.apply(new ExistsRequest.Builder()).build());
}

// ----- Endpoint: indices.exists_alias

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,38 +488,6 @@ public final DiskUsageResponse diskUsage(Function<DiskUsageRequest.Builder, Obje
return diskUsage(fn.apply(new DiskUsageRequest.Builder()).build());
}

// ----- Endpoint: indices.exists

/**
* Returns information about whether a particular index exists.
*
*
*/

public BooleanResponse exists(ExistsRequest request) throws IOException, OpenSearchException {
@SuppressWarnings("unchecked")
JsonEndpoint<ExistsRequest, BooleanResponse, ErrorResponse> 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<ExistsRequest.Builder, ObjectBuilder<ExistsRequest>> fn) throws IOException,
OpenSearchException {
return exists(fn.apply(new ExistsRequest.Builder()).build());
}

// ----- Endpoint: indices.exists_alias

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@

public class BooleanEndpoint<RequestT> extends SimpleEndpoint<RequestT, BooleanResponse> {

public BooleanEndpoint(
Function<RequestT, String> method,
Function<RequestT, String> requestUrl,
Function<RequestT, Map<String, String>> queryParameters,
Function<RequestT, Map<String, String>> headers
) {
super(method, requestUrl, queryParameters, headers, false, null);
}

public BooleanEndpoint(
String id,
Function<RequestT, String> method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class RequestShape extends ObjectShape {
private final Map<String, Field> pathParams = new TreeMap<>();
@Nonnull
private final Map<String, Field> 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);
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ private void visit(@Nonnull OperationGroup group, @Nonnull List<OpenApiOperation
return OpenApiSchema.builder().withPointer(s.getPointer()).withAllOf(s, OpenApiSchema.ANONYMOUS_OBJECT).build();
}
return s.resolve();
})
.orElse(OpenApiSchema.ANONYMOUS_OBJECT);
});

if (responseSchema.isEmpty() && !requestShape.hasRequestBody()) {
requestShape.setIsBooleanRequest();
return;
}

visit(parent, requestShape.getResponseType().getName(), group + ".Response", responseSchema);
visit(parent, requestShape.getResponseType().getName(), group + ".Response", responseSchema.orElse(OpenApiSchema.ANONYMOUS_OBJECT));
}

@Nonnull
Expand Down Expand Up @@ -204,7 +208,7 @@ private RequestShape visit(@Nonnull Namespace parent, @Nonnull OperationGroup gr
.map(this::visit)
.forEachOrdered(shape::addQueryParam);

var bodySchema = variants.stream()
variants.stream()
.map(OpenApiOperation::getRequestBody)
.flatMap(Optional::stream)
.findFirst()
Expand All @@ -213,9 +217,7 @@ private RequestShape visit(@Nonnull Namespace parent, @Nonnull OperationGroup gr
.flatMap(c -> 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);
Expand Down
Loading

0 comments on commit 98d2b4b

Please sign in to comment.