From acfb7dd9f2bff362f164e14b4823aba2931515d8 Mon Sep 17 00:00:00 2001 From: Alexis Cote Date: Wed, 29 Jul 2026 16:23:14 -0400 Subject: [PATCH 1/6] fix(json): handle pre-consumed parser event in JsonData._DESERIALIZER and support custom variant serialization - Override three-arg deserialize in JsonData._DESERIALIZER to correctly use parser.getValue() when the event is already consumed. - Add default _customKind() method to TaggedUnion interface returning null for built-in kinds. - Fall back to _customKind() in ExternallyTaggedUnion typed-keys serialization when jsonValue() is null. --- .../client/json/ExternallyTaggedUnion.java | 13 +++++++++++-- .../java/org/opensearch/client/json/JsonData.java | 13 ++++++++++++- .../org/opensearch/client/util/TaggedUnion.java | 8 ++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/java-client/src/main/java/org/opensearch/client/json/ExternallyTaggedUnion.java b/java-client/src/main/java/org/opensearch/client/json/ExternallyTaggedUnion.java index f8beafceb7..7327412a9b 100644 --- a/java-client/src/main/java/org/opensearch/client/json/ExternallyTaggedUnion.java +++ b/java-client/src/main/java/org/opensearch/client/json/ExternallyTaggedUnion.java @@ -89,6 +89,7 @@ public Union deserialize(String type, JsonParser parser, JsonpMapper mapper, Eve if (unKnownUnionCtor != null) { return unKnownUnionCtor.apply(type, JsonData._DESERIALIZER.deserialize(parser, mapper, event)); } + throw new jakarta.json.JsonException("Unknown variant type '" + type + "'"); } return unionCtor.apply(deserializer.deserialize(parser, mapper, event)); @@ -191,7 +192,11 @@ public void deserializeEntry(String key, JsonParser parser, JsonpMapper mapper, if (mapper.attribute(JsonpMapperAttributes.SERIALIZE_TYPED_KEYS, true)) { for (Map.Entry entry : map.entrySet()) { T value = entry.getValue(); - generator.writeKey(value._kind().jsonValue() + "#" + entry.getKey()); + String type = value._kind().jsonValue(); + if (type == null) { + type = value._customKind(); + } + generator.writeKey(type + "#" + entry.getKey()); value.serialize(generator, mapper); } } else { @@ -223,7 +228,11 @@ public void deserializeEntry(String key, JsonParser parser, JsonpMapper mapper, if (list.isEmpty()) { continue; } - generator.writeKey(list.get(0)._kind().jsonValue() + "#" + entry.getKey()); + String type = list.get(0)._kind().jsonValue(); + if (type == null) { + type = list.get(0)._customKind(); + } + generator.writeKey(type + "#" + entry.getKey()); generator.writeStartArray(); for (T value : list) { value.serialize(generator, mapper); diff --git a/java-client/src/main/java/org/opensearch/client/json/JsonData.java b/java-client/src/main/java/org/opensearch/client/json/JsonData.java index ad907650bb..0aa99b5363 100644 --- a/java-client/src/main/java/org/opensearch/client/json/JsonData.java +++ b/java-client/src/main/java/org/opensearch/client/json/JsonData.java @@ -108,5 +108,16 @@ static JsonData from(JsonParser parser, JsonpMapper mapper) { return of(parser.getValue(), mapper); } - JsonpDeserializer _DESERIALIZER = JsonpDeserializer.of(EnumSet.allOf(JsonParser.Event.class), JsonData::from); + JsonpDeserializer _DESERIALIZER = new JsonpDeserializerBase(EnumSet.allOf(JsonParser.Event.class)) { + @Override + public JsonData deserialize(JsonParser parser, JsonpMapper mapper) { + return JsonData.from(parser, mapper); + } + + @Override + public JsonData deserialize(JsonParser parser, JsonpMapper mapper, JsonParser.Event event) { + // Event already consumed — getValue() returns the current token's value tree + return JsonData.of(parser.getValue(), mapper); + } + }; } diff --git a/java-client/src/main/java/org/opensearch/client/util/TaggedUnion.java b/java-client/src/main/java/org/opensearch/client/util/TaggedUnion.java index bc4f048b3e..e0b3284d4a 100644 --- a/java-client/src/main/java/org/opensearch/client/util/TaggedUnion.java +++ b/java-client/src/main/java/org/opensearch/client/util/TaggedUnion.java @@ -42,4 +42,12 @@ public interface TaggedUnion, BaseType> { Tag _kind(); BaseType _get(); + + /** + * Returns the actual type name for custom (plugin-provided) variant kinds whose + * {@code jsonValue} is {@code null}. Returns {@code null} for all built-in kinds. + */ + default String _customKind() { + return null; + } } From 734c5c8bb2256aa208af283795e59f93d43b116b Mon Sep 17 00:00:00 2001 From: Alexis Cote Date: Wed, 29 Jul 2026 16:24:10 -0400 Subject: [PATCH 2/6] feat(codegen): add _Custom variant kind to all discriminated tagged unions Add Kind._Custom to every discriminated tagged union to gracefully handle plugin-provided types. Unknown discriminator values are captured as _Custom with the raw JSON preserved as JsonData. - Add _Custom(null) enum constant, _customKind field, _isCustom(), _customKind(), _custom() accessors, and Builder._custom(type, data). - Add CustomVariant inner class with equals/hashCode. - Use _customKind in serialize when Kind is _Custom. - Include _customKind in equals()/hashCode(). - Validate type and data with ApiTypeHelper.requireNonNull(). - Wire unknownFieldHandler in internally-tagged deserializers and unknownVariantCtor in externally-tagged deserializers. - Add user guide section with read/build examples. --- guides/json.md | 39 +++++- .../_types/aggregations/Aggregate.java | 94 ++++++++++++- .../_types/aggregations/Aggregation.java | 90 +++++++++++- .../MovingAverageAggregation.java | 90 +++++++++++- .../opensearch/_types/analysis/Analyzer.java | 90 +++++++++++- .../_types/analysis/CharFilterDefinition.java | 90 +++++++++++- .../_types/analysis/Normalizer.java | 90 +++++++++++- .../analysis/TokenFilterDefinition.java | 90 +++++++++++- .../_types/analysis/TokenizerDefinition.java | 90 +++++++++++- .../opensearch/_types/mapping/Property.java | 90 +++++++++++- .../_types/query_dsl/FunctionScore.java | 91 +++++++++++- .../_types/query_dsl/Intervals.java | 92 ++++++++++++- .../_types/query_dsl/IntervalsFilter.java | 92 ++++++++++++- .../_types/query_dsl/IntervalsQuery.java | 91 +++++++++++- .../opensearch/_types/query_dsl/Query.java | 91 +++++++++++- .../_types/query_dsl/SpanQuery.java | 92 ++++++++++++- .../remote_info/ClusterRemoteInfo.java | 90 +++++++++++- .../core/search/FieldSuggester.java | 91 +++++++++++- .../core/search/SmoothingModel.java | 92 ++++++++++++- .../opensearch/core/search/Suggest.java | 93 ++++++++++++- .../indices/update_aliases/Action.java | 92 ++++++++++++- .../client/opensearch/ingest/Processor.java | 92 ++++++++++++- .../PhaseResultsProcessor.java | 92 ++++++++++++- .../search_pipeline/RequestProcessor.java | 92 ++++++++++++- .../search_pipeline/ResponseProcessor.java | 92 ++++++++++++- .../templates/TaggedUnionShape.mustache | 130 +++++++++++++++++- .../TaggedUnionShape/Deserialize.mustache | 9 +- .../TaggedUnionShape/Serialize.mustache | 2 +- 28 files changed, 2303 insertions(+), 66 deletions(-) diff --git a/guides/json.md b/guides/json.md index 86e7f15fb9..be53327d30 100644 --- a/guides/json.md +++ b/guides/json.md @@ -5,6 +5,9 @@ - [Deserialization](#deserialization) - [Using withJson](#using-withjson) - [Using static _DESERIALIZER](#using-static-_deserializer) + - [Custom (Plugin-Provided) Variant Types](#custom-plugin-provided-variant-types) + - [Reading a custom variant](#reading-a-custom-variant) + - [Building a custom variant](#building-a-custom-variant) # Working With JSON @@ -109,4 +112,38 @@ private IndexTemplateMapping getInstance(String templateJsonString) { return indexTemplateMapping; } } -``` \ No newline at end of file +``` + +## Custom (Plugin-Provided) Variant Types + +All discriminated tagged unions in this client — both externally-tagged (e.g. `Aggregate`, `Suggest`) and internally-tagged (e.g. `Query`, `Property`, `Processor`, `Analyzer`, `TokenFilterDefinition`) — support a `_Custom` variant kind. + +When the server returns a discriminator value that isn't natively modeled (for example, a type introduced by a plugin), the client captures it as `Kind._Custom` with the raw JSON preserved as `JsonData`, rather than throwing a deserialization error. + +### Reading a custom variant + +```java +SearchResponse response = client.search(searchRequest, IndexData.class); + +for (Map.Entry entry : response.aggregations().entrySet()) { + Aggregate agg = entry.getValue(); + if (agg._isCustom()) { + // _customKind() returns the type name from the server (e.g. "my_plugin_agg") + String typeName = agg._customKind(); + // _custom() returns the raw JSON body as JsonData + JsonData rawData = agg._custom(); + System.out.printf("Custom aggregation '%s' of type '%s': %s%n", + entry.getKey(), typeName, rawData.toJson()); + } +} +``` + +### Building a custom variant + +```java +Aggregate custom = new Aggregate.Builder() + ._custom("my_plugin_agg", JsonData.of(Map.of("score", 42))) + .build(); +``` + +The same `_isCustom()`, `_customKind()`, `_custom()`, and `Builder._custom(type, data)` methods are available on every discriminated tagged union type. diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java index e3b7869072..4228ab801e 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java @@ -44,6 +44,7 @@ import javax.annotation.Generated; import javax.annotation.Nonnull; import org.opensearch.client.json.ExternallyTaggedUnion; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; @@ -122,7 +123,9 @@ public enum Kind implements JsonEnum { Umterms("umterms"), ValueCount("value_count"), VariableWidthHistogram("variable_width_histogram"), - WeightedAvg("weighted_avg"); + WeightedAvg("weighted_avg"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -138,6 +141,7 @@ public String jsonValue() { private final Kind _kind; private final AggregateVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -149,14 +153,23 @@ public final AggregateVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public Aggregate(AggregateVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._aggregateKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Aggregate(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Aggregate of(Function> fn) { @@ -1139,6 +1152,25 @@ public WeightedAvgAggregate weightedAvg() { return TaggedUnionUtils.get(this, Kind.WeightedAvg); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -1157,12 +1189,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private AggregateVariant _value; + private String _customKind; public Builder() {} private Builder(Aggregate o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder adjacencyMatrix(AdjacencyMatrixAggregate v) { @@ -1809,6 +1843,19 @@ public ObjectBuilder weightedAvg(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Aggregate build() { _checkSingleUse(); @@ -1818,6 +1865,10 @@ public Aggregate build() { public static final ExternallyTaggedUnion.TypedKeysDeserializer _TYPED_KEYS_DESERIALIZER; + private static Aggregate _buildCustom(String type, JsonData data) { + return new Builder()._custom(type, data).build(); + } + static { Map> deserializers = new HashMap<>(); deserializers.put("adjacency_matrix", AdjacencyMatrixAggregate._DESERIALIZER); @@ -1882,7 +1933,8 @@ public Aggregate build() { deserializers.put("variable_width_histogram", VariableWidthHistogramAggregate._DESERIALIZER); deserializers.put("weighted_avg", WeightedAvgAggregate._DESERIALIZER); - _TYPED_KEYS_DESERIALIZER = new ExternallyTaggedUnion.Deserializer<>(deserializers, Aggregate::new).typedKeys(); + _TYPED_KEYS_DESERIALIZER = new ExternallyTaggedUnion.Deserializer<>(deserializers, Aggregate::new, Aggregate::_buildCustom) + .typedKeys(); } @Override @@ -1890,6 +1942,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -1898,6 +1951,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Aggregate other = (Aggregate) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements AggregateVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _aggregateKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregation.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregation.java index 57994ec30d..45194935a6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregation.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregation.java @@ -132,7 +132,9 @@ public enum Kind implements JsonEnum { TopHits("top_hits"), ValueCount("value_count"), VariableWidthHistogram("variable_width_histogram"), - WeightedAvg("weighted_avg"); + WeightedAvg("weighted_avg"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -148,6 +150,7 @@ public String jsonValue() { private final Kind _kind; private final AggregationVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -159,12 +162,20 @@ public final AggregationVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + @Nonnull private final Map meta; public Aggregation(AggregationVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._aggregationKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; this.meta = null; } @@ -172,6 +183,7 @@ private Aggregation(Builder builder) { this.meta = ApiTypeHelper.unmodifiable(builder.meta); this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Aggregation of(Function> fn) { @@ -1226,6 +1238,25 @@ public WeightedAverageAggregation weightedAvg() { return TaggedUnionUtils.get(this, Kind.WeightedAvg); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); @@ -1238,7 +1269,7 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } generator.writeEnd(); } - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -1258,6 +1289,7 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase { private Kind _kind; private AggregationVariant _value; + private String _customKind; @Nullable private Map meta; @@ -1267,6 +1299,7 @@ private Builder(Aggregation o) { this.meta = _mapCopy(o.meta); this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } /** @@ -1971,6 +2004,19 @@ public ContainerBuilder weightedAvg(Function"); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return new ContainerBuilder(); + } + protected Aggregation build() { _checkSingleUse(); return new Aggregation(this); @@ -2079,6 +2125,9 @@ protected static void setupAggregationDeserializer(ObjectDeserializer o op.add(Builder::valueCount, ValueCountAggregation._DESERIALIZER, "value_count"); op.add(Builder::variableWidthHistogram, VariableWidthHistogramAggregation._DESERIALIZER, "variable_width_histogram"); op.add(Builder::weightedAvg, WeightedAverageAggregation._DESERIALIZER, "weighted_avg"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -2092,6 +2141,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); result = 31 * result + Objects.hashCode(this.meta); return result; } @@ -2103,6 +2153,42 @@ public boolean equals(Object o) { Aggregation other = (Aggregation) o; return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind) && Objects.equals(this.meta, other.meta); } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements AggregationVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _aggregationKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java index 514a973f88..37fa47d52c 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -71,7 +72,9 @@ public enum Kind implements JsonEnum { Holt("holt"), HoltWinters("holt_winters"), Linear("linear"), - Simple("simple"); + Simple("simple"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -95,6 +98,7 @@ public Aggregation.Kind _aggregationKind() { private final Kind _kind; private final MovingAverageAggregationVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -106,14 +110,23 @@ public final MovingAverageAggregationVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public MovingAverageAggregation(MovingAverageAggregationVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._movingAverageAggregationKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private MovingAverageAggregation(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static MovingAverageAggregation of(Function> fn) { @@ -200,6 +213,25 @@ public SimpleMovingAverageAggregation simple() { return TaggedUnionUtils.get(this, Kind.Simple); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -218,12 +250,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private MovingAverageAggregationVariant _value; + private String _customKind; public Builder() {} private Builder(MovingAverageAggregation o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder ewma(EwmaMovingAverageAggregation v) { @@ -286,6 +320,19 @@ public ObjectBuilder simple( return this.simple(fn.apply(new SimpleMovingAverageAggregation.Builder()).build()); } + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public ObjectBuilder _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public MovingAverageAggregation build() { _checkSingleUse(); @@ -300,6 +347,9 @@ protected static void setupMovingAverageAggregationDeserializer(ObjectDeserializ op.add(Builder::linear, LinearMovingAverageAggregation._DESERIALIZER, "linear"); op.add(Builder::simple, SimpleMovingAverageAggregation._DESERIALIZER, "simple"); op.setTypeProperty("model", null); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -313,6 +363,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -321,6 +372,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; MovingAverageAggregation other = (MovingAverageAggregation) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements MovingAverageAggregationVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _movingAverageAggregationKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java index 611502d7f1..88b3da4a42 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -80,7 +81,9 @@ public enum Kind implements JsonEnum { Snowball("snowball"), Standard("standard"), Stop("stop"), - Whitespace("whitespace"); + Whitespace("whitespace"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -96,6 +99,7 @@ public String jsonValue() { private final Kind _kind; private final AnalyzerVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -107,14 +111,23 @@ public final AnalyzerVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public Analyzer(AnalyzerVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._analyzerKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Analyzer(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Analyzer of(Function> fn) { @@ -409,6 +422,25 @@ public WhitespaceAnalyzer whitespace() { return TaggedUnionUtils.get(this, Kind.Whitespace); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -427,12 +459,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private AnalyzerVariant _value; + private String _customKind; public Builder() {} private Builder(Analyzer o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder cjk(CjkAnalyzer v) { @@ -615,6 +649,19 @@ public ObjectBuilder whitespace(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Analyzer build() { _checkSingleUse(); @@ -642,6 +689,9 @@ protected static void setupAnalyzerDeserializer(ObjectDeserializer op) op.add(Builder::stop, StopAnalyzer._DESERIALIZER, "stop"); op.add(Builder::whitespace, WhitespaceAnalyzer._DESERIALIZER, "whitespace"); op.setTypeProperty("type", Kind.Custom.jsonValue()); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -655,6 +705,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -663,6 +714,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Analyzer other = (Analyzer) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements AnalyzerVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _analyzerKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java index 4763559d01..cd8fd5c67b 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -67,7 +68,9 @@ public enum Kind implements JsonEnum { IcuNormalizer("icu_normalizer"), KuromojiIterationMark("kuromoji_iteration_mark"), Mapping("mapping"), - PatternReplace("pattern_replace"); + PatternReplace("pattern_replace"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -83,6 +86,7 @@ public String jsonValue() { private final Kind _kind; private final CharFilterDefinitionVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -94,14 +98,23 @@ public final CharFilterDefinitionVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public CharFilterDefinition(CharFilterDefinitionVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._charFilterDefinitionKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private CharFilterDefinition(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static CharFilterDefinition of(Function> fn) { @@ -188,6 +201,25 @@ public PatternReplaceCharFilter patternReplace() { return TaggedUnionUtils.get(this, Kind.PatternReplace); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -206,12 +238,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private CharFilterDefinitionVariant _value; + private String _customKind; public Builder() {} private Builder(CharFilterDefinition o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder htmlStrip(HtmlStripCharFilter v) { @@ -270,6 +304,19 @@ public ObjectBuilder patternReplace( return this.patternReplace(fn.apply(new PatternReplaceCharFilter.Builder()).build()); } + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public ObjectBuilder _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public CharFilterDefinition build() { _checkSingleUse(); @@ -284,6 +331,9 @@ protected static void setupCharFilterDefinitionDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -297,6 +347,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -305,6 +356,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; CharFilterDefinition other = (CharFilterDefinition) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements CharFilterDefinitionVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _charFilterDefinitionKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java index 1982f0a12f..5fe39f1cf6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -64,7 +65,9 @@ public class Normalizer implements TaggedUnion"); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Normalizer(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Normalizer of(Function> fn) { @@ -137,6 +150,25 @@ public LowercaseNormalizer lowercase() { return TaggedUnionUtils.get(this, Kind.Lowercase); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -155,12 +187,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private NormalizerVariant _value; + private String _customKind; public Builder() {} private Builder(Normalizer o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder custom(CustomNormalizer v) { @@ -183,6 +217,19 @@ public ObjectBuilder lowercase(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Normalizer build() { _checkSingleUse(); @@ -194,6 +241,9 @@ protected static void setupNormalizerDeserializer(ObjectDeserializer op op.add(Builder::custom, CustomNormalizer._DESERIALIZER, "custom"); op.add(Builder::lowercase, LowercaseNormalizer._DESERIALIZER, "lowercase"); op.setTypeProperty("type", Kind.Custom.jsonValue()); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -207,6 +257,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -215,6 +266,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Normalizer other = (Normalizer) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements NormalizerVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _normalizerKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java index 56bd2a8e00..9f9ff7224a 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -112,7 +113,9 @@ public enum Kind implements JsonEnum { Unique("unique"), Uppercase("uppercase"), WordDelimiter("word_delimiter"), - WordDelimiterGraph("word_delimiter_graph"); + WordDelimiterGraph("word_delimiter_graph"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -128,6 +131,7 @@ public String jsonValue() { private final Kind _kind; private final TokenFilterDefinitionVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -139,14 +143,23 @@ public final TokenFilterDefinitionVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public TokenFilterDefinition(TokenFilterDefinitionVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._tokenFilterDefinitionKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private TokenFilterDefinition(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static TokenFilterDefinition of(Function> fn) { @@ -953,6 +966,25 @@ public WordDelimiterGraphTokenFilter wordDelimiterGraph() { return TaggedUnionUtils.get(this, Kind.WordDelimiterGraph); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -971,12 +1003,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private TokenFilterDefinitionVariant _value; + private String _customKind; public Builder() {} private Builder(TokenFilterDefinition o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder asciifolding(AsciiFoldingTokenFilter v) { @@ -1545,6 +1579,19 @@ public ObjectBuilder wordDelimiterGraph( return this.wordDelimiterGraph(fn.apply(new WordDelimiterGraphTokenFilter.Builder()).build()); } + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public ObjectBuilder _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public TokenFilterDefinition build() { _checkSingleUse(); @@ -1604,6 +1651,9 @@ protected static void setupTokenFilterDefinitionDeserializer(ObjectDeserializer< op.add(Builder::wordDelimiter, WordDelimiterTokenFilter._DESERIALIZER, "word_delimiter"); op.add(Builder::wordDelimiterGraph, WordDelimiterGraphTokenFilter._DESERIALIZER, "word_delimiter_graph"); op.setTypeProperty("type", null); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -1617,6 +1667,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -1625,6 +1676,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; TokenFilterDefinition other = (TokenFilterDefinition) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements TokenFilterDefinitionVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _tokenFilterDefinitionKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java index b999d3da57..91dfaca6ce 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -79,7 +80,9 @@ public enum Kind implements JsonEnum { SmartcnTokenizer("smartcn_tokenizer"), Standard("standard"), UaxUrlEmail("uax_url_email"), - Whitespace("whitespace"); + Whitespace("whitespace"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -95,6 +98,7 @@ public String jsonValue() { private final Kind _kind; private final TokenizerDefinitionVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -106,14 +110,23 @@ public final TokenizerDefinitionVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public TokenizerDefinition(TokenizerDefinitionVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._tokenizerDefinitionKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private TokenizerDefinition(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static TokenizerDefinition of(Function> fn) { @@ -392,6 +405,25 @@ public WhitespaceTokenizer whitespace() { return TaggedUnionUtils.get(this, Kind.Whitespace); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -410,12 +442,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private TokenizerDefinitionVariant _value; + private String _customKind; public Builder() {} private Builder(TokenizerDefinition o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder charGroup(CharGroupTokenizer v) { @@ -598,6 +632,19 @@ public ObjectBuilder whitespace(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public TokenizerDefinition build() { _checkSingleUse(); @@ -624,6 +671,9 @@ protected static void setupTokenizerDefinitionDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -637,6 +687,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -645,6 +696,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; TokenizerDefinition other = (TokenizerDefinition) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements TokenizerDefinitionVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _tokenizerDefinitionKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java index 87a02aa2eb..d6b39e212f 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -109,7 +110,9 @@ public enum Kind implements JsonEnum { Version("version"), Wildcard("wildcard"), XyPoint("xy_point"), - XyShape("xy_shape"); + XyShape("xy_shape"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -125,6 +128,7 @@ public String jsonValue() { private final Kind _kind; private final PropertyVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -136,14 +140,23 @@ public final PropertyVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public Property(PropertyVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._propertyKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Property(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Property of(Function> fn) { @@ -902,6 +915,25 @@ public XyShapeProperty xyShape() { return TaggedUnionUtils.get(this, Kind.XyShape); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -920,12 +952,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private PropertyVariant _value; + private String _customKind; public Builder() {} private Builder(Property o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder aggregateMetricDouble(AggregateMetricDoubleProperty v) { @@ -1410,6 +1444,19 @@ public ObjectBuilder xyShape(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Property build() { _checkSingleUse(); @@ -1466,6 +1513,9 @@ protected static void setupPropertyDeserializer(ObjectDeserializer op) op.add(Builder::xyPoint, XyPointProperty._DESERIALIZER, "xy_point"); op.add(Builder::xyShape, XyShapeProperty._DESERIALIZER, "xy_shape"); op.setTypeProperty("type", Kind.Object.jsonValue()); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -1479,6 +1529,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -1487,6 +1538,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Property other = (Property) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements PropertyVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _propertyKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScore.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScore.java index 5f2b7994ac..2e4a1d464a 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScore.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScore.java @@ -42,6 +42,7 @@ import javax.annotation.Generated; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -70,7 +71,9 @@ public enum Kind implements JsonEnum { Gauss("gauss"), Linear("linear"), RandomScore("random_score"), - ScriptScore("script_score"); + ScriptScore("script_score"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -86,6 +89,7 @@ public String jsonValue() { private final Kind _kind; private final FunctionScoreVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -97,6 +101,13 @@ public final FunctionScoreVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + @Nullable private final Query filter; @@ -111,6 +122,7 @@ public FunctionScore(FunctionScoreVariant value) { this._kind = null; this._value = null; } + this._customKind = null; this.filter = null; this.weight = null; } @@ -125,6 +137,7 @@ private FunctionScore(Builder builder) { this._kind = null; this._value = null; } + this._customKind = builder._customKind; } public static FunctionScore of(Function> fn) { @@ -243,6 +256,25 @@ public ScriptScoreFunction scriptScore() { return TaggedUnionUtils.get(this, Kind.ScriptScore); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); @@ -256,7 +288,7 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.write(this.weight); } if (_kind != null) { - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -277,6 +309,7 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private FunctionScoreVariant _value; + private String _customKind; @Nullable private Query filter; @Nullable @@ -289,6 +322,7 @@ private Builder(FunctionScore o) { this.weight = o.weight; this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } /** @@ -379,6 +413,19 @@ public ContainerBuilder scriptScore(Function"); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return new ContainerBuilder(); + } + public FunctionScore build() { _checkSingleUse(); return new FunctionScore(this); @@ -429,6 +476,9 @@ protected static void setupFunctionScoreDeserializer(ObjectDeserializer op.add(Builder::linear, DecayFunction._DESERIALIZER, "linear"); op.add(Builder::randomScore, RandomScoreFunction._DESERIALIZER, "random_score"); op.add(Builder::scriptScore, ScriptScoreFunction._DESERIALIZER, "script_score"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -442,6 +492,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); result = 31 * result + Objects.hashCode(this.filter); result = 31 * result + Objects.hashCode(this.weight); return result; @@ -454,7 +505,43 @@ public boolean equals(Object o) { FunctionScore other = (FunctionScore) o; return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind) && Objects.equals(this.filter, other.filter) && Objects.equals(this.weight, other.weight); } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements FunctionScoreVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _functionScoreKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java index 5ce5d4b196..f4ea6611b2 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -69,7 +70,9 @@ public enum Kind implements JsonEnum { Fuzzy("fuzzy"), Match("match"), Prefix("prefix"), - Wildcard("wildcard"); + Wildcard("wildcard"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -93,6 +96,7 @@ public IntervalsFilter.Kind _intervalsFilterKind() { private final Kind _kind; private final IntervalsVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -104,14 +108,23 @@ public final IntervalsVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public Intervals(IntervalsVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._intervalsKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Intervals(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Intervals of(Function> fn) { @@ -214,10 +227,29 @@ public IntervalsWildcard wildcard() { return TaggedUnionUtils.get(this, Kind.Wildcard); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -237,12 +269,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private IntervalsVariant _value; + private String _customKind; public Builder() {} private Builder(Intervals o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder allOf(IntervalsAllOf v) { @@ -305,6 +339,19 @@ public ObjectBuilder wildcard(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Intervals build() { _checkSingleUse(); @@ -319,6 +366,9 @@ protected static void setupIntervalsDeserializer(ObjectDeserializer op) op.add(Builder::match, IntervalsMatch._DESERIALIZER, "match"); op.add(Builder::prefix, IntervalsPrefix._DESERIALIZER, "prefix"); op.add(Builder::wildcard, IntervalsWildcard._DESERIALIZER, "wildcard"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -332,6 +382,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -340,6 +391,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Intervals other = (Intervals) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements IntervalsVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _intervalsKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java index 945a710bdc..43cf2cb241 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -73,7 +74,9 @@ public enum Kind implements JsonEnum { NotContaining("not_containing"), NotOverlapping("not_overlapping"), Overlapping("overlapping"), - Script("script"); + Script("script"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -89,6 +92,7 @@ public String jsonValue() { private final Kind _kind; private final IntervalsFilterVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -100,14 +104,23 @@ public final IntervalsFilterVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public IntervalsFilter(IntervalsFilterVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._intervalsFilterKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private IntervalsFilter(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static IntervalsFilter of(Function> fn) { @@ -258,10 +271,29 @@ public Script script() { return TaggedUnionUtils.get(this, Kind.Script); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -281,12 +313,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private IntervalsFilterVariant _value; + private String _customKind; public Builder() {} private Builder(IntervalsFilter o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder after(Intervals v) { @@ -379,6 +413,19 @@ public ObjectBuilder script(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public IntervalsFilter build() { _checkSingleUse(); @@ -396,6 +443,9 @@ protected static void setupIntervalsFilterDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -409,6 +459,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -417,6 +468,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; IntervalsFilter other = (IntervalsFilter) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements IntervalsFilterVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _intervalsFilterKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java index 0df3091744..7c8d25d563 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -72,7 +73,9 @@ public enum Kind implements JsonEnum { Fuzzy("fuzzy"), Match("match"), Prefix("prefix"), - Wildcard("wildcard"); + Wildcard("wildcard"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -96,6 +99,7 @@ public Query.Kind _queryKind() { private final Kind _kind; private final IntervalsQueryVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -107,6 +111,13 @@ public final IntervalsQueryVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + @Nonnull private final String field; @@ -115,6 +126,7 @@ private IntervalsQuery(Builder builder) { this.field = ApiTypeHelper.requireNonNull(builder.field, this, "field"); this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static IntervalsQuery of(Function> fn) { @@ -225,12 +237,31 @@ public IntervalsWildcard wildcard() { return TaggedUnionUtils.get(this, Kind.Wildcard); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); generator.writeStartObject(this.field); super.serializeInternal(generator, mapper); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -251,6 +282,7 @@ public static Builder builder() { public static class Builder extends QueryBase.AbstractBuilder implements ObjectBuilder { private Kind _kind; private IntervalsQueryVariant _value; + private String _customKind; private String field; public Builder() {} @@ -260,6 +292,7 @@ private Builder(IntervalsQuery o) { this.field = o.field; this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } @Override @@ -337,6 +370,19 @@ public ObjectBuilder wildcard(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public IntervalsQuery build() { _checkSingleUse(); @@ -353,6 +399,9 @@ protected static void setupIntervalsQueryDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -366,6 +415,7 @@ public int hashCode() { int result = super.hashCode(); result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); result = 31 * result + this.field.hashCode(); return result; } @@ -378,6 +428,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; IntervalsQuery other = (IntervalsQuery) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && this.field.equals(other.field); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind) && this.field.equals(other.field); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements IntervalsQueryVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _intervalsQueryKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java index c3255666c1..13d865c336 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java @@ -125,7 +125,9 @@ public enum Kind implements JsonEnum { Type("type"), Wildcard("wildcard"), Wrapper("wrapper"), - XyShape("xy_shape"); + XyShape("xy_shape"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -149,6 +151,7 @@ public Aggregation.Kind _aggregationKind() { private final Kind _kind; private final Object _value; + private final String _customKind; @Override public final Kind _kind() { @@ -160,14 +163,23 @@ public final Object _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public Query(QueryVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._queryKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Query(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Query of(Function> fn) { @@ -1102,10 +1114,29 @@ public XyShapeQuery xyShape() { return TaggedUnionUtils.get(this, Kind.XyShape); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } else { @@ -1136,12 +1167,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private Object _value; + private String _customKind; public Builder() {} private Builder(Query o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder agentic(AgenticQuery v) { @@ -1720,6 +1753,19 @@ public ObjectBuilder xyShape(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Query build() { _checkSingleUse(); @@ -1786,6 +1832,9 @@ protected static void setupQueryDeserializer(ObjectDeserializer op) { op.add(Builder::wildcard, WildcardQuery._DESERIALIZER, "wildcard"); op.add(Builder::wrapper, WrapperQuery._DESERIALIZER, "wrapper"); op.add(Builder::xyShape, XyShapeQuery._DESERIALIZER, "xy_shape"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -1799,6 +1848,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -1807,6 +1857,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Query other = (Query) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements QueryVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _queryKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java index 285a353e14..a271208e9c 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -73,7 +74,9 @@ public enum Kind implements JsonEnum { SpanNot("span_not"), SpanOr("span_or"), SpanTerm("span_term"), - SpanWithin("span_within"); + SpanWithin("span_within"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -89,6 +92,7 @@ public String jsonValue() { private final Kind _kind; private final SpanQueryVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -100,14 +104,23 @@ public final SpanQueryVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public SpanQuery(SpanQueryVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._spanQueryKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private SpanQuery(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static SpanQuery of(Function> fn) { @@ -274,10 +287,29 @@ public SpanWithinQuery spanWithin() { return TaggedUnionUtils.get(this, Kind.SpanWithin); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -297,12 +329,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private SpanQueryVariant _value; + private String _customKind; public Builder() {} private Builder(SpanQuery o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder fieldMaskingSpan(SpanFieldMaskingQuery v) { @@ -405,6 +439,19 @@ public ObjectBuilder spanWithin(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public SpanQuery build() { _checkSingleUse(); @@ -423,6 +470,9 @@ protected static void setupSpanQueryDeserializer(ObjectDeserializer op) op.add(Builder::spanOr, SpanOrQuery._DESERIALIZER, "span_or"); op.add(Builder::spanTerm, SpanTermQuery._DESERIALIZER, "span_term"); op.add(Builder::spanWithin, SpanWithinQuery._DESERIALIZER, "span_within"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -436,6 +486,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -444,6 +495,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; SpanQuery other = (SpanQuery) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements SpanQueryVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _spanQueryKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java b/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java index b40fdaa4a4..e8a28740d4 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -64,7 +65,9 @@ public class ClusterRemoteInfo implements TaggedUnion"); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private ClusterRemoteInfo(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static ClusterRemoteInfo of(Function> fn) { @@ -137,6 +150,25 @@ public ClusterRemoteSniffInfo sniff() { return TaggedUnionUtils.get(this, Kind.Sniff); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -155,12 +187,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private ClusterRemoteInfoVariant _value; + private String _customKind; public Builder() {} private Builder(ClusterRemoteInfo o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder proxy(ClusterRemoteProxyInfo v) { @@ -183,6 +217,19 @@ public ObjectBuilder sniff(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public ClusterRemoteInfo build() { _checkSingleUse(); @@ -194,6 +241,9 @@ protected static void setupClusterRemoteInfoDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -207,6 +257,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -215,6 +266,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; ClusterRemoteInfo other = (ClusterRemoteInfo) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements ClusterRemoteInfoVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _clusterRemoteInfoKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/FieldSuggester.java b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/FieldSuggester.java index 30f01b8406..9ca2437fbd 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/FieldSuggester.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/FieldSuggester.java @@ -42,6 +42,7 @@ import javax.annotation.Generated; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -67,7 +68,9 @@ public class FieldSuggester implements TaggedUnion"); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; this.prefix = null; this.regex = null; this.text = null; @@ -117,6 +129,7 @@ private FieldSuggester(Builder builder) { this.text = builder.text; this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static FieldSuggester of(Function> fn) { @@ -195,6 +208,25 @@ public TermSuggester term() { return TaggedUnionUtils.get(this, Kind.Term); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); @@ -212,7 +244,7 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("text"); generator.write(this.text); } - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -232,6 +264,7 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase { private Kind _kind; private FieldSuggesterVariant _value; + private String _customKind; @Nullable private String prefix; @Nullable @@ -247,6 +280,7 @@ private Builder(FieldSuggester o) { this.text = o.text; this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } /** @@ -306,6 +340,19 @@ public ContainerBuilder term(Function"); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return new ContainerBuilder(); + } + protected FieldSuggester build() { _checkSingleUse(); return new FieldSuggester(this); @@ -355,6 +402,9 @@ protected static void setupFieldSuggesterDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -368,6 +418,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); result = 31 * result + Objects.hashCode(this.prefix); result = 31 * result + Objects.hashCode(this.regex); result = 31 * result + Objects.hashCode(this.text); @@ -381,8 +432,44 @@ public boolean equals(Object o) { FieldSuggester other = (FieldSuggester) o; return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind) && Objects.equals(this.prefix, other.prefix) && Objects.equals(this.regex, other.regex) && Objects.equals(this.text, other.text); } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements FieldSuggesterVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _fieldSuggesterKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } + } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java index e4da1b993f..89bea81660 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -66,7 +67,9 @@ public class SmoothingModel implements TaggedUnion"); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private SmoothingModel(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static SmoothingModel of(Function> fn) { @@ -155,10 +168,29 @@ public StupidBackoffSmoothingModel stupidBackoff() { return TaggedUnionUtils.get(this, Kind.StupidBackoff); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -178,12 +210,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private SmoothingModelVariant _value; + private String _customKind; public Builder() {} private Builder(SmoothingModel o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder laplace(LaplaceSmoothingModel v) { @@ -220,6 +254,19 @@ public ObjectBuilder stupidBackoff( return this.stupidBackoff(fn.apply(new StupidBackoffSmoothingModel.Builder()).build()); } + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public ObjectBuilder _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public SmoothingModel build() { _checkSingleUse(); @@ -231,6 +278,9 @@ protected static void setupSmoothingModelDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -244,6 +294,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -252,6 +303,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; SmoothingModel other = (SmoothingModel) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements SmoothingModelVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _smoothingModelKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java index b7c437d513..a26d9c5a34 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java @@ -44,6 +44,7 @@ import javax.annotation.Generated; import javax.annotation.Nonnull; import org.opensearch.client.json.ExternallyTaggedUnion; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; @@ -64,7 +65,9 @@ public class Suggest implements TaggedUnion"); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Suggest(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Suggest of(Function, ObjectBuilder>> fn) { @@ -153,6 +166,25 @@ public TermSuggest term() { return TaggedUnionUtils.get(this, Kind.Term); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { mapper.serialize(_value, generator); @@ -171,12 +203,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder> { private Kind _kind; private SuggestVariant _value; + private String _customKind; public Builder() {} private Builder(Suggest o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder> completion(CompletionSuggest v) { @@ -211,6 +245,19 @@ public ObjectBuilder> term(Function> _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Suggest build() { _checkSingleUse(); @@ -226,7 +273,11 @@ public static ExternallyTaggedUnion.TypedKeysDeserializer(deserializers, Suggest::new).typedKeys(); + return new ExternallyTaggedUnion.Deserializer<>( + deserializers, + Suggest::new, + (t, d) -> new Builder()._custom(t, d).build() + ).typedKeys(); } @Override @@ -234,6 +285,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -242,6 +294,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Suggest other = (Suggest) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements SuggestVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _suggestKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java index 70107bb962..64dc402c49 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -69,7 +70,9 @@ public class Action implements TaggedUnion, PlainJso public enum Kind implements JsonEnum { Add("add"), Remove("remove"), - RemoveIndex("remove_index"); + RemoveIndex("remove_index"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -85,6 +88,7 @@ public String jsonValue() { private final Kind _kind; private final ActionVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -96,14 +100,23 @@ public final ActionVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public Action(ActionVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._actionKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Action(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Action of(Function> fn) { @@ -158,10 +171,29 @@ public RemoveIndexAction removeIndex() { return TaggedUnionUtils.get(this, Kind.RemoveIndex); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -181,12 +213,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private ActionVariant _value; + private String _customKind; public Builder() {} private Builder(Action o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder add(AddAction v) { @@ -219,6 +253,19 @@ public ObjectBuilder removeIndex(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Action build() { _checkSingleUse(); @@ -230,6 +277,9 @@ protected static void setupActionDeserializer(ObjectDeserializer op) { op.add(Builder::add, AddAction._DESERIALIZER, "add"); op.add(Builder::remove, RemoveAction._DESERIALIZER, "remove"); op.add(Builder::removeIndex, RemoveIndexAction._DESERIALIZER, "remove_index"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -243,6 +293,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -251,6 +302,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Action other = (Action) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements ActionVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _actionKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java index f016292223..cb791f5965 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -97,7 +98,9 @@ public enum Kind implements JsonEnum { Trim("trim"), Uppercase("uppercase"), Urldecode("urldecode"), - UserAgent("user_agent"); + UserAgent("user_agent"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -113,6 +116,7 @@ public String jsonValue() { private final Kind _kind; private final ProcessorVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -124,14 +128,23 @@ public final ProcessorVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public Processor(ProcessorVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._processorKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private Processor(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static Processor of(Function> fn) { @@ -666,10 +679,29 @@ public UserAgentProcessor userAgent() { return TaggedUnionUtils.get(this, Kind.UserAgent); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -689,12 +721,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private ProcessorVariant _value; + private String _customKind; public Builder() {} private Builder(Processor o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder append(AppendProcessor v) { @@ -1029,6 +1063,19 @@ public ObjectBuilder userAgent(Function _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public Processor build() { _checkSingleUse(); @@ -1070,6 +1117,9 @@ protected static void setupProcessorDeserializer(ObjectDeserializer op) op.add(Builder::uppercase, UppercaseProcessor._DESERIALIZER, "uppercase"); op.add(Builder::urldecode, UrlDecodeProcessor._DESERIALIZER, "urldecode"); op.add(Builder::userAgent, UserAgentProcessor._DESERIALIZER, "user_agent"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -1083,6 +1133,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -1091,6 +1142,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Processor other = (Processor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements ProcessorVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _processorKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java index e131b2717d..0ebddbbdf1 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -65,7 +66,9 @@ public class PhaseResultsProcessor implements TaggedUnion"); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private PhaseResultsProcessor(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static PhaseResultsProcessor of(Function> fn) { @@ -138,10 +151,29 @@ public ScoreRankerPhaseResultsProcessor scoreRankerProcessor() { return TaggedUnionUtils.get(this, Kind.ScoreRankerProcessor); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -161,12 +193,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private PhaseResultsProcessorVariant _value; + private String _customKind; public Builder() {} private Builder(PhaseResultsProcessor o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder normalizationProcessor(NormalizationPhaseResultsProcessor v) { @@ -193,6 +227,19 @@ public ObjectBuilder scoreRankerProcessor( return this.scoreRankerProcessor(fn.apply(new ScoreRankerPhaseResultsProcessor.Builder()).build()); } + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public ObjectBuilder _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public PhaseResultsProcessor build() { _checkSingleUse(); @@ -203,6 +250,9 @@ public PhaseResultsProcessor build() { protected static void setupPhaseResultsProcessorDeserializer(ObjectDeserializer op) { op.add(Builder::normalizationProcessor, NormalizationPhaseResultsProcessor._DESERIALIZER, "normalization-processor"); op.add(Builder::scoreRankerProcessor, ScoreRankerPhaseResultsProcessor._DESERIALIZER, "score-ranker-processor"); + op.setUnknownFieldHandler( + (builder, name, parser, mapper) -> builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -216,6 +266,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -224,6 +275,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; PhaseResultsProcessor other = (PhaseResultsProcessor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements PhaseResultsProcessorVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _phaseResultsProcessorKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java index 39fd740da3..09632b03c5 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -68,7 +69,9 @@ public enum Kind implements JsonEnum { FilterQuery("filter_query"), NeuralQueryEnricher("neural_query_enricher"), Oversample("oversample"), - Script("script"); + Script("script"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -84,6 +87,7 @@ public String jsonValue() { private final Kind _kind; private final RequestProcessorVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -95,14 +99,23 @@ public final RequestProcessorVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public RequestProcessor(RequestProcessorVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._requestProcessorKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private RequestProcessor(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static RequestProcessor of(Function> fn) { @@ -189,10 +202,29 @@ public SearchScriptRequestProcessor script() { return TaggedUnionUtils.get(this, Kind.Script); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -212,12 +244,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private RequestProcessorVariant _value; + private String _customKind; public Builder() {} private Builder(RequestProcessor o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder agenticQueryTranslator(AgenticQueryTranslatorRequestProcessor v) { @@ -280,6 +314,19 @@ public ObjectBuilder script( return this.script(fn.apply(new SearchScriptRequestProcessor.Builder()).build()); } + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public ObjectBuilder _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public RequestProcessor build() { _checkSingleUse(); @@ -293,6 +340,9 @@ protected static void setupRequestProcessorDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -306,6 +356,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -314,6 +365,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; RequestProcessor other = (RequestProcessor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements RequestProcessorVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _requestProcessorKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java index 37aa18aa3d..f5e372d66a 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java @@ -41,6 +41,7 @@ import java.util.function.Function; import javax.annotation.Generated; import javax.annotation.Nonnull; +import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -72,7 +73,9 @@ public enum Kind implements JsonEnum { RetrievalAugmentedGeneration("retrieval_augmented_generation"), Sort("sort"), Split("split"), - TruncateHits("truncate_hits"); + TruncateHits("truncate_hits"), + /** A custom variant type not natively supported by this client. */ + _Custom(null); private final String jsonValue; @@ -88,6 +91,7 @@ public String jsonValue() { private final Kind _kind; private final ResponseProcessorVariant _value; + private final String _customKind; @Override public final Kind _kind() { @@ -99,14 +103,23 @@ public final ResponseProcessorVariant _get() { return _value; } + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } + public ResponseProcessor(ResponseProcessorVariant value) { this._kind = ApiTypeHelper.requireNonNull(value._responseProcessorKind(), this, ""); this._value = ApiTypeHelper.requireNonNull(value, this, ""); + this._customKind = null; } private ResponseProcessor(Builder builder) { this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, ""); this._value = ApiTypeHelper.requireNonNull(builder._value, builder, ""); + this._customKind = builder._customKind; } public static ResponseProcessor of(Function> fn) { @@ -257,10 +270,29 @@ public TruncateHitsResponseProcessor truncateHits() { return TaggedUnionUtils.get(this, Kind.TruncateHits); } + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public JsonData _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); if (_value instanceof JsonpSerializable) { ((JsonpSerializable) _value).serialize(generator, mapper); } @@ -280,12 +312,14 @@ public static Builder builder() { public static class Builder extends ObjectBuilderBase implements ObjectBuilder { private Kind _kind; private ResponseProcessorVariant _value; + private String _customKind; public Builder() {} private Builder(ResponseProcessor o) { this._kind = o._kind; this._value = o._value; + this._customKind = o._customKind; } public ObjectBuilder agenticContext(AgenticContextResponseProcessor v) { @@ -392,6 +426,19 @@ public ObjectBuilder truncateHits( return this.truncateHits(fn.apply(new TruncateHitsResponseProcessor.Builder()).build()); } + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public ObjectBuilder _custom(String type, JsonData data) { + this._kind = Kind._Custom; + this._customKind = ApiTypeHelper.requireNonNull(type, this, ""); + this._value = new CustomVariant(ApiTypeHelper.requireNonNull(data, this, "")); + return this; + } + @Override public ResponseProcessor build() { _checkSingleUse(); @@ -413,6 +460,9 @@ protected static void setupResponseProcessorDeserializer(ObjectDeserializer builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper)) + ); } public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( @@ -426,6 +476,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this._kind); result = 31 * result + Objects.hashCode(this._value); + result = 31 * result + Objects.hashCode(this._customKind); return result; } @@ -434,6 +485,41 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; ResponseProcessor other = (ResponseProcessor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value); + return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + } + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements ResponseProcessorVariant, PlainJsonSerializable { + private final JsonData data; + + CustomVariant(JsonData data) { + this.data = data; + } + + public JsonData data() { + return data; + } + + @Override + public Kind _responseProcessorKind() { + return Kind._Custom; + } + + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } } } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache index 1b45c88676..2ff0b26a9d 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache @@ -3,7 +3,9 @@ * {@link {{className}}} variant kinds. */ public enum Kind{{#discriminated}} implements {{TYPES.Client.Json.JsonEnum}}{{/discriminated}} { - {{#variants}}{{#pascalCase}}{{name}}{{/pascalCase}}{{#discriminated}}({{#quoted}}{{name}}{{/quoted}}){{/discriminated}}{{^-last}},{{/-last}}{{/variants}} + {{#variants}}{{#pascalCase}}{{name}}{{/pascalCase}}{{#discriminated}}({{#quoted}}{{name}}{{/quoted}}){{/discriminated}}{{^-last}},{{/-last}}{{/variants}}{{#discriminated}}, + /** A custom variant type not natively supported by this client. */ + _Custom(null){{/discriminated}} {{#discriminated}}; private final String jsonValue; @@ -25,6 +27,9 @@ private final Kind _kind; private final {{variantBaseType}} _value; +{{#discriminated}} + private final String _customKind; +{{/discriminated}} @Override public final Kind _kind() { @@ -35,6 +40,15 @@ public final {{variantBaseType}} _get() { return _value; } +{{#discriminated}} + + /** + * Returns the actual type name when {@code _kind() == Kind._Custom}, otherwise {@code null}. + */ + public final String _customKind() { + return _customKind; + } +{{/discriminated}} {{#hasFields}} {{>ObjectShape/Fields}} @@ -54,6 +68,9 @@ this._value = null; } {{/isOptionalExternallyDiscriminated}} + {{#discriminated}} + this._customKind = null; + {{/discriminated}} {{#fields}} this.{{name}} = null; {{/fields}} @@ -84,6 +101,9 @@ this._value = null; } {{/isOptionalExternallyDiscriminated}} + {{#discriminated}} + this._customKind = builder._customKind; + {{/discriminated}} } public static{{#typeParameters}} {{.}}{{/typeParameters}} {{selfType}} of({{selfType.builderFnType}} fn) { @@ -125,6 +145,27 @@ } {{/variants}} +{{#discriminated}} + + /** + * Is this variant instance of kind {@code _custom}? + */ + public boolean _isCustom() { + return _kind == Kind._Custom; + } + + /** + * Get the raw JSON data for a custom (plugin-provided) variant type. + * + * @throws IllegalStateException if the current variant is not the {@code _custom} kind. + */ + public {{TYPES.Client.Json.JsonData}} _custom() { + if (_kind != Kind._Custom) { + throw new IllegalStateException("Expected variant kind '_custom' but got '" + _kind + "'"); + } + return ((CustomVariant) _value).data(); + } +{{/discriminated}} {{>TaggedUnionShape/Serialize}} @@ -138,6 +179,9 @@ public static class Builder{{#typeParameters}}{{.}}{{/typeParameters}} extends {{#extendsOtherShape}}{{extendsType}}.AbstractBuilder{{/extendsOtherShape}}{{^extendsOtherShape}}{{TYPES.Client.Util.ObjectBuilderBase}}{{/extendsOtherShape}}{{#needsContainerBuilder}}{{#isOptionalExternallyDiscriminated}} implements {{TYPES.Client.Util.ObjectBuilder}}<{{selfType}}>{{/isOptionalExternallyDiscriminated}}{{/needsContainerBuilder}}{{^needsContainerBuilder}} implements {{TYPES.Client.Util.ObjectBuilder}}<{{selfType}}>{{/needsContainerBuilder}} { private Kind _kind; private {{variantBaseType}} _value; + {{#discriminated}} + private String _customKind; + {{/discriminated}} {{>ObjectShape/Builder/Fields}} public Builder() {} @@ -146,6 +190,9 @@ {{>ObjectShape/Builder/CopyCtorImpl}} this._kind = o._kind; this._value = o._value; + {{#discriminated}} + this._customKind = o._customKind; + {{/discriminated}} } {{#extendsOtherShape}} @@ -171,6 +218,21 @@ {{/type.hasBuilder}} {{/variants}} + {{#discriminated}} + /** + * Set a custom (plugin-provided) variant. + * + * @param type the variant type name as returned by the server + * @param data the raw JSON body of the variant result + */ + public {{^needsContainerBuilder}}{{TYPES.Client.Util.ObjectBuilder}}<{{selfType}}>{{/needsContainerBuilder}}{{#needsContainerBuilder}}ContainerBuilder{{/needsContainerBuilder}} _custom(String type, {{TYPES.Client.Json.JsonData}} data) { + this._kind = Kind._Custom; + this._customKind = {{TYPES.Client.Util.ApiTypeHelper}}.requireNonNull(type, this, ""); + this._value = new CustomVariant({{TYPES.Client.Util.ApiTypeHelper}}.requireNonNull(data, this, "")); + return {{^needsContainerBuilder}}this{{/needsContainerBuilder}}{{#needsContainerBuilder}}new ContainerBuilder(){{/needsContainerBuilder}}; + } + + {{/discriminated}} {{^needsContainerBuilder}}@Override public{{/needsContainerBuilder}}{{#needsContainerBuilder}}{{#isOptionalExternallyDiscriminated}}public{{/isOptionalExternallyDiscriminated}}{{^isOptionalExternallyDiscriminated}}protected{{/isOptionalExternallyDiscriminated}}{{/needsContainerBuilder}} {{selfType}} build() { _checkSingleUse(); @@ -195,7 +257,73 @@ {{>TaggedUnionShape/Deserialize}} +{{#discriminated}} + @Override + public int hashCode() { + int result = 17; + result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._kind); + result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._value); + result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._customKind); + {{#fields}} + result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this.{{name}}); + {{/fields}} + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + {{className}}{{#typeParameters}}{{/typeParameters}} other = ({{className}}{{#typeParameters}}{{/typeParameters}}) o; + return {{TYPES.Java.Util.Objects}}.equals(this._kind, other._kind) + && {{TYPES.Java.Util.Objects}}.equals(this._value, other._value) + && {{TYPES.Java.Util.Objects}}.equals(this._customKind, other._customKind) + {{#fields}} + && {{TYPES.Java.Util.Objects}}.equals(this.{{name}}, other.{{name}}) + {{/fields}} + ; + } +{{/discriminated}} +{{^discriminated}} {{>ObjectShape/HashCode}} {{>ObjectShape/Equals}} +{{/discriminated}} +{{#discriminated}} + + // Wrapper so JsonData fits the variant interface slot for custom/plugin types + private static final class CustomVariant implements {{variantInterfaceType}}, {{TYPES.Client.Json.PlainJsonSerializable}} { + private final {{TYPES.Client.Json.JsonData}} data; + + CustomVariant({{TYPES.Client.Json.JsonData}} data) { + this.data = data; + } + + public {{TYPES.Client.Json.JsonData}} data() { + return data; + } + + @Override + public Kind _{{#camelCase}}{{className}}{{/camelCase}}Kind() { + return Kind._Custom; + } + + @Override + public void serialize({{TYPES.Jakarta.Json.Stream.JsonGenerator}} generator, {{TYPES.Client.Json.JsonpMapper}} mapper) { + data.serialize(generator, mapper); + } + + @Override + public int hashCode() { + return data.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return data.equals(((CustomVariant) o).data); + } + } +{{/discriminated}} } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Deserialize.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Deserialize.mustache index 8b398f6800..b80dadf9b0 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Deserialize.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Deserialize.mustache @@ -14,6 +14,7 @@ {{#singleKeyMap}} op.setKey(Builder::{{name}}, {{#type}}{{>Type/deserializer}}{{/type}}); {{/singleKeyMap}} + op.setUnknownFieldHandler((builder, name, parser, mapper) -> builder._custom(name, {{TYPES.Client.Json.JsonData}}._DESERIALIZER.deserialize(parser, mapper))); } public static final {{TYPES.Client.Json.JsonpDeserializer}}<{{className}}> _DESERIALIZER = {{TYPES.Client.Json.ObjectBuilderDeserializer}}.lazy(Builder::new, {{className}}::setup{{className}}Deserializer, Builder::build); @@ -43,6 +44,10 @@ {{^typeParameters}} public static final {{TYPES.Client.Json.ExternallyTaggedUnion}}.TypedKeysDeserializer<{{className}}> _TYPED_KEYS_DESERIALIZER; + private static {{className}} _buildCustom(String type, {{TYPES.Client.Json.JsonData}} data) { + return new Builder()._custom(type, data).build(); + } + static { {{/typeParameters}} {{TYPES.Java.Util.Map}}> deserializers = new {{TYPES.Java.Util.HashMap}}<>(); @@ -51,10 +56,10 @@ {{/variants}} {{#typeParameters}} - return new {{TYPES.Client.Json.ExternallyTaggedUnion}}.Deserializer<>(deserializers, {{selfType}}::new).typedKeys(); + return new {{TYPES.Client.Json.ExternallyTaggedUnion}}.Deserializer<>(deserializers, {{selfType}}::new, (t, d) -> new Builder{{#typeParameters}}{{.}}{{/typeParameters}}()._custom(t, d).build()).typedKeys(); {{/typeParameters}} {{^typeParameters}} - _TYPED_KEYS_DESERIALIZER = new {{TYPES.Client.Json.ExternallyTaggedUnion}}.Deserializer<>(deserializers, {{selfType}}::new).typedKeys(); + _TYPED_KEYS_DESERIALIZER = new {{TYPES.Client.Json.ExternallyTaggedUnion}}.Deserializer<>(deserializers, {{selfType}}::new, {{className}}::_buildCustom).typedKeys(); {{/typeParameters}} } {{/usesTypedKeys}} \ No newline at end of file diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Serialize.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Serialize.mustache index cbf1b85eaa..95ef1f6c53 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Serialize.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape/Serialize.mustache @@ -22,7 +22,7 @@ public void serialize({{TYPES.Jakarta.Json.Stream.JsonGenerator}} generator, {{T if (_kind != null) { {{/isOptionalExternallyDiscriminated}} {{#externallyDiscriminated}} - generator.writeKey(_kind.jsonValue()); + generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue()); {{/externallyDiscriminated}} if (_value instanceof {{TYPES.Client.Json.JsonpSerializable}}) { (({{TYPES.Client.Json.JsonpSerializable}}) _value).serialize(generator, mapper); From 17146cfe90b8a0b78e663a97a187d15f02f54a1d Mon Sep 17 00:00:00 2001 From: Alexis Cote Date: Wed, 29 Jul 2026 16:24:33 -0400 Subject: [PATCH 3/6] test(json): add round-trip tests for _Custom variant deserialization and serialization - Test externally-tagged (Aggregate) deserialization of unknown type. - Test typed-keys round-trip serialization preserves custom type name. - Test internally-tagged (Query) round-trip. - Test Builder._custom() API and equality semantics. - Update CHANGELOG with feature and fix entries. --- CHANGELOG.md | 2 + .../opensearch/model/CustomVariantTest.java | 134 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/model/CustomVariantTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index b9ca65d964..14393f734b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Bump `org.apache.httpcomponents.client5:httpclient5` from 5.6 to 5.6.1 ([#1967](https://github.com/opensearch-project/opensearch-java/pull/1967)) ### Added +- Add `_Custom` variant kind to all discriminated tagged unions (e.g. `Aggregate`, `Suggest`, `Query`, `Property`, `Processor`) to gracefully handle plugin-provided types without deserialization failures - Run Java client integration tests with a Testcontainers-managed OpenSearch instance by default ([#2033](https://github.com/opensearch-project/opensearch-java/pull/2033)) - Detect AWS SDK `Apache5HttpClient` in `AwsSdk2Transport` body-method guardrail ([#1903](https://github.com/opensearch-project/opensearch-java/pull/1970)) - Support Jackson 3.x release line ([#1810](https://github.com/opensearch-project/opensearch-java/pull/1810)) @@ -25,6 +26,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Add transparent gRPC transport with HybridTransport (bulk over gRPC, REST fallback), translation layer, TLS, basic auth, AWS SigV4, and JWT support ([#2062](https://github.com/opensearch-project/opensearch-java/pull/2062)) ### Fixed +- Fix `JsonData._DESERIALIZER` to correctly handle a pre-consumed parser event in the three-argument `deserialize` overload ## [Unreleased 3.x] ### Added diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/model/CustomVariantTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/model/CustomVariantTest.java new file mode 100644 index 0000000000..91925f3fc4 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/model/CustomVariantTest.java @@ -0,0 +1,134 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.model; + +import jakarta.json.stream.JsonParser; +import java.io.StringReader; +import java.util.Map; +import org.junit.Test; +import org.opensearch.client.json.JsonData; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.opensearch._types.aggregations.Aggregate; +import org.opensearch.client.opensearch._types.query_dsl.Query; +import org.opensearch.client.opensearch.core.SearchResponse; + +/** + * Tests that unknown/plugin-provided aggregation types deserialize into the {@code _Custom} variant + * instead of throwing or silently dropping data. + */ +public class CustomVariantTest extends ModelTestCase { + + @Test + public void testUnknownAggregationTypeDeserializesToCustomVariant() { + // A response containing a fictional "my_plugin_agg" typed-key aggregation + String json = "{\"took\":1,\"timed_out\":false," + + "\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0}," + + "\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"hits\":[]}," + + "\"aggregations\":{\"my_plugin_agg#foo\":{\"custom_field\":42,\"label\":\"hello\"}}}"; + + JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json)); + SearchResponse response = SearchResponse._DESERIALIZER.deserialize(parser, mapper); + + Map aggs = response.aggregations(); + assertTrue("aggregation 'foo' should be present", aggs.containsKey("foo")); + + Aggregate agg = aggs.get("foo"); + assertEquals(Aggregate.Kind._Custom, agg._kind()); + assertTrue(agg._isCustom()); + assertEquals("my_plugin_agg", agg._customKind()); + + // The raw data is accessible and contains the original payload + JsonData data = agg._custom(); + assertNotNull(data); + assertEquals(42, data.toJson().asJsonObject().getInt("custom_field")); + assertEquals("hello", data.toJson().asJsonObject().getString("label")); + } + + @Test + public void testCustomVariantSerializesRoundTrip() { + // Build a custom variant programmatically + Aggregate agg = new Aggregate.Builder()._custom("my_plugin_agg", JsonData.of(Map.of("x", 1))).build(); + + assertTrue(agg._isCustom()); + assertEquals("my_plugin_agg", agg._customKind()); + + // Serialize and verify it produces JSON + String json = toJson(agg); + assertNotNull(json); + assertTrue("serialized JSON should contain the payload", json.contains("\"x\"")); + } + + @Test + public void testKnownAggregationTypeStillWorks() { + // Sanity: a known type (avg) still deserializes normally + String json = "{\"took\":1,\"timed_out\":false," + + "\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0}," + + "\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"hits\":[]}," + + "\"aggregations\":{\"avg#bar\":{\"value\":3.14}}}"; + + SearchResponse response = fromJson( + json, + SearchResponse.createSearchResponseDeserializer(JsonpDeserializer.of(Object.class)) + ); + + Aggregate agg = response.aggregations().get("bar"); + assertEquals(Aggregate.Kind.Avg, agg._kind()); + assertFalse(agg._isCustom()); + assertNull(agg._customKind()); + assertEquals(3.14, agg.avg().value(), 0.001); + } + + @Test + public void testCustomAggregateTypedKeysRoundTrip() { + // Simulates a typed-keys response with a custom aggregation, then re-serializes + String json = "{\"took\":1,\"timed_out\":false," + + "\"_shards\":{\"total\":1,\"successful\":1,\"skipped\":0,\"failed\":0}," + + "\"hits\":{\"total\":{\"value\":0,\"relation\":\"eq\"},\"hits\":[]}," + + "\"aggregations\":{\"my_plugin_agg#metric\":{\"score\":99}}}"; + + SearchResponse response = fromJson( + json, + SearchResponse.createSearchResponseDeserializer(JsonpDeserializer.of(Object.class)) + ); + + // Round-trip: serialize the response back to JSON + String reserialized = toJson(response); + // The typed-key format must use the custom type name, not "null" + assertTrue("typed-key must contain custom type name", reserialized.contains("my_plugin_agg#metric")); + assertTrue("payload must survive round-trip", reserialized.contains("\"score\"")); + } + + @Test + public void testCustomQueryVariantRoundTrip() { + // An internally-tagged query with a plugin-provided type + String json = "{\"my_plugin_query\":{\"param\":\"value\"}}"; + + Query query = fromJson(json, Query._DESERIALIZER); + + assertTrue(query._isCustom()); + assertEquals("my_plugin_query", query._customKind()); + assertNotNull(query._custom()); + + // Round-trip serialization + String reserialized = toJson(query); + assertTrue("must contain custom type key", reserialized.contains("\"my_plugin_query\"")); + assertTrue("must contain payload", reserialized.contains("\"param\"")); + } + + @Test + public void testCustomVariantEquality() { + Aggregate a = new Aggregate.Builder()._custom("type_a", JsonData.of(Map.of("x", 1))).build(); + Aggregate b = new Aggregate.Builder()._custom("type_a", JsonData.of(Map.of("x", 1))).build(); + Aggregate c = new Aggregate.Builder()._custom("type_b", JsonData.of(Map.of("x", 1))).build(); + + assertEquals(a, b); + assertEquals(a.hashCode(), b.hashCode()); + assertNotEquals(a, c); // different _customKind + } +} From d5ca738cfa79a00bb6caa8bf082785e371b725df Mon Sep 17 00:00:00 2001 From: Alexis Cote Date: Wed, 29 Jul 2026 16:46:31 -0400 Subject: [PATCH 4/6] chore: Lint code --- .../client/opensearch/_types/aggregations/Aggregate.java | 4 +++- .../_types/aggregations/MovingAverageAggregation.java | 4 +++- .../client/opensearch/_types/analysis/Analyzer.java | 4 +++- .../opensearch/_types/analysis/CharFilterDefinition.java | 4 +++- .../client/opensearch/_types/analysis/Normalizer.java | 4 +++- .../opensearch/_types/analysis/TokenFilterDefinition.java | 4 +++- .../opensearch/_types/analysis/TokenizerDefinition.java | 4 +++- .../client/opensearch/_types/mapping/Property.java | 4 +++- .../client/opensearch/_types/query_dsl/Intervals.java | 4 +++- .../client/opensearch/_types/query_dsl/IntervalsFilter.java | 4 +++- .../client/opensearch/_types/query_dsl/IntervalsQuery.java | 5 ++++- .../opensearch/client/opensearch/_types/query_dsl/Query.java | 4 +++- .../client/opensearch/_types/query_dsl/SpanQuery.java | 4 +++- .../opensearch/cluster/remote_info/ClusterRemoteInfo.java | 4 +++- .../client/opensearch/core/search/SmoothingModel.java | 4 +++- .../opensearch/client/opensearch/core/search/Suggest.java | 4 +++- .../client/opensearch/indices/update_aliases/Action.java | 4 +++- .../org/opensearch/client/opensearch/ingest/Processor.java | 4 +++- .../opensearch/search_pipeline/PhaseResultsProcessor.java | 4 +++- .../client/opensearch/search_pipeline/RequestProcessor.java | 4 +++- .../client/opensearch/search_pipeline/ResponseProcessor.java | 4 +++- 21 files changed, 64 insertions(+), 21 deletions(-) diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java index 4228ab801e..ab7e676b43 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/Aggregate.java @@ -1951,7 +1951,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Aggregate other = (Aggregate) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java index 37fa47d52c..36789e59c6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/aggregations/MovingAverageAggregation.java @@ -372,7 +372,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; MovingAverageAggregation other = (MovingAverageAggregation) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java index 88b3da4a42..13de047755 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java @@ -714,7 +714,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Analyzer other = (Analyzer) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java index cd8fd5c67b..e472158b3f 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharFilterDefinition.java @@ -356,7 +356,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; CharFilterDefinition other = (CharFilterDefinition) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java index 5fe39f1cf6..1301524a94 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java @@ -266,7 +266,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Normalizer other = (Normalizer) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java index 9f9ff7224a..e288553ea6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenFilterDefinition.java @@ -1676,7 +1676,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; TokenFilterDefinition other = (TokenFilterDefinition) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java index 91dfaca6ce..18e37e6431 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/TokenizerDefinition.java @@ -696,7 +696,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; TokenizerDefinition other = (TokenizerDefinition) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java index d6b39e212f..09c8d20aa3 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/Property.java @@ -1538,7 +1538,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Property other = (Property) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java index f4ea6611b2..50c8ed265d 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Intervals.java @@ -391,7 +391,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Intervals other = (Intervals) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java index 43cf2cb241..467d472889 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsFilter.java @@ -468,7 +468,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; IntervalsFilter other = (IntervalsFilter) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java index 7c8d25d563..2712fa152e 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java @@ -428,7 +428,10 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; IntervalsQuery other = (IntervalsQuery) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind) && this.field.equals(other.field); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind) + && this.field.equals(other.field); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java index 13d865c336..aa99b5ce05 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java @@ -1857,7 +1857,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Query other = (Query) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java index a271208e9c..381cf101e9 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQuery.java @@ -495,7 +495,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; SpanQuery other = (SpanQuery) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java b/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java index e8a28740d4..92b8ccd5dc 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/cluster/remote_info/ClusterRemoteInfo.java @@ -266,7 +266,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; ClusterRemoteInfo other = (ClusterRemoteInfo) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java index 89bea81660..95accaf8dd 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/SmoothingModel.java @@ -303,7 +303,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; SmoothingModel other = (SmoothingModel) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java index a26d9c5a34..d6356b6e54 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/core/search/Suggest.java @@ -294,7 +294,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Suggest other = (Suggest) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java index 64dc402c49..975b9b7370 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/indices/update_aliases/Action.java @@ -302,7 +302,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Action other = (Action) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java index cb791f5965..134a2a9bab 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ingest/Processor.java @@ -1142,7 +1142,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Processor other = (Processor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java index 0ebddbbdf1..2a13ba56b7 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/PhaseResultsProcessor.java @@ -275,7 +275,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; PhaseResultsProcessor other = (PhaseResultsProcessor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java index 09632b03c5..c7ef3837f6 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/RequestProcessor.java @@ -365,7 +365,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; RequestProcessor other = (RequestProcessor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java index f5e372d66a..db0f4ad393 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/search_pipeline/ResponseProcessor.java @@ -485,7 +485,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; ResponseProcessor other = (ResponseProcessor) o; - return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value) && Objects.equals(this._customKind, other._customKind); + return Objects.equals(this._kind, other._kind) + && Objects.equals(this._value, other._value) + && Objects.equals(this._customKind, other._customKind); } // Wrapper so JsonData fits the variant interface slot for custom/plugin types From 13a7b5869d297012607be618e4510d6814d9e8d2 Mon Sep 17 00:00:00 2001 From: Alexis Cote Date: Wed, 29 Jul 2026 16:50:43 -0400 Subject: [PATCH 5/6] fix: Regen files --- .../opensearch/_types/query_dsl/IntervalsQuery.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java index 2712fa152e..a299e8e4db 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java @@ -412,26 +412,23 @@ protected static void setupIntervalsQueryDeserializer(ObjectDeserializer Date: Wed, 29 Jul 2026 18:34:23 -0400 Subject: [PATCH 6/6] refactor: Simplify hash + equality generation --- .../_types/query_dsl/IntervalsQuery.java | 9 ++++-- .../codegen/model/TaggedUnionShape.java | 3 ++ .../templates/TaggedUnionShape.mustache | 29 ------------------- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java index a299e8e4db..2712fa152e 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java @@ -412,23 +412,26 @@ protected static void setupIntervalsQueryDeserializer(ObjectDeserializer getHashableFields() { var fields = new ArrayList(); fields.add(Field.builder().withName("_kind", true).withType(getMaterializedType().getNestedType("Kind")).build()); fields.add(Field.builder().withName("_value", true).withType(getVariantBaseType()).build()); + if (isDiscriminated()) { + fields.add(Field.builder().withName("_customKind", true).withType(Types.Java.Lang.String).build()); + } fields.addAll(super.getHashableFields()); return fields; } diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache index 2ff0b26a9d..9e693d507b 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/TaggedUnionShape.mustache @@ -257,38 +257,9 @@ {{>TaggedUnionShape/Deserialize}} -{{#discriminated}} - @Override - public int hashCode() { - int result = 17; - result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._kind); - result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._value); - result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this._customKind); - {{#fields}} - result = 31 * result + {{TYPES.Java.Util.Objects}}.hashCode(this.{{name}}); - {{/fields}} - return result; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || this.getClass() != o.getClass()) return false; - {{className}}{{#typeParameters}}{{/typeParameters}} other = ({{className}}{{#typeParameters}}{{/typeParameters}}) o; - return {{TYPES.Java.Util.Objects}}.equals(this._kind, other._kind) - && {{TYPES.Java.Util.Objects}}.equals(this._value, other._value) - && {{TYPES.Java.Util.Objects}}.equals(this._customKind, other._customKind) - {{#fields}} - && {{TYPES.Java.Util.Objects}}.equals(this.{{name}}, other.{{name}}) - {{/fields}} - ; - } -{{/discriminated}} -{{^discriminated}} {{>ObjectShape/HashCode}} {{>ObjectShape/Equals}} -{{/discriminated}} {{#discriminated}} // Wrapper so JsonData fits the variant interface slot for custom/plugin types