Skip to content

Commit f8084fd

Browse files
committed
Fix ShardProfile.fetch typed as single FetchProfile instead of List<FetchProfile>
OpenSearch returns fetch as a JSON array in profile responses but the spec defined it as a single FetchProfile object. This caused: UnexpectedJsonEventException: Unexpected JSON event 'START_ARRAY' instead of '[START_OBJECT, KEY_NAME]' Change the spec to type: array / items: FetchProfile and update the generated ShardProfile.java to use List<FetchProfile> with array serialization and arrayDeserializer, matching the pattern already used by aggregations and searches in the same class. Fixes #1965 Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
1 parent 0707347 commit f8084fd

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

java-client/src/generated/java/org/opensearch/client/opensearch/core/search/ShardProfile.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public class ShardProfile implements PlainJsonSerializable, ToCopyableBuilder<Sh
6464
@Nonnull
6565
private final List<AggregationProfile> aggregations;
6666

67-
@Nullable
68-
private final FetchProfile fetch;
67+
@Nonnull
68+
private final List<FetchProfile> fetch;
6969

7070
@Nonnull
7171
private final String id;
@@ -77,7 +77,7 @@ public class ShardProfile implements PlainJsonSerializable, ToCopyableBuilder<Sh
7777

7878
private ShardProfile(Builder builder) {
7979
this.aggregations = ApiTypeHelper.unmodifiableRequired(builder.aggregations, this, "aggregations");
80-
this.fetch = builder.fetch;
80+
this.fetch = ApiTypeHelper.unmodifiable(builder.fetch);
8181
this.id = ApiTypeHelper.requireNonNull(builder.id, this, "id");
8282
this.searches = ApiTypeHelper.unmodifiableRequired(builder.searches, this, "searches");
8383
}
@@ -97,8 +97,8 @@ public final List<AggregationProfile> aggregations() {
9797
/**
9898
* API name: {@code fetch}
9999
*/
100-
@Nullable
101-
public final FetchProfile fetch() {
100+
@Nonnull
101+
public final List<FetchProfile> fetch() {
102102
return this.fetch;
103103
}
104104

@@ -136,9 +136,13 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
136136
}
137137
generator.writeEnd();
138138

139-
if (this.fetch != null) {
139+
if (ApiTypeHelper.isDefined(this.fetch)) {
140140
generator.writeKey("fetch");
141-
this.fetch.serialize(generator, mapper);
141+
generator.writeStartArray();
142+
for (FetchProfile item0 : this.fetch) {
143+
item0.serialize(generator, mapper);
144+
}
145+
generator.writeEnd();
142146
}
143147

144148
generator.writeKey("id");
@@ -171,22 +175,22 @@ public static Builder builder() {
171175
public static class Builder extends ObjectBuilderBase implements CopyableBuilder<Builder, ShardProfile> {
172176
private List<AggregationProfile> aggregations;
173177
@Nullable
174-
private FetchProfile fetch;
178+
private List<FetchProfile> fetch;
175179
private String id;
176180
private List<SearchProfile> searches;
177181

178182
public Builder() {}
179183

180184
private Builder(ShardProfile o) {
181185
this.aggregations = _listCopy(o.aggregations);
182-
this.fetch = o.fetch;
186+
this.fetch = _listCopy(o.fetch);
183187
this.id = o.id;
184188
this.searches = _listCopy(o.searches);
185189
}
186190

187191
private Builder(Builder o) {
188192
this.aggregations = _listCopy(o.aggregations);
189-
this.fetch = o.fetch;
193+
this.fetch = _listCopy(o.fetch);
190194
this.id = o.id;
191195
this.searches = _listCopy(o.searches);
192196
}
@@ -237,15 +241,36 @@ public final Builder aggregations(Function<AggregationProfile.Builder, ObjectBui
237241

238242
/**
239243
* API name: {@code fetch}
244+
*
245+
* <p>
246+
* Adds all elements of <code>list</code> to <code>fetch</code>.
247+
* </p>
248+
*/
249+
@Nonnull
250+
public final Builder fetch(List<FetchProfile> list) {
251+
this.fetch = _listAddAll(this.fetch, list);
252+
return this;
253+
}
254+
255+
/**
256+
* API name: {@code fetch}
257+
*
258+
* <p>
259+
* Adds one or more values to <code>fetch</code>.
260+
* </p>
240261
*/
241262
@Nonnull
242-
public final Builder fetch(@Nullable FetchProfile value) {
243-
this.fetch = value;
263+
public final Builder fetch(FetchProfile value, FetchProfile... values) {
264+
this.fetch = _listAdd(this.fetch, value, values);
244265
return this;
245266
}
246267

247268
/**
248269
* API name: {@code fetch}
270+
*
271+
* <p>
272+
* Adds a value to <code>fetch</code> using a builder lambda.
273+
* </p>
249274
*/
250275
@Nonnull
251276
public final Builder fetch(Function<FetchProfile.Builder, ObjectBuilder<FetchProfile>> fn) {
@@ -325,7 +350,7 @@ public ShardProfile build() {
325350

326351
protected static void setupShardProfileDeserializer(ObjectDeserializer<ShardProfile.Builder> op) {
327352
op.add(Builder::aggregations, JsonpDeserializer.arrayDeserializer(AggregationProfile._DESERIALIZER), "aggregations");
328-
op.add(Builder::fetch, FetchProfile._DESERIALIZER, "fetch");
353+
op.add(Builder::fetch, JsonpDeserializer.arrayDeserializer(FetchProfile._DESERIALIZER), "fetch");
329354
op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id");
330355
op.add(Builder::searches, JsonpDeserializer.arrayDeserializer(SearchProfile._DESERIALIZER), "searches");
331356
}

java-codegen/opensearch-openapi.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52512,7 +52512,9 @@ components:
5251252512
items:
5251352513
$ref: '#/components/schemas/_core.search___SearchProfile'
5251452514
fetch:
52515-
$ref: '#/components/schemas/_core.search___FetchProfile'
52515+
type: array
52516+
items:
52517+
$ref: '#/components/schemas/_core.search___FetchProfile'
5251652518
required:
5251752519
- aggregations
5251852520
- id

0 commit comments

Comments
 (0)