Skip to content

Commit

Permalink
Generate Property variants (opensearch-project#1291)
Browse files Browse the repository at this point in the history
* Generate Property variants

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

* Handle default Property variant

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

* spotless

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

---------

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Nov 13, 2024
1 parent 3955240 commit 5dbe61e
Show file tree
Hide file tree
Showing 77 changed files with 3,561 additions and 1,953 deletions.
8 changes: 7 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ After:
- The `smartcn_stop` Builder method has been renamed to `smartcnStop`.

### TokenizerDefinition
- The `smartcn` Builder method has been renamed to `smartcnTokenizer`.
- The `smartcn` Builder method has been renamed to `smartcnTokenizer`.

### PointProperty
- `PointProperty` has been removed and is replaced by `XyPointProperty`.

### PropertyBase
- The `name` and `localMetadata` fields, getters and builder methods have been removed from `PropertyBase` as they are not supported by OpenSearch.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@
* GitHub history for details.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package org.opensearch.client.opensearch._types;

import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import javax.annotation.Generated;
import javax.annotation.Nonnull;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
Expand All @@ -47,50 +53,50 @@
// typedef: _types.GeoHashLocation

@JsonpDeserializable
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class GeoHashLocation implements PlainJsonSerializable {

@Nonnull
private final String geohash;

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

private GeoHashLocation(Builder builder) {

this.geohash = ApiTypeHelper.requireNonNull(builder.geohash, this, "geohash");

}

public static GeoHashLocation of(Function<Builder, ObjectBuilder<GeoHashLocation>> fn) {
public static GeoHashLocation of(Function<GeoHashLocation.Builder, ObjectBuilder<GeoHashLocation>> fn) {
return fn.apply(new Builder()).build();
}

/**
* Required - API name: {@code geohash}
*/
@Nonnull
public final String geohash() {
return this.geohash;
}

/**
* 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) {

generator.writeKey("geohash");
generator.write(this.geohash);

}

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

/**
* Builder for {@link GeoHashLocation}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<GeoHashLocation> {
private String geohash;

Expand All @@ -105,8 +111,7 @@ public final Builder geohash(String value) {
/**
* Builds a {@link GeoHashLocation}.
*
* @throws NullPointerException
* if some of the required fields are null.
* @throws NullPointerException if some of the required fields are null.
*/
public GeoHashLocation build() {
_checkSingleUse();
Expand All @@ -126,9 +131,21 @@ public GeoHashLocation build() {
);

protected static void setupGeoHashLocationDeserializer(ObjectDeserializer<GeoHashLocation.Builder> op) {

op.add(Builder::geohash, JsonpDeserializer.stringDeserializer(), "geohash");
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + this.geohash.hashCode();
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
GeoHashLocation other = (GeoHashLocation) o;
return this.geohash.equals(other.geohash);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@
* GitHub history for details.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package org.opensearch.client.opensearch._types;

import jakarta.json.stream.JsonGenerator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Generated;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.PlainJsonSerializable;
import org.opensearch.client.json.UnionDeserializer;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
Expand All @@ -49,26 +56,27 @@
// typedef: _types.GeoLocation

/**
* A latitude/longitude as a 2 dimensional point. It can be represented in
* various ways:
* <p>
* A latitude/longitude as a two-dimensional point. It can be represented in the following ways:
* </p>
* <ul>
* <li>as a <code>{lat, long}</code> object</li>
* <li>as a geo hash value</li>
* <li>as a <code>[lon, lat]</code> array</li>
* <li>as a string in <code>&quot;&lt;lat&gt;, &lt;lon&gt;&quot;</code> or WKT
* point formats</li>
* <li>As a <code>{lat, long}</code> object.</li>
* <li>As a geohash value.</li>
* <li>As a <code>[lon, lat]</code> array.</li>
* <li>As a string in <code>&quot;&lt;lat&gt;, &lt;lon&gt;&quot;</code> or WKT point format.</li>
* </ul>
*
*/
@JsonpDeserializable
public class GeoLocation implements TaggedUnion<GeoLocation.Kind, Object>, JsonpSerializable {

@Generated("org.opensearch.client.codegen.CodeGenerator")
public class GeoLocation implements TaggedUnion<GeoLocation.Kind, Object>, PlainJsonSerializable {
/**
* {@link GeoLocation} variant kinds.
*/
public enum Kind {
Coords,
Geohash,
Latlon,
Text

}

private final Kind _kind;
Expand All @@ -90,13 +98,11 @@ private GeoLocation(Kind kind, Object value) {
}

private GeoLocation(Builder builder) {

this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");

}

public static GeoLocation of(Function<Builder, ObjectBuilder<GeoLocation>> fn) {
public static GeoLocation of(Function<GeoLocation.Builder, ObjectBuilder<GeoLocation>> fn) {
return fn.apply(new Builder()).build();
}

Expand All @@ -110,8 +116,7 @@ public boolean isCoords() {
/**
* Get the {@code coords} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code coords} kind.
* @throws IllegalStateException if the current variant is not the {@code coords} kind.
*/
public List<Double> coords() {
return TaggedUnionUtils.get(this, Kind.Coords);
Expand All @@ -127,8 +132,7 @@ public boolean isGeohash() {
/**
* Get the {@code geohash} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code geohash} kind.
* @throws IllegalStateException if the current variant is not the {@code geohash} kind.
*/
public GeoHashLocation geohash() {
return TaggedUnionUtils.get(this, Kind.Geohash);
Expand All @@ -144,8 +148,7 @@ public boolean isLatlon() {
/**
* Get the {@code latlon} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code latlon} kind.
* @throws IllegalStateException if the current variant is not the {@code latlon} kind.
*/
public LatLonGeoLocation latlon() {
return TaggedUnionUtils.get(this, Kind.Latlon);
Expand All @@ -161,8 +164,7 @@ public boolean isText() {
/**
* Get the {@code text} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code text} kind.
* @throws IllegalStateException if the current variant is not the {@code text} kind.
*/
public String text() {
return TaggedUnionUtils.get(this, Kind.Text);
Expand All @@ -178,18 +180,14 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartArray();
for (Double item0 : ((List<Double>) this._value)) {
generator.write(item0);

}
generator.writeEnd();

break;
case Text:
generator.write(((String) this._value));

break;
}
}

}

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<GeoLocation> {
Expand Down Expand Up @@ -228,11 +226,11 @@ public ObjectBuilder<GeoLocation> text(String v) {
return this;
}

@Override
public GeoLocation build() {
_checkSingleUse();
return new GeoLocation(this);
}

}

private static JsonpDeserializer<GeoLocation> buildGeoLocationDeserializer() {
Expand All @@ -247,4 +245,20 @@ private static JsonpDeserializer<GeoLocation> buildGeoLocationDeserializer() {
}

public static final JsonpDeserializer<GeoLocation> _DESERIALIZER = JsonpDeserializer.lazy(GeoLocation::buildGeoLocationDeserializer);

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this._kind);
result = 31 * result + Objects.hashCode(this._value);
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
GeoLocation other = (GeoLocation) o;
return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,38 @@
* GitHub history for details.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package org.opensearch.client.opensearch._types;

import javax.annotation.Generated;

/**
* <p>
* Builders for {@link GeoLocation} variants.
* </p>
* <p>
* Variants <code>coords</code>, <code>text</code> are not available here as
* they don't have a dedicated class. Use {@link GeoLocation}'s builder for
* these.
*
* Variants <code>coords</code>, <code>text</code> are not available here as they don't have a dedicated class. Use {@link GeoLocation}'s
* builder for these.
* </p>
*/
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class GeoLocationBuilders {
private GeoLocationBuilders() {}

/**
* Creates a builder for the {@link GeoHashLocation geohash} {@code GeoLocation}
* variant.
* Creates a builder for the {@link GeoHashLocation geohash} {@code GeoLocation} variant.
*/
public static GeoHashLocation.Builder geohash() {
return new GeoHashLocation.Builder();
}

/**
* Creates a builder for the {@link LatLonGeoLocation latlon}
* {@code GeoLocation} variant.
* Creates a builder for the {@link LatLonGeoLocation latlon} {@code GeoLocation} variant.
*/
public static LatLonGeoLocation.Builder latlon() {
return new LatLonGeoLocation.Builder();
}

}
Loading

0 comments on commit 5dbe61e

Please sign in to comment.