Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate toBuilder and Builder.copy methods #1300

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This section is for maintaining a changelog for all breaking changes for the cli

### Added
- Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330))
- Added `toBuilder()` and `Builder.copy()` methods to all generated classes ([#1300](https://github.com/opensearch-project/opensearch-java/pull/1300))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import jakarta.json.stream.JsonGenerator;
import javax.annotation.Generated;
import javax.annotation.Nonnull;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.ObjectDeserializer;
Expand Down Expand Up @@ -88,18 +89,31 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
protected abstract static class AbstractBuilder<BuilderT extends AbstractBuilder<BuilderT>> extends ObjectBuilderBase {
private Boolean acknowledged;

protected AbstractBuilder() {}

protected AbstractBuilder(AcknowledgedResponseBase o) {
this.acknowledged = o.acknowledged;
}

protected AbstractBuilder(AbstractBuilder<BuilderT> o) {
this.acknowledged = o.acknowledged;
}

@Nonnull
protected abstract BuilderT self();

/**
* Required - For a successful response, this value is always true. On failure, an exception is returned instead.
* <p>
* API name: {@code acknowledged}
* </p>
*/
@Nonnull
public final BuilderT acknowledged(boolean value) {
this.acknowledged = value;
return self();
}

protected abstract BuilderT self();
}

// ---------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,37 @@ protected abstract static class AbstractBuilder<BuilderT extends AbstractBuilder
@Nullable
private String transportAddress;

protected AbstractBuilder() {}

protected AbstractBuilder(BaseNode o) {
this.attributes = _mapCopy(o.attributes);
this.host = o.host;
this.ip = o.ip;
this.name = o.name;
this.roles = _listCopy(o.roles);
this.transportAddress = o.transportAddress;
}

protected AbstractBuilder(AbstractBuilder<BuilderT> o) {
this.attributes = _mapCopy(o.attributes);
this.host = o.host;
this.ip = o.ip;
this.name = o.name;
this.roles = _listCopy(o.roles);
this.transportAddress = o.transportAddress;
}

@Nonnull
protected abstract BuilderT self();

/**
* API name: {@code attributes}
*
* <p>
* Adds all elements of <code>map</code> to <code>attributes</code>.
* </p>
*/
@Nonnull
public final BuilderT attributes(Map<String, String> map) {
this.attributes = _mapPutAll(this.attributes, map);
return self();
Expand All @@ -215,6 +239,7 @@ public final BuilderT attributes(Map<String, String> map) {
* Adds an entry to <code>attributes</code>.
* </p>
*/
@Nonnull
public final BuilderT attributes(String key, String value) {
this.attributes = _mapPut(this.attributes, key, value);
return self();
Expand All @@ -223,6 +248,7 @@ public final BuilderT attributes(String key, String value) {
/**
* API name: {@code host}
*/
@Nonnull
public final BuilderT host(@Nullable String value) {
this.host = value;
return self();
Expand All @@ -231,6 +257,7 @@ public final BuilderT host(@Nullable String value) {
/**
* API name: {@code ip}
*/
@Nonnull
public final BuilderT ip(@Nullable String value) {
this.ip = value;
return self();
Expand All @@ -239,6 +266,7 @@ public final BuilderT ip(@Nullable String value) {
/**
* Required - API name: {@code name}
*/
@Nonnull
public final BuilderT name(String value) {
this.name = value;
return self();
Expand All @@ -251,6 +279,7 @@ public final BuilderT name(String value) {
* Adds all elements of <code>list</code> to <code>roles</code>.
* </p>
*/
@Nonnull
public final BuilderT roles(List<NodeRole> list) {
this.roles = _listAddAll(this.roles, list);
return self();
Expand All @@ -263,6 +292,7 @@ public final BuilderT roles(List<NodeRole> list) {
* Adds one or more values to <code>roles</code>.
* </p>
*/
@Nonnull
public final BuilderT roles(NodeRole value, NodeRole... values) {
this.roles = _listAdd(this.roles, value, values);
return self();
Expand All @@ -271,12 +301,12 @@ public final BuilderT roles(NodeRole value, NodeRole... values) {
/**
* API name: {@code transport_address}
*/
@Nonnull
public final BuilderT transportAddress(@Nullable String value) {
this.transportAddress = value;
return self();
}

protected abstract BuilderT self();
}

// ---------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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;
Expand All @@ -48,14 +49,16 @@
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.json.PlainJsonSerializable;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.CopyableBuilder;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;
import org.opensearch.client.util.ToCopyableBuilder;

// typedef: _types.BulkByScrollFailure

@JsonpDeserializable
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class BulkByScrollFailure implements PlainJsonSerializable {
public class BulkByScrollFailure implements PlainJsonSerializable, ToCopyableBuilder<BulkByScrollFailure.Builder, BulkByScrollFailure> {

@Nullable
private final ErrorCause cause;
Expand Down Expand Up @@ -195,10 +198,21 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

// ---------------------------------------------------------------------------------------------

@Override
@Nonnull
public Builder toBuilder() {
return new Builder(this);
}

@Nonnull
public static Builder builder() {
return new Builder();
}

/**
* Builder for {@link BulkByScrollFailure}.
*/
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<BulkByScrollFailure> {
public static class Builder extends ObjectBuilderBase implements CopyableBuilder<Builder, BulkByScrollFailure> {
@Nullable
private ErrorCause cause;
@Nullable
Expand All @@ -213,9 +227,38 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<B
private Integer shard;
private Integer status;

public Builder() {}

private Builder(BulkByScrollFailure o) {
this.cause = o.cause;
this.id = o.id;
this.index = o.index;
this.node = o.node;
this.reason = o.reason;
this.shard = o.shard;
this.status = o.status;
}

private Builder(Builder o) {
this.cause = o.cause;
this.id = o.id;
this.index = o.index;
this.node = o.node;
this.reason = o.reason;
this.shard = o.shard;
this.status = o.status;
}

@Override
@Nonnull
public Builder copy() {
return new Builder(this);
}

/**
* API name: {@code cause}
*/
@Nonnull
public final Builder cause(@Nullable ErrorCause value) {
this.cause = value;
return this;
Expand All @@ -224,13 +267,15 @@ public final Builder cause(@Nullable ErrorCause value) {
/**
* API name: {@code cause}
*/
@Nonnull
public final Builder cause(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
return cause(fn.apply(new ErrorCause.Builder()).build());
}

/**
* API name: {@code id}
*/
@Nonnull
public final Builder id(@Nullable String value) {
this.id = value;
return this;
Expand All @@ -239,6 +284,7 @@ public final Builder id(@Nullable String value) {
/**
* API name: {@code index}
*/
@Nonnull
public final Builder index(@Nullable String value) {
this.index = value;
return this;
Expand All @@ -247,6 +293,7 @@ public final Builder index(@Nullable String value) {
/**
* API name: {@code node}
*/
@Nonnull
public final Builder node(@Nullable String value) {
this.node = value;
return this;
Expand All @@ -255,6 +302,7 @@ public final Builder node(@Nullable String value) {
/**
* API name: {@code reason}
*/
@Nonnull
public final Builder reason(@Nullable ErrorCause value) {
this.reason = value;
return this;
Expand All @@ -263,13 +311,15 @@ public final Builder reason(@Nullable ErrorCause value) {
/**
* API name: {@code reason}
*/
@Nonnull
public final Builder reason(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
return reason(fn.apply(new ErrorCause.Builder()).build());
}

/**
* API name: {@code shard}
*/
@Nonnull
public final Builder shard(@Nullable Integer value) {
this.shard = value;
return this;
Expand All @@ -278,6 +328,7 @@ public final Builder shard(@Nullable Integer value) {
/**
* Required - API name: {@code status}
*/
@Nonnull
public final Builder status(int value) {
this.status = value;
return this;
Expand All @@ -288,6 +339,8 @@ public final Builder status(int value) {
*
* @throws NullPointerException if some of the required fields are null.
*/
@Override
@Nonnull
public BulkByScrollFailure build() {
_checkSingleUse();

Expand Down
Loading
Loading