Skip to content

Commit fea4138

Browse files
authored
Generate toBuilder and Builder.copy methods (#1300)
Signed-off-by: Thomas Farr <[email protected]>
1 parent d990a78 commit fea4138

File tree

281 files changed

+14572
-2169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+14572
-2169
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
1414

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

1819
### Dependencies
1920

java-client/src/generated/java/org/opensearch/client/opensearch/_types/AcknowledgedResponseBase.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import jakarta.json.stream.JsonGenerator;
4040
import javax.annotation.Generated;
41+
import javax.annotation.Nonnull;
4142
import org.opensearch.client.json.JsonpDeserializer;
4243
import org.opensearch.client.json.JsonpMapper;
4344
import org.opensearch.client.json.ObjectDeserializer;
@@ -88,18 +89,31 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
8889
protected abstract static class AbstractBuilder<BuilderT extends AbstractBuilder<BuilderT>> extends ObjectBuilderBase {
8990
private Boolean acknowledged;
9091

92+
protected AbstractBuilder() {}
93+
94+
protected AbstractBuilder(AcknowledgedResponseBase o) {
95+
this.acknowledged = o.acknowledged;
96+
}
97+
98+
protected AbstractBuilder(AbstractBuilder<BuilderT> o) {
99+
this.acknowledged = o.acknowledged;
100+
}
101+
102+
@Nonnull
103+
protected abstract BuilderT self();
104+
91105
/**
92106
* Required - For a successful response, this value is always true. On failure, an exception is returned instead.
93107
* <p>
94108
* API name: {@code acknowledged}
95109
* </p>
96110
*/
111+
@Nonnull
97112
public final BuilderT acknowledged(boolean value) {
98113
this.acknowledged = value;
99114
return self();
100115
}
101116

102-
protected abstract BuilderT self();
103117
}
104118

105119
// ---------------------------------------------------------------------------------------------

java-client/src/generated/java/org/opensearch/client/opensearch/_types/BaseNode.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,37 @@ protected abstract static class AbstractBuilder<BuilderT extends AbstractBuilder
196196
@Nullable
197197
private String transportAddress;
198198

199+
protected AbstractBuilder() {}
200+
201+
protected AbstractBuilder(BaseNode o) {
202+
this.attributes = _mapCopy(o.attributes);
203+
this.host = o.host;
204+
this.ip = o.ip;
205+
this.name = o.name;
206+
this.roles = _listCopy(o.roles);
207+
this.transportAddress = o.transportAddress;
208+
}
209+
210+
protected AbstractBuilder(AbstractBuilder<BuilderT> o) {
211+
this.attributes = _mapCopy(o.attributes);
212+
this.host = o.host;
213+
this.ip = o.ip;
214+
this.name = o.name;
215+
this.roles = _listCopy(o.roles);
216+
this.transportAddress = o.transportAddress;
217+
}
218+
219+
@Nonnull
220+
protected abstract BuilderT self();
221+
199222
/**
200223
* API name: {@code attributes}
201224
*
202225
* <p>
203226
* Adds all elements of <code>map</code> to <code>attributes</code>.
204227
* </p>
205228
*/
229+
@Nonnull
206230
public final BuilderT attributes(Map<String, String> map) {
207231
this.attributes = _mapPutAll(this.attributes, map);
208232
return self();
@@ -215,6 +239,7 @@ public final BuilderT attributes(Map<String, String> map) {
215239
* Adds an entry to <code>attributes</code>.
216240
* </p>
217241
*/
242+
@Nonnull
218243
public final BuilderT attributes(String key, String value) {
219244
this.attributes = _mapPut(this.attributes, key, value);
220245
return self();
@@ -223,6 +248,7 @@ public final BuilderT attributes(String key, String value) {
223248
/**
224249
* API name: {@code host}
225250
*/
251+
@Nonnull
226252
public final BuilderT host(@Nullable String value) {
227253
this.host = value;
228254
return self();
@@ -231,6 +257,7 @@ public final BuilderT host(@Nullable String value) {
231257
/**
232258
* API name: {@code ip}
233259
*/
260+
@Nonnull
234261
public final BuilderT ip(@Nullable String value) {
235262
this.ip = value;
236263
return self();
@@ -239,6 +266,7 @@ public final BuilderT ip(@Nullable String value) {
239266
/**
240267
* Required - API name: {@code name}
241268
*/
269+
@Nonnull
242270
public final BuilderT name(String value) {
243271
this.name = value;
244272
return self();
@@ -251,6 +279,7 @@ public final BuilderT name(String value) {
251279
* Adds all elements of <code>list</code> to <code>roles</code>.
252280
* </p>
253281
*/
282+
@Nonnull
254283
public final BuilderT roles(List<NodeRole> list) {
255284
this.roles = _listAddAll(this.roles, list);
256285
return self();
@@ -263,6 +292,7 @@ public final BuilderT roles(List<NodeRole> list) {
263292
* Adds one or more values to <code>roles</code>.
264293
* </p>
265294
*/
295+
@Nonnull
266296
public final BuilderT roles(NodeRole value, NodeRole... values) {
267297
this.roles = _listAdd(this.roles, value, values);
268298
return self();
@@ -271,12 +301,12 @@ public final BuilderT roles(NodeRole value, NodeRole... values) {
271301
/**
272302
* API name: {@code transport_address}
273303
*/
304+
@Nonnull
274305
public final BuilderT transportAddress(@Nullable String value) {
275306
this.transportAddress = value;
276307
return self();
277308
}
278309

279-
protected abstract BuilderT self();
280310
}
281311

282312
// ---------------------------------------------------------------------------------------------

java-client/src/generated/java/org/opensearch/client/opensearch/_types/BulkByScrollFailure.java

+55-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.Objects;
4141
import java.util.function.Function;
4242
import javax.annotation.Generated;
43+
import javax.annotation.Nonnull;
4344
import javax.annotation.Nullable;
4445
import org.opensearch.client.json.JsonpDeserializable;
4546
import org.opensearch.client.json.JsonpDeserializer;
@@ -48,14 +49,16 @@
4849
import org.opensearch.client.json.ObjectDeserializer;
4950
import org.opensearch.client.json.PlainJsonSerializable;
5051
import org.opensearch.client.util.ApiTypeHelper;
52+
import org.opensearch.client.util.CopyableBuilder;
5153
import org.opensearch.client.util.ObjectBuilder;
5254
import org.opensearch.client.util.ObjectBuilderBase;
55+
import org.opensearch.client.util.ToCopyableBuilder;
5356

5457
// typedef: _types.BulkByScrollFailure
5558

5659
@JsonpDeserializable
5760
@Generated("org.opensearch.client.codegen.CodeGenerator")
58-
public class BulkByScrollFailure implements PlainJsonSerializable {
61+
public class BulkByScrollFailure implements PlainJsonSerializable, ToCopyableBuilder<BulkByScrollFailure.Builder, BulkByScrollFailure> {
5962

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

196199
// ---------------------------------------------------------------------------------------------
197200

201+
@Override
202+
@Nonnull
203+
public Builder toBuilder() {
204+
return new Builder(this);
205+
}
206+
207+
@Nonnull
208+
public static Builder builder() {
209+
return new Builder();
210+
}
211+
198212
/**
199213
* Builder for {@link BulkByScrollFailure}.
200214
*/
201-
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<BulkByScrollFailure> {
215+
public static class Builder extends ObjectBuilderBase implements CopyableBuilder<Builder, BulkByScrollFailure> {
202216
@Nullable
203217
private ErrorCause cause;
204218
@Nullable
@@ -213,9 +227,38 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<B
213227
private Integer shard;
214228
private Integer status;
215229

230+
public Builder() {}
231+
232+
private Builder(BulkByScrollFailure o) {
233+
this.cause = o.cause;
234+
this.id = o.id;
235+
this.index = o.index;
236+
this.node = o.node;
237+
this.reason = o.reason;
238+
this.shard = o.shard;
239+
this.status = o.status;
240+
}
241+
242+
private Builder(Builder o) {
243+
this.cause = o.cause;
244+
this.id = o.id;
245+
this.index = o.index;
246+
this.node = o.node;
247+
this.reason = o.reason;
248+
this.shard = o.shard;
249+
this.status = o.status;
250+
}
251+
252+
@Override
253+
@Nonnull
254+
public Builder copy() {
255+
return new Builder(this);
256+
}
257+
216258
/**
217259
* API name: {@code cause}
218260
*/
261+
@Nonnull
219262
public final Builder cause(@Nullable ErrorCause value) {
220263
this.cause = value;
221264
return this;
@@ -224,13 +267,15 @@ public final Builder cause(@Nullable ErrorCause value) {
224267
/**
225268
* API name: {@code cause}
226269
*/
270+
@Nonnull
227271
public final Builder cause(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
228272
return cause(fn.apply(new ErrorCause.Builder()).build());
229273
}
230274

231275
/**
232276
* API name: {@code id}
233277
*/
278+
@Nonnull
234279
public final Builder id(@Nullable String value) {
235280
this.id = value;
236281
return this;
@@ -239,6 +284,7 @@ public final Builder id(@Nullable String value) {
239284
/**
240285
* API name: {@code index}
241286
*/
287+
@Nonnull
242288
public final Builder index(@Nullable String value) {
243289
this.index = value;
244290
return this;
@@ -247,6 +293,7 @@ public final Builder index(@Nullable String value) {
247293
/**
248294
* API name: {@code node}
249295
*/
296+
@Nonnull
250297
public final Builder node(@Nullable String value) {
251298
this.node = value;
252299
return this;
@@ -255,6 +302,7 @@ public final Builder node(@Nullable String value) {
255302
/**
256303
* API name: {@code reason}
257304
*/
305+
@Nonnull
258306
public final Builder reason(@Nullable ErrorCause value) {
259307
this.reason = value;
260308
return this;
@@ -263,13 +311,15 @@ public final Builder reason(@Nullable ErrorCause value) {
263311
/**
264312
* API name: {@code reason}
265313
*/
314+
@Nonnull
266315
public final Builder reason(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
267316
return reason(fn.apply(new ErrorCause.Builder()).build());
268317
}
269318

270319
/**
271320
* API name: {@code shard}
272321
*/
322+
@Nonnull
273323
public final Builder shard(@Nullable Integer value) {
274324
this.shard = value;
275325
return this;
@@ -278,6 +328,7 @@ public final Builder shard(@Nullable Integer value) {
278328
/**
279329
* Required - API name: {@code status}
280330
*/
331+
@Nonnull
281332
public final Builder status(int value) {
282333
this.status = value;
283334
return this;
@@ -288,6 +339,8 @@ public final Builder status(int value) {
288339
*
289340
* @throws NullPointerException if some of the required fields are null.
290341
*/
342+
@Override
343+
@Nonnull
291344
public BulkByScrollFailure build() {
292345
_checkSingleUse();
293346

0 commit comments

Comments
 (0)