From 71d63d0481d20bd74bd128c154f6e224625786d8 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Sat, 2 Nov 2024 04:23:46 +1300 Subject: [PATCH] Generate KnnVectorProperty (#1255) * Generate KnnVectorProperty Signed-off-by: Thomas Farr * spotlessApply Signed-off-by: Thomas Farr * Add PR number Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr --- CHANGELOG.md | 19 +- .../_types/mapping/CorePropertyBase.java | 52 ++- .../_types/mapping/DocValuesPropertyBase.java | 32 +- .../_types/mapping/KnnVectorMethod.java | 293 +++++++++------ .../_types/mapping/KnnVectorProperty.java | 347 ++++++++++++++++++ .../_types/mapping/KnnVectorProperty.java | 186 ---------- .../client/codegen/model/ArrayShape.java | 12 +- .../model/DictionaryResponseShape.java | 6 +- .../client/codegen/model/EnumShape.java | 5 +- .../client/codegen/model/Namespace.java | 9 +- .../client/codegen/model/ObjectShape.java | 5 +- .../client/codegen/model/ReferenceKind.java | 3 +- .../client/codegen/model/RequestShape.java | 10 +- .../client/codegen/model/Shape.java | 36 +- .../client/codegen/model/SpecTransformer.java | 48 +-- .../codegen/model/TaggedUnionShape.java | 28 +- .../opensearch/client/codegen/model/Type.java | 1 + .../codegen/model/overrides/Overrides.java | 7 + .../model/overrides/SchemaOverride.java | 4 +- .../codegen/openapi/OpenApiSpecification.java | 2 +- 20 files changed, 734 insertions(+), 371 deletions(-) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/_types/mapping/CorePropertyBase.java (79%) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/_types/mapping/DocValuesPropertyBase.java (76%) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorMethod.java (68%) create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java delete mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3630053b08..23b21295d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Bumps `org.eclipse.parsson:parsson` from 1.1.6 to 1.1.7 - Bumps `org.hamcrest:hamcrest` from 2.2 to 3.0 - Bumps `com.github.jk1.dependency-license-report` from 2.8 to 2.9 -- Bumps `org.ajoberstar.grgit:grgit-gradle` from 5.2.2 to 5.3.0 - Bumps `org.apache.httpcomponents.core5:httpcore5-h2` from 5.3 to 5.3.1 This section is for maintaining a changelog for all breaking changes for the client that cannot be released in the 2.x line. All other non-breaking changes should be added to [Unreleased 2.x] section. @@ -41,8 +40,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ## [Unreleased 2.x] ### Added -- Added `minScore` and `maxDistance` to `KnnQuery` ([#1166](https://github.com/opensearch-project/opensearch-java/pull/1166)) -- Added `minScore` and `maxDistance` to `NeuralQuery` ([#1235](https://github.com/opensearch-project/opensearch-java/pull/1235)) +- Added support for `KnnVectorProperty`'s `compression_level`, `data_type`, `mode` & `space_type` properties ([#1255](https://github.com/opensearch-project/opensearch-java/pull/1255)) ### Dependencies @@ -53,10 +51,20 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Removed ### Fixed -- Fixed deserializing `GeoBoundsAggregate` when `bounds` is not returned by OpenSearch ([#1238](https://github.com/opensearch-project/opensearch-java/pull/1238)) ### Security +## [2.16.0] - 10/22/2024 +### Added +- Added `minScore` and `maxDistance` to `KnnQuery` ([#1166](https://github.com/opensearch-project/opensearch-java/pull/1166)) +- Added `minScore` and `maxDistance` to `NeuralQuery` ([#1235](https://github.com/opensearch-project/opensearch-java/pull/1235)) + +### Dependencies +- Bumps `org.ajoberstar.grgit:grgit-gradle` from 5.2.2 to 5.3.0 + +### Fixed +- Fixed deserializing `GeoBoundsAggregate` when `bounds` is not returned by OpenSearch ([#1238](https://github.com/opensearch-project/opensearch-java/pull/1238)) + ## [2.15.0] - 10/17/2024 ### Added - Added `hashCode` and `equals` implementations to generated code ([#312](https://github.com/opensearch-project/opensearch-java/pull/312)) @@ -548,7 +556,8 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Security [Unreleased 3.0]: https://github.com/opensearch-project/opensearch-java/compare/2.x...HEAD -[Unreleased 2.x]: https://github.com/opensearch-project/opensearch-java/compare/v2.15.0...2.x +[Unreleased 2.x]: https://github.com/opensearch-project/opensearch-java/compare/v2.16.0...2.x +[2.16.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.15.0...v2.16.0 [2.15.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.14.0...v2.15.0 [2.14.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.13.0...v2.14.0 [2.13.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.12.0...v2.13.0 diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/CorePropertyBase.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/CorePropertyBase.java similarity index 79% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/CorePropertyBase.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/CorePropertyBase.java index cc14e499e4..062d2fb80a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/CorePropertyBase.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/CorePropertyBase.java @@ -30,10 +30,17 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch._types.mapping; import jakarta.json.stream.JsonGenerator; import java.util.List; +import java.util.Objects; +import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; @@ -42,7 +49,10 @@ // typedef: _types.mapping.CorePropertyBase +@Generated("org.opensearch.client.codegen.CodeGenerator") public abstract class CorePropertyBase extends PropertyBase { + + @Nonnull private final List copyTo; @Nullable @@ -55,16 +65,15 @@ public abstract class CorePropertyBase extends PropertyBase { protected CorePropertyBase(AbstractBuilder builder) { super(builder); - this.copyTo = ApiTypeHelper.unmodifiable(builder.copyTo); this.similarity = builder.similarity; this.store = builder.store; - } /** * API name: {@code copy_to} */ + @Nonnull public final List copyTo() { return this.copyTo; } @@ -86,46 +95,44 @@ public final Boolean store() { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - super.serializeInternal(generator, mapper); if (ApiTypeHelper.isDefined(this.copyTo)) { generator.writeKey("copy_to"); generator.writeStartArray(); for (String item0 : this.copyTo) { generator.write(item0); - } generator.writeEnd(); - } + if (this.similarity != null) { generator.writeKey("similarity"); generator.write(this.similarity); - } + if (this.store != null) { generator.writeKey("store"); generator.write(this.store); - } - } + // --------------------------------------------------------------------------------------------- + protected abstract static class AbstractBuilder> extends PropertyBase.AbstractBuilder< BuilderT> { @Nullable private List copyTo; - @Nullable private String similarity; - @Nullable private Boolean store; /** * API name: {@code copy_to} + * *

* Adds all elements of list to copyTo. + *

*/ public final BuilderT copyTo(List list) { this.copyTo = _listAddAll(this.copyTo, list); @@ -134,8 +141,10 @@ public final BuilderT copyTo(List list) { /** * API name: {@code copy_to} + * *

* Adds one or more values to copyTo. + *

*/ public final BuilderT copyTo(String value, String... values) { this.copyTo = _listAdd(this.copyTo, value, values); @@ -161,12 +170,33 @@ public final BuilderT store(@Nullable Boolean value) { } // --------------------------------------------------------------------------------------------- + protected static > void setupCorePropertyBaseDeserializer(ObjectDeserializer op) { - PropertyBase.setupPropertyBaseDeserializer(op); + setupPropertyBaseDeserializer(op); op.add(AbstractBuilder::copyTo, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "copy_to"); op.add(AbstractBuilder::similarity, JsonpDeserializer.stringDeserializer(), "similarity"); op.add(AbstractBuilder::store, JsonpDeserializer.booleanDeserializer(), "store"); + } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + Objects.hashCode(this.copyTo); + result = 31 * result + Objects.hashCode(this.similarity); + result = 31 * result + Objects.hashCode(this.store); + return result; } + @Override + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + CorePropertyBase other = (CorePropertyBase) o; + return Objects.equals(this.copyTo, other.copyTo) + && Objects.equals(this.similarity, other.similarity) + && Objects.equals(this.store, other.store); + } } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/DocValuesPropertyBase.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/DocValuesPropertyBase.java similarity index 76% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/DocValuesPropertyBase.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/DocValuesPropertyBase.java index 8ffe566ebb..a5b51d9677 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/DocValuesPropertyBase.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/DocValuesPropertyBase.java @@ -30,9 +30,15 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch._types.mapping; import jakarta.json.stream.JsonGenerator; +import java.util.Objects; +import javax.annotation.Generated; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; @@ -40,7 +46,9 @@ // typedef: _types.mapping.DocValuesPropertyBase +@Generated("org.opensearch.client.codegen.CodeGenerator") public abstract class DocValuesPropertyBase extends CorePropertyBase { + @Nullable private final Boolean docValues; @@ -48,9 +56,7 @@ public abstract class DocValuesPropertyBase extends CorePropertyBase { protected DocValuesPropertyBase(AbstractBuilder builder) { super(builder); - this.docValues = builder.docValues; - } /** @@ -62,16 +68,15 @@ public final Boolean docValues() { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - super.serializeInternal(generator, mapper); if (this.docValues != null) { generator.writeKey("doc_values"); generator.write(this.docValues); - } - } + // --------------------------------------------------------------------------------------------- + protected abstract static class AbstractBuilder> extends CorePropertyBase.AbstractBuilder< BuilderT> { @Nullable @@ -88,12 +93,29 @@ public final BuilderT docValues(@Nullable Boolean value) { } // --------------------------------------------------------------------------------------------- + protected static > void setupDocValuesPropertyBaseDeserializer( ObjectDeserializer op ) { setupCorePropertyBaseDeserializer(op); op.add(AbstractBuilder::docValues, JsonpDeserializer.booleanDeserializer(), "doc_values"); + } + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + Objects.hashCode(this.docValues); + return result; } + @Override + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + DocValuesPropertyBase other = (DocValuesPropertyBase) o; + return Objects.equals(this.docValues, other.docValues); + } } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorMethod.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorMethod.java similarity index 68% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorMethod.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorMethod.java index b9077a43da..da8f7400c0 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorMethod.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorMethod.java @@ -6,11 +6,42 @@ * compatible open source license. */ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch._types.mapping; import jakarta.json.stream.JsonGenerator; import java.util.Map; +import java.util.Objects; import java.util.function.Function; +import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonpDeserializable; @@ -26,68 +57,167 @@ // typedef: _types.mapping.KnnVectorMethod @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public class KnnVectorMethod implements PlainJsonSerializable { + + @Nullable + private final String engine; + + @Nonnull + private final String name; + + @Nonnull + private final Map parameters; + + @Nullable + private final String spaceType; + + // --------------------------------------------------------------------------------------------- + + private KnnVectorMethod(Builder builder) { + this.engine = builder.engine; + this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); + this.parameters = ApiTypeHelper.unmodifiable(builder.parameters); + this.spaceType = builder.spaceType; + } + + public static KnnVectorMethod of(Function> fn) { + return fn.apply(new Builder()).build(); + } + /** - * Builder for {@link KnnVectorMethod}. + * API name: {@code engine} */ + @Nullable + public final String engine() { + return this.engine; + } - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - private String name; + /** + * Required - API name: {@code name} + */ + @Nonnull + public final String name() { + return this.name; + } - @Nullable - private String spaceType; + /** + * API name: {@code parameters} + */ + @Nonnull + public final Map parameters() { + return this.parameters; + } + + /** + * API name: {@code space_type} + */ + @Nullable + public final String spaceType() { + return this.spaceType; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + if (this.engine != null) { + generator.writeKey("engine"); + generator.write(this.engine); + } + + generator.writeKey("name"); + generator.write(this.name); + + if (ApiTypeHelper.isDefined(this.parameters)) { + generator.writeKey("parameters"); + generator.writeStartObject(); + for (Map.Entry item0 : this.parameters.entrySet()) { + generator.writeKey(item0.getKey()); + item0.getValue().serialize(generator, mapper); + } + generator.writeEnd(); + } + + if (this.spaceType != null) { + generator.writeKey("space_type"); + generator.write(this.spaceType); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link KnnVectorMethod}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { @Nullable private String engine; - + private String name; @Nullable private Map parameters; + @Nullable + private String spaceType; /** - * Required - API name: {@code name} + * API name: {@code engine} */ - public final Builder name(String value) { - this.name = value; + public final Builder engine(@Nullable String value) { + this.engine = value; return this; } /** - * API name: {@code space_type} + * Required - API name: {@code name} */ - public final Builder spaceType(@Nullable String value) { - this.spaceType = value; + public final Builder name(String value) { + this.name = value; return this; } /** - * API name: {@code engine} + * API name: {@code parameters} + * + *

+ * Adds all elements of map to parameters. + *

*/ - public final Builder engine(@Nullable String value) { - this.engine = value; + public final Builder parameters(Map map) { + this.parameters = _mapPutAll(this.parameters, map); return this; } /** * API name: {@code parameters} + * + *

+ * Adds an entry to parameters. + *

*/ - public final Builder parameters(@Nullable Map map) { - this.parameters = _mapPutAll(this.parameters, map); + public final Builder parameters(String key, JsonData value) { + this.parameters = _mapPut(this.parameters, key, value); return this; } /** - * API name: {@code parameters} + * API name: {@code space_type} */ - public final Builder parameters(String key, JsonData value) { - this.parameters = _mapPut(this.parameters, key, value); + public final Builder spaceType(@Nullable String value) { + this.spaceType = value; return this; } /** * Builds a {@link KnnVectorMethod}. * - * @throws NullPointerException - * if some of the required fields are null. + * @throws NullPointerException if some of the required fields are null. */ public KnnVectorMethod build() { _checkSingleUse(); @@ -96,6 +226,8 @@ public KnnVectorMethod build() { } } + // --------------------------------------------------------------------------------------------- + /** * Json deserializer for {@link KnnVectorMethod} */ @@ -104,110 +236,31 @@ public KnnVectorMethod build() { KnnVectorMethod::setupKnnVectorMethodDeserializer ); - public static KnnVectorMethod of(Function> fn) { - return fn.apply(new Builder()).build(); - } - protected static void setupKnnVectorMethodDeserializer(ObjectDeserializer op) { - - op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); - op.add(Builder::spaceType, JsonpDeserializer.stringDeserializer(), "space_type"); op.add(Builder::engine, JsonpDeserializer.stringDeserializer(), "engine"); + op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); op.add(Builder::parameters, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "parameters"); - - } - - // --------------------------------------------------------------------------------------------- - - private final String name; - - @Nullable - private final String spaceType; - - @Nullable - private final String engine; - - @Nullable - private final Map parameters; - - private KnnVectorMethod(Builder builder) { - - this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); - this.spaceType = builder.spaceType; - this.engine = builder.engine; - this.parameters = builder.parameters; - - } - - /** - * Required - API name: {@code name} - */ - public final String name() { - return this.name; - } - - /** - * API name: {@code space_type} - */ - @Nullable - public final String spaceType() { - return this.spaceType; + op.add(Builder::spaceType, JsonpDeserializer.stringDeserializer(), "space_type"); } - /** - * API name: {@code engine} - */ - @Nullable - public final String engine() { - return this.engine; + @Override + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.engine); + result = 31 * result + this.name.hashCode(); + result = 31 * result + Objects.hashCode(this.parameters); + result = 31 * result + Objects.hashCode(this.spaceType); + return result; } - // --------------------------------------------------------------------------------------------- - - /** - * API name: {@code parameters} - */ - @Nullable - public final Map parameters() { - return this.parameters; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + KnnVectorMethod other = (KnnVectorMethod) o; + return Objects.equals(this.engine, other.engine) + && this.name.equals(other.name) + && Objects.equals(this.parameters, other.parameters) + && Objects.equals(this.spaceType, other.spaceType); } - - // --------------------------------------------------------------------------------------------- - - /** - * Serialize this object to JSON. - */ - public void serialize(JsonGenerator generator, JsonpMapper mapper) { - generator.writeStartObject(); - serializeInternal(generator, mapper); - generator.writeEnd(); - } - - protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - - generator.writeKey("name"); - generator.write(this.name); - - if (this.spaceType != null) { - generator.writeKey("space_type"); - generator.write(this.spaceType); - } - - if (this.engine != null) { - generator.writeKey("engine"); - generator.write(this.engine); - } - - if (this.parameters != null) { - generator.writeKey("parameters"); - generator.writeStartObject(); - for (Map.Entry item0 : this.parameters.entrySet()) { - generator.writeKey(item0.getKey()); - item0.getValue().serialize(generator, mapper); - } - generator.writeEnd(); - } - - } - } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java new file mode 100644 index 0000000000..54ed487dde --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java @@ -0,0 +1,347 @@ +/* + * 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. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch._types.mapping; + +import jakarta.json.stream.JsonGenerator; +import java.util.Objects; +import java.util.function.Function; +import javax.annotation.Generated; +import javax.annotation.Nullable; +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ApiTypeHelper; +import org.opensearch.client.util.ObjectBuilder; + +// typedef: _types.mapping.KnnVectorProperty + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class KnnVectorProperty extends DocValuesPropertyBase implements PropertyVariant { + + @Nullable + private final String compressionLevel; + + @Nullable + private final String dataType; + + private final int dimension; + + @Nullable + private final KnnVectorMethod method; + + @Nullable + private final String mode; + + @Nullable + private final String modelId; + + @Nullable + private final String spaceType; + + // --------------------------------------------------------------------------------------------- + + private KnnVectorProperty(Builder builder) { + super(builder); + this.compressionLevel = builder.compressionLevel; + this.dataType = builder.dataType; + this.dimension = ApiTypeHelper.requireNonNull(builder.dimension, this, "dimension"); + this.method = builder.method; + this.mode = builder.mode; + this.modelId = builder.modelId; + this.spaceType = builder.spaceType; + } + + public static KnnVectorProperty of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * {@link Property} variant kind. + */ + @Override + public Property.Kind _propertyKind() { + return Property.Kind.KnnVector; + } + + /** + * API name: {@code compression_level} + */ + @Nullable + public final String compressionLevel() { + return this.compressionLevel; + } + + /** + * API name: {@code data_type} + */ + @Nullable + public final String dataType() { + return this.dataType; + } + + /** + * Required - API name: {@code dimension} + */ + public final int dimension() { + return this.dimension; + } + + /** + * API name: {@code method} + */ + @Nullable + public final KnnVectorMethod method() { + return this.method; + } + + /** + * API name: {@code mode} + */ + @Nullable + public final String mode() { + return this.mode; + } + + /** + * API name: {@code model_id} + */ + @Nullable + public final String modelId() { + return this.modelId; + } + + /** + * API name: {@code space_type} + */ + @Nullable + public final String spaceType() { + return this.spaceType; + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + generator.write("type", "knn_vector"); + super.serializeInternal(generator, mapper); + if (this.compressionLevel != null) { + generator.writeKey("compression_level"); + generator.write(this.compressionLevel); + } + + if (this.dataType != null) { + generator.writeKey("data_type"); + generator.write(this.dataType); + } + + generator.writeKey("dimension"); + generator.write(this.dimension); + + if (this.method != null) { + generator.writeKey("method"); + this.method.serialize(generator, mapper); + } + + if (this.mode != null) { + generator.writeKey("mode"); + generator.write(this.mode); + } + + if (this.modelId != null) { + generator.writeKey("model_id"); + generator.write(this.modelId); + } + + if (this.spaceType != null) { + generator.writeKey("space_type"); + generator.write(this.spaceType); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link KnnVectorProperty}. + */ + public static class Builder extends DocValuesPropertyBase.AbstractBuilder implements ObjectBuilder { + @Nullable + private String compressionLevel; + @Nullable + private String dataType; + private Integer dimension; + @Nullable + private KnnVectorMethod method; + @Nullable + private String mode; + @Nullable + private String modelId; + @Nullable + private String spaceType; + + /** + * API name: {@code compression_level} + */ + public final Builder compressionLevel(@Nullable String value) { + this.compressionLevel = value; + return this; + } + + /** + * API name: {@code data_type} + */ + public final Builder dataType(@Nullable String value) { + this.dataType = value; + return this; + } + + /** + * Required - API name: {@code dimension} + */ + public final Builder dimension(int value) { + this.dimension = value; + return this; + } + + /** + * API name: {@code method} + */ + public final Builder method(@Nullable KnnVectorMethod value) { + this.method = value; + return this; + } + + /** + * API name: {@code method} + */ + public final Builder method(Function> fn) { + return method(fn.apply(new KnnVectorMethod.Builder()).build()); + } + + /** + * API name: {@code mode} + */ + public final Builder mode(@Nullable String value) { + this.mode = value; + return this; + } + + /** + * API name: {@code model_id} + */ + public final Builder modelId(@Nullable String value) { + this.modelId = value; + return this; + } + + /** + * API name: {@code space_type} + */ + public final Builder spaceType(@Nullable String value) { + this.spaceType = value; + return this; + } + + @Override + protected Builder self() { + return this; + } + + /** + * Builds a {@link KnnVectorProperty}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public KnnVectorProperty build() { + _checkSingleUse(); + + return new KnnVectorProperty(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link KnnVectorProperty} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + KnnVectorProperty::setupKnnVectorPropertyDeserializer + ); + + protected static void setupKnnVectorPropertyDeserializer(ObjectDeserializer op) { + setupDocValuesPropertyBaseDeserializer(op); + op.add(Builder::compressionLevel, JsonpDeserializer.stringDeserializer(), "compression_level"); + op.add(Builder::dataType, JsonpDeserializer.stringDeserializer(), "data_type"); + op.add(Builder::dimension, JsonpDeserializer.integerDeserializer(), "dimension"); + op.add(Builder::method, KnnVectorMethod._DESERIALIZER, "method"); + op.add(Builder::mode, JsonpDeserializer.stringDeserializer(), "mode"); + op.add(Builder::modelId, JsonpDeserializer.stringDeserializer(), "model_id"); + op.add(Builder::spaceType, JsonpDeserializer.stringDeserializer(), "space_type"); + + op.ignore("type"); + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + Objects.hashCode(this.compressionLevel); + result = 31 * result + Objects.hashCode(this.dataType); + result = 31 * result + Integer.hashCode(this.dimension); + result = 31 * result + Objects.hashCode(this.method); + result = 31 * result + Objects.hashCode(this.mode); + result = 31 * result + Objects.hashCode(this.modelId); + result = 31 * result + Objects.hashCode(this.spaceType); + return result; + } + + @Override + public boolean equals(Object o) { + if (!super.equals(o)) { + return false; + } + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + KnnVectorProperty other = (KnnVectorProperty) o; + return Objects.equals(this.compressionLevel, other.compressionLevel) + && Objects.equals(this.dataType, other.dataType) + && this.dimension == other.dimension + && Objects.equals(this.method, other.method) + && Objects.equals(this.mode, other.mode) + && Objects.equals(this.modelId, other.modelId) + && Objects.equals(this.spaceType, other.spaceType); + } +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java deleted file mode 100644 index 6a1261c5dd..0000000000 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/KnnVectorProperty.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * 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._types.mapping; - -import jakarta.json.stream.JsonGenerator; -import java.util.function.Function; -import javax.annotation.Nullable; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; -import org.opensearch.client.util.ApiTypeHelper; -import org.opensearch.client.util.ObjectBuilder; - -// typedef: _types.mapping.KnnVectorProperty - -@JsonpDeserializable -public class KnnVectorProperty extends PropertyBase implements PropertyVariant { - /** - * Builder for {@link KnnVectorProperty}. - */ - - public static class Builder extends PropertyBase.AbstractBuilder implements ObjectBuilder { - private Integer dimension; - - @Nullable - private String modelId; - - @Nullable - private KnnVectorMethod method; - - /** - * Required - API name: {@code dimension} - */ - public final Builder dimension(int value) { - this.dimension = value; - return this; - } - - /** - * API name: {@code model_id} - */ - public final Builder modelId(@Nullable String value) { - this.modelId = value; - return this; - } - - /** - * API name: {@code method} - */ - public final Builder method(@Nullable KnnVectorMethod value) { - this.method = value; - return this; - } - - /** - * API name: {@code method} - */ - public final Builder method(Function> fn) { - return this.method(fn.apply(new KnnVectorMethod.Builder()).build()); - } - - /** - * Builds a {@link KnnVectorProperty}. - * - * @throws NullPointerException - * if some of the required fields are null. - */ - public KnnVectorProperty build() { - _checkSingleUse(); - - return new KnnVectorProperty(this); - } - - @Override - protected Builder self() { - return this; - } - } - - /** - * Json deserializer for {@link KnnVectorProperty} - */ - public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( - Builder::new, - KnnVectorProperty::setupKnnVectorPropertyDeserializer - ); - - public static KnnVectorProperty of(Function> fn) { - return fn.apply(new Builder()).build(); - } - - // --------------------------------------------------------------------------------------------- - - protected static void setupKnnVectorPropertyDeserializer(ObjectDeserializer op) { - PropertyBase.setupPropertyBaseDeserializer(op); - op.add(Builder::dimension, JsonpDeserializer.integerDeserializer(), "dimension"); - op.add(Builder::modelId, JsonpDeserializer.stringDeserializer(), "model_id"); - op.add(Builder::method, KnnVectorMethod._DESERIALIZER, "method"); - - op.ignore("type"); - } - - private final int dimension; - - @Nullable - private final String modelId; - - @Nullable - private final KnnVectorMethod method; - - private KnnVectorProperty(Builder builder) { - super(builder); - - this.dimension = ApiTypeHelper.requireNonNull(builder.dimension, this, "dimension"); - this.modelId = builder.modelId; - this.method = builder.method; - - } - - /** - * Property variant kind. - */ - @Override - public Property.Kind _propertyKind() { - return Property.Kind.KnnVector; - } - - /** - * Required - API name: {@code dimension} - */ - public final int dimension() { - return this.dimension; - } - - // --------------------------------------------------------------------------------------------- - - /** - * API name: {@code model_id} - */ - @Nullable - public final String modelId() { - return this.modelId; - } - - // --------------------------------------------------------------------------------------------- - - /** - * API name: {@code method} - */ - @Nullable - public final KnnVectorMethod method() { - return this.method; - } - - @Override - protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - - generator.write("type", "knn_vector"); - super.serializeInternal(generator, mapper); - generator.writeKey("dimension"); - generator.write(this.dimension); - - if (this.modelId != null) { - - generator.writeKey("model_id"); - generator.write(this.modelId); - - } - - if (this.method != null) { - - generator.writeKey("method"); - this.method.serialize(generator, mapper); - } - - } - -} diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ArrayShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ArrayShape.java index d04f66f6f7..9e53bbb660 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ArrayShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ArrayShape.java @@ -10,12 +10,20 @@ import java.util.Collection; import java.util.List; +import org.opensearch.client.codegen.model.overrides.ShouldGenerate; public class ArrayShape extends ObjectShape { private final Field valueBodyField; - public ArrayShape(Namespace parent, String className, Type arrayType, String typedefName, String description) { - super(parent, className, typedefName, description); + public ArrayShape( + Namespace parent, + String className, + Type arrayType, + String typedefName, + String description, + ShouldGenerate shouldGenerate + ) { + super(parent, className, typedefName, description, shouldGenerate); this.valueBodyField = new Field("_value_body", arrayType, true, "Response value.", null); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/DictionaryResponseShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/DictionaryResponseShape.java index 7d3691de9b..377cc33301 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/DictionaryResponseShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/DictionaryResponseShape.java @@ -10,6 +10,7 @@ import java.util.Collection; import java.util.List; +import org.opensearch.client.codegen.model.overrides.ShouldGenerate; public class DictionaryResponseShape extends Shape { private final Type keyType; @@ -21,9 +22,10 @@ public DictionaryResponseShape( String typedefName, String description, Type keyType, - Type valueType + Type valueType, + ShouldGenerate shouldGenerate ) { - super(parent, className, typedefName, description); + super(parent, className, typedefName, description, shouldGenerate); this.keyType = keyType; this.valueType = valueType; setExtendsType(Types.Client.Transport.Endpoints.DictionaryResponse(keyType, valueType)); diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/EnumShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/EnumShape.java index 1150a1813f..c33b7da0f8 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/EnumShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/EnumShape.java @@ -14,6 +14,7 @@ import java.util.Set; import java.util.TreeMap; import javax.annotation.Nullable; +import org.opensearch.client.codegen.model.overrides.ShouldGenerate; import org.opensearch.client.codegen.utils.JavaClassKind; import org.opensearch.client.codegen.utils.Markdown; import org.opensearch.client.codegen.utils.Strings; @@ -21,8 +22,8 @@ public class EnumShape extends Shape { private final TreeMap variants = new TreeMap<>(); - public EnumShape(Namespace parent, String className, String typedefName, String description) { - super(parent, className, typedefName, description); + public EnumShape(Namespace parent, String className, String typedefName, String description, ShouldGenerate shouldGenerate) { + super(parent, className, typedefName, description, shouldGenerate); } @Override diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java index 35087e5f92..1416a707d4 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java @@ -19,6 +19,7 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.builder.ToStringBuilder; import org.opensearch.client.codegen.exceptions.RenderException; +import org.opensearch.client.codegen.model.overrides.ShouldGenerate; import org.opensearch.client.codegen.utils.Lists; import org.opensearch.client.codegen.utils.Strings; @@ -115,7 +116,13 @@ private static class Client extends Shape { private final Collection operations; private Client(Namespace parent, boolean async, boolean base, Collection operations) { - super(parent, parent.getClientClassName(async, base), null, "Client for the " + parent.name + " namespace."); + super( + parent, + parent.getClientClassName(async, base), + null, + "Client for the " + parent.name + " namespace.", + ShouldGenerate.Always + ); this.async = async; this.base = base; this.operations = operations; diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java index 9caa269bf5..3cbabe8754 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ObjectShape.java @@ -17,14 +17,15 @@ import java.util.TreeMap; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; +import org.opensearch.client.codegen.model.overrides.ShouldGenerate; public class ObjectShape extends Shape { protected final Map bodyFields = new TreeMap<>(); protected Field additionalPropertiesField; private String shortcutProperty; - public ObjectShape(Namespace parent, String className, String typedefName, String description) { - super(parent, className, typedefName, description); + public ObjectShape(Namespace parent, String className, String typedefName, String description, ShouldGenerate shouldGenerate) { + super(parent, className, typedefName, description, shouldGenerate); } public void addBodyField(Field field) { diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ReferenceKind.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ReferenceKind.java index 19a92dd6fb..b9ca519856 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/ReferenceKind.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/ReferenceKind.java @@ -11,7 +11,8 @@ public enum ReferenceKind { Extends(false), Field(true), - UnionVariant(true); + UnionVariant(true), + TypeParameter(true); private final boolean isConcreteUsage; diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java index fc351a1156..df8ffabe6f 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java @@ -19,6 +19,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; +import org.opensearch.client.codegen.model.overrides.ShouldGenerate; import org.opensearch.client.codegen.utils.Streams; import org.opensearch.client.codegen.utils.Strings; @@ -37,8 +38,13 @@ public class RequestShape extends ObjectShape { private final Map fields = new TreeMap<>(); private boolean isBooleanRequest; - public RequestShape(@Nonnull Namespace parent, @Nonnull OperationGroup operationGroup, @Nullable String description) { - super(parent, requestClassName(operationGroup), operationGroup.asTypedefPrefix() + ".Request", description); + public RequestShape( + @Nonnull Namespace parent, + @Nonnull OperationGroup operationGroup, + @Nullable String description, + @Nonnull ShouldGenerate shouldGenerate + ) { + super(parent, requestClassName(operationGroup), operationGroup.asTypedefPrefix() + ".Request", description, shouldGenerate); this.operationGroup = operationGroup; } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java index 7f3e6ab5cc..e1e834480f 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java @@ -23,6 +23,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.codegen.exceptions.RenderException; +import org.opensearch.client.codegen.model.overrides.ShouldGenerate; import org.opensearch.client.codegen.utils.JavaClassKind; import org.opensearch.client.codegen.utils.Markdown; @@ -35,13 +36,15 @@ public abstract class Shape { private final String className; private final String typedefName; private final String description; + private final ShouldGenerate shouldGenerate; private Type extendsType; - public Shape(Namespace parent, String className, String typedefName, String description) { + public Shape(Namespace parent, String className, String typedefName, String description, ShouldGenerate shouldGenerate) { this.parent = parent; this.className = className; this.typedefName = typedefName; this.description = description != null ? Markdown.toJavaDocHtml(description) : null; + this.shouldGenerate = shouldGenerate; } public String getPackageName() { @@ -105,6 +108,12 @@ public Collection getImplementsTypes() { protected void tryAddReference(ReferenceKind kind, Type to) { if (to == null) return; to.getTargetShape().ifPresent(s -> addReference(kind, s)); + var typeParams = to.getTypeParams(); + if (typeParams != null) { + for (var typeParam : typeParams) { + tryAddReference(ReferenceKind.TypeParameter, typeParam); + } + } } private void addReference(ReferenceKind kind, Shape to) { @@ -125,8 +134,33 @@ public Namespace getParent() { return this.parent; } + private boolean shouldGenerate(Set visited) { + switch (shouldGenerate) { + case Always: + return true; + case Never: + return false; + case IfNeeded: + if (visited.contains(this)) { + return false; + } + visited.add(this); + return incomingReferences.values().stream().flatMap(List::stream).anyMatch(s -> s.shouldGenerate(visited)); + default: + throw new IllegalStateException("Unknown ShouldGenerate: " + shouldGenerate); + } + } + + public boolean shouldGenerate() { + return shouldGenerate(new HashSet<>()); + } + public void render(ShapeRenderingContext ctx) throws RenderException { var outFile = ctx.getOutputFile(className + ".java"); + if (!shouldGenerate()) { + LOGGER.info("Skipping: {}", outFile); + return; + } LOGGER.info("Rendering: {}", outFile); var renderer = ctx.getTemplateRenderer(b -> b.withFormatter(Type.class, t -> { referencedTypes.add(t); diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java index a631254623..7983ec9df4 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java @@ -95,6 +95,13 @@ public void visit(@Nonnull OpenApiSpecification spec) { }); groupedOperations.forEach(this::visit); + + overrides.getSchemas().forEach((pointer, schemaOverride) -> { + if (schemaOverride.shouldGenerate() != ShouldGenerate.Always) { + return; + } + visit(spec.getElement(pointer, OpenApiSchema.class)); + }); } private void visit(@Nonnull OperationGroup group, @Nonnull List variants) { @@ -130,7 +137,13 @@ private void visit(@Nonnull OperationGroup group, @Nonnull List variants = new TreeMap<>(); private final String discriminatingField; - public TaggedUnionShape(Namespace parent, String className, String typedefName, String description, String discriminatingField) { - super(parent, className, typedefName, description); + public TaggedUnionShape( + Namespace parent, + String className, + String typedefName, + String description, + String discriminatingField, + ShouldGenerate shouldGenerate + ) { + super(parent, className, typedefName, description, shouldGenerate); this.discriminatingField = discriminatingField; } @@ -91,13 +99,16 @@ public boolean hasAmbiguities() { @Override public void render(ShapeRenderingContext ctx) throws RenderException { + if (!shouldGenerate()) { + return; + } super.render(ctx); var buildableVariants = Lists.filter(getVariants(), v -> v.getType().hasBuilder()); if (!buildableVariants.isEmpty()) { - new Builders(this, buildableVariants).render(ctx); + new Builders(this, buildableVariants, ShouldGenerate.Always).render(ctx); } if (isDiscriminated()) { - new VariantInterface(this).render(ctx); + new VariantInterface(this, ShouldGenerate.Always).render(ctx); } } @@ -141,8 +152,8 @@ private static String buildDescription(TaggedUnionShape union) { private final String unionClassName; private final Collection variants; - private Builders(TaggedUnionShape union, Collection variants) { - super(union.getParent(), union.getClassName() + "Builders", null, buildDescription(union)); + private Builders(TaggedUnionShape union, Collection variants, ShouldGenerate shouldGenerate) { + super(union.getParent(), union.getClassName() + "Builders", null, buildDescription(union), shouldGenerate); this.variants = variants; unionClassName = union.getClassName(); } @@ -169,12 +180,13 @@ public String toString() { public static class VariantInterface extends Shape { private final String unionClassName; - private VariantInterface(TaggedUnionShape union) { + private VariantInterface(TaggedUnionShape union, ShouldGenerate shouldGenerate) { super( union.getParent(), union.getClassName() + "Variant", null, - "Base interface for {@link " + union.getClassName() + "} variants." + "Base interface for {@link " + union.getClassName() + "} variants.", + shouldGenerate ); unionClassName = union.getClassName(); setExtendsType(Types.Client.Json.JsonpSerializable); diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java index 92101c96a9..38bcd76d82 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java @@ -97,6 +97,7 @@ public String getName() { return name; } + @Nullable public Type[] getTypeParams() { return typeParams; } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/Overrides.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/Overrides.java index 750a4e8e88..bd040d5f5b 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/Overrides.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/Overrides.java @@ -27,6 +27,8 @@ public class Overrides { s -> s // TODO: Remove this to generate property mapping types .with(SCHEMAS.append("_common.mapping:Property"), so -> so.withShouldGenerate(ShouldGenerate.Never)) + .with(SCHEMAS.append("_common.mapping:PropertyBase"), so -> so.withShouldGenerate(ShouldGenerate.Never)) + .with(SCHEMAS.append("_common.mapping:KnnVectorProperty"), so -> so.withShouldGenerate(ShouldGenerate.Always)) // TODO: Remove this to generate query types .with( SCHEMAS.append("_common.query_dsl:QueryContainer"), @@ -43,6 +45,11 @@ private Overrides(Builder builder) { this.schemas = builder.schemas != null ? Collections.unmodifiableMap(builder.schemas) : Collections.emptyMap(); } + @Nonnull + public Map getSchemas() { + return schemas; + } + @Nonnull public Optional getSchema(@Nonnull JsonPointer pointer) { return Optional.ofNullable(schemas.get(pointer)); diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/SchemaOverride.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/SchemaOverride.java index a1ee81b882..6cc3b97006 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/SchemaOverride.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/SchemaOverride.java @@ -24,6 +24,7 @@ import org.opensearch.client.codegen.utils.builder.ObjectMapBuilderBase; public final class SchemaOverride { + @Nonnull private final ShouldGenerate shouldGenerate; @Nonnull private final Map properties; @@ -66,6 +67,7 @@ public PropertyOverride getProperty(@Nonnull String key) { return PropertyOverride.builder().withMappedType(mappedType).withAliases(aliases).build(); } + @Nonnull public ShouldGenerate shouldGenerate() { return shouldGenerate; } @@ -111,7 +113,7 @@ protected SchemaOverride construct() { } @Nonnull - public Builder withShouldGenerate(ShouldGenerate shouldGenerate) { + public Builder withShouldGenerate(@Nonnull ShouldGenerate shouldGenerate) { this.shouldGenerate = Objects.requireNonNull(shouldGenerate, "shouldGenerate must not be null"); return this; } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSpecification.java b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSpecification.java index aa09da8d06..ffdf3f7741 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSpecification.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSpecification.java @@ -84,7 +84,7 @@ > void addElement(@Nonnull JsonPointer pointer, @Non } @Nonnull - > T getElement(@Nonnull JsonPointer pointer, @Nonnull Class type) { + public > T getElement(@Nonnull JsonPointer pointer, @Nonnull Class type) { Objects.requireNonNull(pointer, "pointer must not be null"); Objects.requireNonNull(type, "type must not be null"); return Optional.ofNullable(elementCache.get(type))