Skip to content

Commit 539f864

Browse files
committed
[codegen] update to latest spec
1 parent d439d7a commit 539f864

File tree

10 files changed

+238
-898
lines changed

10 files changed

+238
-898
lines changed

java-client/src/main/java/co/elastic/clients/elasticsearch/_types/aggregations/AggregationRange.java

Lines changed: 108 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@
1919

2020
package co.elastic.clients.elasticsearch._types.aggregations;
2121

22-
import co.elastic.clients.json.JsonEnum;
2322
import co.elastic.clients.json.JsonpDeserializable;
2423
import co.elastic.clients.json.JsonpDeserializer;
2524
import co.elastic.clients.json.JsonpMapper;
2625
import co.elastic.clients.json.JsonpSerializable;
2726
import co.elastic.clients.json.JsonpUtils;
27+
import co.elastic.clients.json.ObjectBuilderDeserializer;
2828
import co.elastic.clients.json.ObjectDeserializer;
29-
import co.elastic.clients.json.UnionDeserializer;
30-
import co.elastic.clients.util.ApiTypeHelper;
3129
import co.elastic.clients.util.ObjectBuilder;
32-
import co.elastic.clients.util.ObjectBuilderBase;
33-
import co.elastic.clients.util.TaggedUnion;
34-
import co.elastic.clients.util.TaggedUnionUtils;
30+
import co.elastic.clients.util.WithJsonObjectBuilderBase;
3531
import jakarta.json.stream.JsonGenerator;
32+
import java.lang.Double;
33+
import java.lang.String;
3634
import java.util.Objects;
3735
import java.util.function.Function;
3836
import javax.annotation.Nullable;
@@ -61,71 +59,23 @@
6159
* specification</a>
6260
*/
6361
@JsonpDeserializable
64-
public class AggregationRange
65-
implements
66-
TaggedUnion<AggregationRange.Kind, AggregationRangeVariant>,
67-
JsonpSerializable {
62+
public class AggregationRange implements JsonpSerializable {
63+
@Nullable
64+
private final Double from;
6865

69-
/**
70-
* {@link AggregationRange} variant kinds.
71-
*
72-
* @see <a href=
73-
* "../../doc-files/api-spec.html#_types.aggregations.AggregationRange">API
74-
* specification</a>
75-
*/
76-
77-
public enum Kind implements JsonEnum {
78-
Date("date"),
79-
80-
Number("number"),
81-
82-
Term("term"),
83-
84-
Untyped("untyped"),
85-
86-
;
87-
88-
private final String jsonValue;
66+
@Nullable
67+
private final String key;
8968

90-
Kind(String jsonValue) {
91-
this.jsonValue = jsonValue;
92-
}
93-
94-
public String jsonValue() {
95-
return this.jsonValue;
96-
}
97-
98-
}
99-
100-
private final Kind _kind;
101-
private final AggregationRangeVariant _value;
69+
@Nullable
70+
private final Double to;
10271

103-
@Override
104-
public final Kind _kind() {
105-
return _kind;
106-
}
107-
108-
@Override
109-
public final AggregationRangeVariant _get() {
110-
return _value;
111-
}
112-
113-
public AggregationRange(AggregationRangeVariant value) {
114-
115-
this._kind = ApiTypeHelper.requireNonNull(value._aggregationRangeKind(), this, "<variant kind>");
116-
this._value = ApiTypeHelper.requireNonNull(value, this, "<variant value>");
117-
118-
}
119-
120-
private AggregationRange(Kind kind, AggregationRangeVariant value) {
121-
this._kind = kind;
122-
this._value = value;
123-
}
72+
// ---------------------------------------------------------------------------------------------
12473

12574
private AggregationRange(Builder builder) {
12675

127-
this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
128-
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");
76+
this.from = builder.from;
77+
this.key = builder.key;
78+
this.to = builder.to;
12979

13080
}
13181

@@ -134,77 +84,61 @@ public static AggregationRange of(Function<Builder, ObjectBuilder<AggregationRan
13484
}
13585

13686
/**
137-
* Is this variant instance of kind {@code date}?
87+
* Start of the range (inclusive).
88+
* <p>
89+
* API name: {@code from}
13890
*/
139-
public boolean isDate() {
140-
return _kind == Kind.Date;
91+
@Nullable
92+
public final Double from() {
93+
return this.from;
14194
}
14295

14396
/**
144-
* Get the {@code date} variant value.
145-
*
146-
* @throws IllegalStateException
147-
* if the current variant is not of the {@code date} kind.
97+
* Custom key to return the range with.
98+
* <p>
99+
* API name: {@code key}
148100
*/
149-
public DateAggregationRange date() {
150-
return TaggedUnionUtils.get(this, Kind.Date);
101+
@Nullable
102+
public final String key() {
103+
return this.key;
151104
}
152105

153106
/**
154-
* Is this variant instance of kind {@code number}?
107+
* End of the range (exclusive).
108+
* <p>
109+
* API name: {@code to}
155110
*/
156-
public boolean isNumber() {
157-
return _kind == Kind.Number;
111+
@Nullable
112+
public final Double to() {
113+
return this.to;
158114
}
159115

160116
/**
161-
* Get the {@code number} variant value.
162-
*
163-
* @throws IllegalStateException
164-
* if the current variant is not of the {@code number} kind.
117+
* Serialize this object to JSON.
165118
*/
166-
public NumberAggregationRange number() {
167-
return TaggedUnionUtils.get(this, Kind.Number);
168-
}
169-
170-
/**
171-
* Is this variant instance of kind {@code term}?
172-
*/
173-
public boolean isTerm() {
174-
return _kind == Kind.Term;
119+
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
120+
generator.writeStartObject();
121+
serializeInternal(generator, mapper);
122+
generator.writeEnd();
175123
}
176124

177-
/**
178-
* Get the {@code term} variant value.
179-
*
180-
* @throws IllegalStateException
181-
* if the current variant is not of the {@code term} kind.
182-
*/
183-
public TermAggregationRange term() {
184-
return TaggedUnionUtils.get(this, Kind.Term);
185-
}
125+
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
186126

187-
/**
188-
* Is this variant instance of kind {@code untyped}?
189-
*/
190-
public boolean isUntyped() {
191-
return _kind == Kind.Untyped;
192-
}
127+
if (this.from != null) {
128+
generator.writeKey("from");
129+
generator.write(this.from);
193130

194-
/**
195-
* Get the {@code untyped} variant value.
196-
*
197-
* @throws IllegalStateException
198-
* if the current variant is not of the {@code untyped} kind.
199-
*/
200-
public UntypedAggregationRange untyped() {
201-
return TaggedUnionUtils.get(this, Kind.Untyped);
202-
}
131+
}
132+
if (this.key != null) {
133+
generator.writeKey("key");
134+
generator.write(this.key);
203135

204-
@Override
205-
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
136+
}
137+
if (this.to != null) {
138+
generator.writeKey("to");
139+
generator.write(this.to);
206140

207-
mapper.serialize(_value, generator);
141+
}
208142

209143
}
210144

@@ -213,66 +147,84 @@ public String toString() {
213147
return JsonpUtils.toString(this);
214148
}
215149

216-
public static class Builder extends ObjectBuilderBase implements ObjectBuilder<AggregationRange> {
217-
private Kind _kind;
218-
private AggregationRangeVariant _value;
150+
// ---------------------------------------------------------------------------------------------
219151

220-
public ObjectBuilder<AggregationRange> date(DateAggregationRange v) {
221-
this._kind = Kind.Date;
222-
this._value = v;
223-
return this;
224-
}
152+
/**
153+
* Builder for {@link AggregationRange}.
154+
*/
225155

226-
public ObjectBuilder<AggregationRange> date(
227-
Function<DateAggregationRange.Builder, ObjectBuilder<DateAggregationRange>> fn) {
228-
return this.date(fn.apply(new DateAggregationRange.Builder()).build());
229-
}
156+
public static class Builder extends WithJsonObjectBuilderBase<Builder> implements ObjectBuilder<AggregationRange> {
157+
@Nullable
158+
private Double from;
230159

231-
public ObjectBuilder<AggregationRange> number(NumberAggregationRange v) {
232-
this._kind = Kind.Number;
233-
this._value = v;
234-
return this;
235-
}
160+
@Nullable
161+
private String key;
236162

237-
public ObjectBuilder<AggregationRange> number(
238-
Function<NumberAggregationRange.Builder, ObjectBuilder<NumberAggregationRange>> fn) {
239-
return this.number(fn.apply(new NumberAggregationRange.Builder()).build());
240-
}
163+
@Nullable
164+
private Double to;
241165

242-
public ObjectBuilder<AggregationRange> term(TermAggregationRange v) {
243-
this._kind = Kind.Term;
244-
this._value = v;
166+
/**
167+
* Start of the range (inclusive).
168+
* <p>
169+
* API name: {@code from}
170+
*/
171+
public final Builder from(@Nullable Double value) {
172+
this.from = value;
245173
return this;
246174
}
247175

248-
public ObjectBuilder<AggregationRange> term(
249-
Function<TermAggregationRange.Builder, ObjectBuilder<TermAggregationRange>> fn) {
250-
return this.term(fn.apply(new TermAggregationRange.Builder()).build());
176+
/**
177+
* Custom key to return the range with.
178+
* <p>
179+
* API name: {@code key}
180+
*/
181+
public final Builder key(@Nullable String value) {
182+
this.key = value;
183+
return this;
251184
}
252185

253-
public ObjectBuilder<AggregationRange> untyped(UntypedAggregationRange v) {
254-
this._kind = Kind.Untyped;
255-
this._value = v;
186+
/**
187+
* End of the range (exclusive).
188+
* <p>
189+
* API name: {@code to}
190+
*/
191+
public final Builder to(@Nullable Double value) {
192+
this.to = value;
256193
return this;
257194
}
258195

259-
public ObjectBuilder<AggregationRange> untyped(
260-
Function<UntypedAggregationRange.Builder, ObjectBuilder<UntypedAggregationRange>> fn) {
261-
return this.untyped(fn.apply(new UntypedAggregationRange.Builder()).build());
196+
@Override
197+
protected Builder self() {
198+
return this;
262199
}
263200

201+
/**
202+
* Builds a {@link AggregationRange}.
203+
*
204+
* @throws NullPointerException
205+
* if some of the required fields are null.
206+
*/
264207
public AggregationRange build() {
265208
_checkSingleUse();
209+
266210
return new AggregationRange(this);
267211
}
268-
269212
}
270213

271-
private static JsonpDeserializer<AggregationRange> buildAggregationRangeDeserializer() {
272-
return new UnionDeserializer.Builder<AggregationRange, Kind, AggregationRangeVariant>(AggregationRange::new,
273-
false).addMember(Kind.Untyped, UntypedAggregationRange._DESERIALIZER).build();
214+
// ---------------------------------------------------------------------------------------------
215+
216+
/**
217+
* Json deserializer for {@link AggregationRange}
218+
*/
219+
public static final JsonpDeserializer<AggregationRange> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new,
220+
AggregationRange::setupAggregationRangeDeserializer);
221+
222+
protected static void setupAggregationRangeDeserializer(ObjectDeserializer<AggregationRange.Builder> op) {
223+
224+
op.add(Builder::from, JsonpDeserializer.doubleDeserializer(), "from");
225+
op.add(Builder::key, JsonpDeserializer.stringDeserializer(), "key");
226+
op.add(Builder::to, JsonpDeserializer.doubleDeserializer(), "to");
227+
274228
}
275229

276-
public static final JsonpDeserializer<AggregationRange> _DESERIALIZER = JsonpDeserializer
277-
.lazy(AggregationRange::buildAggregationRangeDeserializer);
278230
}

0 commit comments

Comments
 (0)