Skip to content

Commit

Permalink
[Backport 2.x] CodeGen Updates (#1257)
Browse files Browse the repository at this point in the history
* Improve code generation (#1219)

- Render descriptions using markdown
- Support generating "DictionaryResponse" types
- Support discriminated unions

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit d045d86)

* Use latest spec

Signed-off-by: Thomas Farr <[email protected]>

* Add `@Override` to equals & hashCode (#1249)

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 282f415)

* Begin generating index CRUD operations (#1220)

* Generate indices.get

Signed-off-by: Thomas Farr <[email protected]>

* Generate indices.exists

Signed-off-by: Thomas Farr <[email protected]>

* Generate indices.create

Signed-off-by: Thomas Farr <[email protected]>

* Generate indices.delete

Signed-off-by: Thomas Farr <[email protected]>

* Cleanup SourceFieldMode

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit b962e89)

* Generate KnnVectorProperty

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 6a930ad)

* Add PR number

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Nov 4, 2024
1 parent 85be720 commit 69698c3
Show file tree
Hide file tree
Showing 109 changed files with 4,615 additions and 2,009 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased 2.x]
### Added
- Added support for `KnnVectorProperty`'s `compression_level`, `data_type`, `mode` & `space_type` properties ([#1255](https://github.com/opensearch-project/opensearch-java/pull/1255))

### Dependencies
- Bumps `org.apache.httpcomponents.core5:httpcore5-h2` from 5.3 to 5.3.1
Expand All @@ -14,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Removed

### Fixed
- Fixed `UndeployModelResponse` deserialization ([#1257](https://github.com/opensearch-project/opensearch-java/pull/1257))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public final ErrorCause causedBy() {
}

/**
* A human-readable explanation of the error, in english
* A human-readable explanation of the error, in English.
* <p>
* API name: {@code reason}
* </p>
Expand All @@ -127,7 +127,7 @@ public final List<ErrorCause> rootCause() {
}

/**
* The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
* The server stack trace, present only if the <code>error_trace=true</code> parameter was sent with the request.
* <p>
* API name: {@code stack_trace}
* </p>
Expand All @@ -146,7 +146,7 @@ public final List<ErrorCause> suppressed() {
}

/**
* Required - The type of error
* Required - The type of error.
* <p>
* API name: {@code type}
* </p>
Expand All @@ -157,7 +157,7 @@ public final String type() {
}

/**
* Additional details about the error.
* Any additional information about the error.
*/
@Nonnull
public final Map<String, JsonData> metadata() {
Expand Down Expand Up @@ -252,7 +252,7 @@ public final Builder causedBy(Function<ErrorCause.Builder, ObjectBuilder<ErrorCa
}

/**
* A human-readable explanation of the error, in english
* A human-readable explanation of the error, in English.
* <p>
* API name: {@code reason}
* </p>
Expand Down Expand Up @@ -298,7 +298,7 @@ public final Builder rootCause(Function<ErrorCause.Builder, ObjectBuilder<ErrorC
}

/**
* The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
* The server stack trace, present only if the <code>error_trace=true</code> parameter was sent with the request.
* <p>
* API name: {@code stack_trace}
* </p>
Expand Down Expand Up @@ -344,7 +344,7 @@ public final Builder suppressed(Function<ErrorCause.Builder, ObjectBuilder<Error
}

/**
* Required - The type of error
* Required - The type of error.
* <p>
* API name: {@code type}
* </p>
Expand All @@ -355,7 +355,7 @@ public final Builder type(String value) {
}

/**
* Additional details about the error.
* Any additional information about the error.
*
* <p>
* Adds all elements of <code>map</code> to <code>metadata</code>.
Expand All @@ -367,7 +367,7 @@ public final Builder metadata(Map<String, JsonData> map) {
}

/**
* Additional details about the error.
* Any additional information about the error.
*
* <p>
* Adds an entry to <code>metadata</code>.
Expand Down Expand Up @@ -415,6 +415,7 @@ protected static void setupErrorCauseDeserializer(ObjectDeserializer<ErrorCause.
});
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this.causedBy);
Expand All @@ -427,6 +428,7 @@ public int hashCode() {
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ protected static void setupShardFailureDeserializer(ObjectDeserializer<ShardFail
op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status");
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this.index);
Expand All @@ -260,6 +261,7 @@ public int hashCode() {
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ protected static void setupShardStatisticsDeserializer(ObjectDeserializer<ShardS
op.add(Builder::total, JsonpDeserializer.numberDeserializer(), "total");
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + this.failed.hashCode();
Expand All @@ -284,6 +285,7 @@ public int hashCode() {
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupWriteRes
op.add(AbstractBuilder::version, JsonpDeserializer.longDeserializer(), "_version");
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this.forcedRefresh);
Expand All @@ -301,6 +302,7 @@ public int hashCode() {
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,7 +49,10 @@

// typedef: _types.mapping.CorePropertyBase

@Generated("org.opensearch.client.codegen.CodeGenerator")
public abstract class CorePropertyBase extends PropertyBase {

@Nonnull
private final List<String> copyTo;

@Nullable
Expand All @@ -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<String> copyTo() {
return this.copyTo;
}
Expand All @@ -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<BuilderT extends AbstractBuilder<BuilderT>> extends PropertyBase.AbstractBuilder<
BuilderT> {
@Nullable
private List<String> copyTo;

@Nullable
private String similarity;

@Nullable
private Boolean store;

/**
* API name: {@code copy_to}
*
* <p>
* Adds all elements of <code>list</code> to <code>copyTo</code>.
* </p>
*/
public final BuilderT copyTo(List<String> list) {
this.copyTo = _listAddAll(this.copyTo, list);
Expand All @@ -134,8 +141,10 @@ public final BuilderT copyTo(List<String> list) {

/**
* API name: {@code copy_to}
*
* <p>
* Adds one or more values to <code>copyTo</code>.
* </p>
*/
public final BuilderT copyTo(String value, String... values) {
this.copyTo = _listAdd(this.copyTo, value, values);
Expand All @@ -161,12 +170,33 @@ public final BuilderT store(@Nullable Boolean value) {
}

// ---------------------------------------------------------------------------------------------

protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupCorePropertyBaseDeserializer(ObjectDeserializer<BuilderT> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,33 @@
* 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;
import org.opensearch.client.json.ObjectDeserializer;

// typedef: _types.mapping.DocValuesPropertyBase

@Generated("org.opensearch.client.codegen.CodeGenerator")
public abstract class DocValuesPropertyBase extends CorePropertyBase {

@Nullable
private final Boolean docValues;

// ---------------------------------------------------------------------------------------------

protected DocValuesPropertyBase(AbstractBuilder<?> builder) {
super(builder);

this.docValues = builder.docValues;

}

/**
Expand All @@ -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<BuilderT extends AbstractBuilder<BuilderT>> extends CorePropertyBase.AbstractBuilder<
BuilderT> {
@Nullable
Expand All @@ -88,12 +93,29 @@ public final BuilderT docValues(@Nullable Boolean value) {
}

// ---------------------------------------------------------------------------------------------

protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupDocValuesPropertyBaseDeserializer(
ObjectDeserializer<BuilderT> 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);
}
}
Loading

0 comments on commit 69698c3

Please sign in to comment.