Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 12a450c

Browse files
committedFeb 18, 2025
Generate part of core namespace (opensearch-project#1377)
* Generate clear_score and ignore paths/operations that have been deprecated since OS 1.0 Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate count Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate create_pit Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate delete Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate delete_all_pits & delete_pit Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate delete_by_query, reindex & update_by_query Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate delete_by_query_rethrottle, reindex_rethrottle, update_by_query_rethrottle Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate get_all_pits Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate delete_script, get_script, get_script_context, get_script_languages & put_script Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate exists & exists_source Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate field_caps Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate mtermvectors Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate ping Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate rank_eval Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate render_search_template Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Generate search_shards Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Remove terms_enum Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix build Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit dffa9c9)
1 parent 65213c4 commit 12a450c

File tree

8 files changed

+164
-190
lines changed

8 files changed

+164
-190
lines changed
 

‎java-codegen/opensearch-openapi.yaml

+127-184
Large diffs are not rendered by default.

‎java-codegen/src/main/java/org/opensearch/client/codegen/model/EnumShape.java

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public Set<String> getAliases() {
9595
}
9696

9797
public void addAlias(String alias) {
98+
if (alias.equals(wireName)) {
99+
return;
100+
}
98101
aliases.add(alias);
99102
}
100103

‎java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void visit(@Nonnull OpenApiSpecification spec) {
9191
.flatMap(Optional::stream)
9292
.map(Map::values)
9393
.flatMap(Collection::stream)
94+
.filter(o -> o.getDeprecation().map(d -> d.getVersion().isGreaterThan(Versions.V1_0_0)).orElse(true))
9495
.forEach(operation -> {
9596
var group = operation.getOperationGroup();
9697
if (!matcher.matches(group)) {
@@ -608,6 +609,9 @@ private void visitInto(OpenApiSchema schema, EnumShape shape) {
608609
} else if (schema.hasConst()) {
609610
var value = (String) schema.getConst().orElseThrow();
610611
shape.addVariant(title.orElse(value), value, schema.getDescription().orElse(null), isDeprecated);
612+
} else if (schema.isBoolean()) {
613+
shape.addVariant(title.orElse("true"), "true", schema.getDescription().orElse(null), isDeprecated);
614+
shape.addVariant(title.orElse("false"), "false", schema.getDescription().orElse(null), isDeprecated);
611615
}
612616
}
613617

@@ -843,7 +847,18 @@ private static boolean isEnum(OpenApiSchema schema) {
843847
return schema.hasEnums() || schema.hasConst();
844848
}
845849
if (schema.getOneOf().isPresent()) {
846-
return schema.getOneOf().get().stream().allMatch(SpecTransformer::isEnum);
850+
var enumCount = 0;
851+
var booleanCount = 0;
852+
var totalCount = 0;
853+
for (var s : schema.getOneOf().orElseThrow()) {
854+
if (s.isBoolean()) {
855+
booleanCount++;
856+
} else if (isEnum(s)) {
857+
enumCount++;
858+
}
859+
totalCount++;
860+
}
861+
return enumCount == totalCount || (booleanCount == 1 && enumCount == totalCount - 1);
847862
}
848863
return false;
849864
}

‎java-codegen/src/main/java/org/opensearch/client/codegen/model/TaggedUnionShape.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ public Type getVariantInterfaceType() {
104104
}
105105

106106
public boolean canStringify() {
107-
return !isDiscriminated() && getVariants().stream().allMatch(v -> {
108-
var t = v.getType();
109-
return t.isPotentiallyBoxedPrimitive() || t.isString() || t.isEnum();
110-
});
107+
return !isDiscriminated() && getVariants().stream().allMatch(v -> v.getType().canQueryParamify());
111108
}
112109

113110
public boolean hasAmbiguities() {

‎java-codegen/src/main/java/org/opensearch/client/codegen/model/Type.java

+10
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,16 @@ public Type withTypeParameters(Type... typeParams) {
247247
return toBuilder().withTypeParameters(typeParams).build();
248248
}
249249

250+
public boolean canQueryParamify() {
251+
if (isString() || isEnum() || isPotentiallyBoxedPrimitive() || isNumber()) {
252+
return true;
253+
}
254+
if (isList()) {
255+
return getListValueType().canQueryParamify();
256+
}
257+
return false;
258+
}
259+
250260
public Mustache.Lambda queryParamify() {
251261
return new TypeQueryParamifyLambda(this);
252262
}

‎java-codegen/src/main/java/org/opensearch/client/codegen/model/overrides/Overrides.java

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ private static JsonPointer schema(String namespace, String name) {
113113

114114
.with(schema("_common.query_dsl", "QueryContainer"), so -> so.withClassName("Query"))
115115

116+
.with(schema("_core.mtermvectors", "Operation"), so -> so.withClassName("MultiTermVectorsOperation"))
117+
.with(schema("_core.mtermvectors", "TermVectorsResult"), so -> so.withClassName("MultiTermVectorsResult"))
118+
119+
.with(schema("_core.reindex", "Source"), so -> so.withProperties(p -> p.with("_source", po -> po.withName("sourceFields"))))
120+
116121
.with(
117122
schema("_core.search", "SourceFilter").append("oneOf", "1"),
118123
so -> so.withAliasProvider(k -> k.endsWith("cludes") ? Set.of(k.substring(0, k.length() - 1)) : null)

‎java-codegen/src/main/java/org/opensearch/client/codegen/utils/Markdown.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class Markdown {
1616
private Markdown() {}
1717

1818
private static final Parser PARSER = Parser.builder().build();
19-
private static final HtmlRenderer RENDERER = HtmlRenderer.builder().omitSingleParagraphP(true).build();
19+
private static final HtmlRenderer RENDERER = HtmlRenderer.builder().escapeHtml(true).omitSingleParagraphP(true).build();
2020

2121
@Nonnull
2222
public static String toJavaDocHtml(@Nonnull String markdown) {

‎java-codegen/src/main/java/org/opensearch/client/codegen/utils/Versions.java

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public final class Versions {
1515
private Versions() {}
1616

17+
public static final Semver V1_0_0 = Semver.of(1, 0, 0);
1718
public static final Semver V2_0_0 = Semver.of(2, 0, 0);
1819

1920
@Nonnull

0 commit comments

Comments
 (0)
Please sign in to comment.