Skip to content

Commit

Permalink
Generate remaining analysis types (opensearch-project#1289)
Browse files Browse the repository at this point in the history
* Generate Tokenizer variants

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

* Generate Analyzer variants

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

* Generate CharFilter variants

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

* Generate Normalizer variants

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

---------

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 3955240)
  • Loading branch information
Xtansia committed Nov 20, 2024
1 parent 8f37e81 commit 00c3859
Show file tree
Hide file tree
Showing 6 changed files with 16,101 additions and 15,263 deletions.
31,295 changes: 16,069 additions & 15,226 deletions java-codegen/opensearch-openapi.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,6 @@ private Type mapType(OpenApiSchema schema, boolean boxed) {
}

private Type mapTypeInner(OpenApiSchema schema) {
if (schema.getPointer().isDirectChildOf(JsonPointer.of("components", "schemas"))) {
var type = mapTypeComponentsSchemas(schema);
if (type != null) {
return type;
}
}

if (schema.has$ref()) {
schema = schema.resolve();

Expand Down Expand Up @@ -534,22 +527,6 @@ private Type mapTypeInner(OpenApiSchema schema) {
throw new UnsupportedOperationException("Can not get type name for: " + types);
}

private Type mapTypeComponentsSchemas(OpenApiSchema schema) {
var key = schema.getPointer().getLastKey().orElseThrow();
switch (key) {
case "_common:Duration":
return Types.Client.OpenSearch._Types.Time;
case "_common:Stringifiedinteger":
return Types.Primitive.Int;
case "_common:Stringifiedboolean":
return Types.Primitive.Boolean;
case "_common:StringifiedEpochTimeUnitMillis":
return Types.Primitive.Long;
default:
return null;
}
}

private Type mapOneOf(List<OpenApiSchema> oneOf) {
if (isOneOfSingleAndArray(oneOf)) {
return mapType(oneOf.get(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
import java.util.Map;

public final class Types {
public static final Map<String, Object> TYPES_MAP = asMap(Types.class);
private static Map<String, Object> TYPES_MAP;

public static Map<String, Object> asMap() {
if (TYPES_MAP == null) {
TYPES_MAP = asMap(Types.class);
}
return TYPES_MAP;
}

private static Map<String, Object> asMap(Class<?> clazz) {
var map = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,36 @@
import javax.annotation.Nullable;
import org.opensearch.client.codegen.model.Types;
import org.opensearch.client.codegen.openapi.JsonPointer;
import org.opensearch.client.codegen.openapi.OpenApiSchema;
import org.opensearch.client.codegen.utils.builder.ObjectBuilder;
import org.opensearch.client.codegen.utils.builder.ObjectBuilderBase;

public class Overrides {
private static final JsonPointer SCHEMAS = JsonPointer.of("components", "schemas");
private static JsonPointer schema(String namespace, String name) {
return OpenApiSchema.COMPONENTS_SCHEMAS.append(namespace + OpenApiSchema.NAMESPACE_NAME_SEPARATOR + name);
}

public static final Overrides OVERRIDES = builder().withSchemas(
s -> s
s -> s.with(schema("_common", "Duration"), so -> so.withMappedType(Types.Client.OpenSearch._Types.Time))
.with(schema("_common", "Stringifiedinteger"), so -> so.withMappedType(Types.Primitive.Int))
.with(schema("_common", "Stringifiedboolean"), so -> so.withMappedType(Types.Primitive.Boolean))
.with(schema("_common", "StringifiedEpochTimeUnitMillis"), so -> so.withMappedType(Types.Primitive.Long))

// 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))
.with(schema("_common.mapping", "Property"), so -> so.withShouldGenerate(ShouldGenerate.Never))
.with(schema("_common.mapping", "PropertyBase"), so -> so.withShouldGenerate(ShouldGenerate.Never))
.with(schema("_common.mapping", "KnnVectorProperty"), so -> so.withShouldGenerate(ShouldGenerate.Always))

// TODO: Remove this to generate query types
.with(
SCHEMAS.append("_common.query_dsl:QueryContainer"),
schema("_common.query_dsl", "QueryContainer"),
so -> so.withMappedType(t -> t.withPackage(Types.Client.OpenSearch._Types.PACKAGE + ".query_dsl").withName("Query"))
)
// TODO: Remove this to generate index settings types
.with(SCHEMAS.append("indices._common:IndexSettings"), so -> so.withShouldGenerate(ShouldGenerate.Never))
.with(schema("indices._common", "IndexSettings"), so -> so.withShouldGenerate(ShouldGenerate.Never))

.with(
SCHEMAS.append("_common:ShardStatistics"),
schema("_common", "ShardStatistics"),
b -> b.withProperties(
p -> p.with("failed", pb -> pb.withMappedType(Types.Java.Lang.Number))
.with("skipped", pb -> pb.withMappedType(Types.Java.Lang.Number))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.semver4j.Semver;

public class OpenApiSchema extends OpenApiRefElement<OpenApiSchema> {
public static final String NAMESPACE_NAME_SEPARATOR = "___";
public static final JsonPointer COMPONENTS_SCHEMAS = JsonPointer.of("components", "schemas");
private static final JsonPointer ANONYMOUS = JsonPointer.of("<anonymous>");

public static final OpenApiSchema ANONYMOUS_UNTYPED = builder().withPointer(ANONYMOUS.append("untyped")).build();
Expand Down Expand Up @@ -102,13 +104,13 @@ protected OpenApiSchema(@Nullable OpenApiElement<?> parent, @Nonnull JsonPointer

if (pointer.isDirectChildOf(JsonPointer.of("components", "schemas"))) {
var key = pointer.getLastKey().orElseThrow();
var colonIdx = key.indexOf(':');
if (colonIdx >= 0) {
namespace = key.substring(0, colonIdx)
var separatorIndex = key.indexOf(NAMESPACE_NAME_SEPARATOR);
if (separatorIndex >= 0) {
namespace = key.substring(0, separatorIndex)
.replaceAll("\\._common", "")
.replaceAll("^_common", "_types")
.replaceAll("^_core", "core");
name = key.substring(colonIdx + 1);
name = key.substring(separatorIndex + NAMESPACE_NAME_SEPARATOR.length());
} else {
namespace = null;
name = key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Builder builder() {
.withLambda("ERROR", s -> {
throw new RuntimeException(s);
})
.withValue("TYPES", Types.TYPES_MAP);
.withValue("TYPES", Types.asMap());
}

public static final class Builder extends ObjectBuilderBase<TemplateGlobalContext, Builder> {
Expand Down

0 comments on commit 00c3859

Please sign in to comment.