Skip to content

Commit

Permalink
Regenerate dangling_indices namespace (opensearch-project#1124)
Browse files Browse the repository at this point in the history
* Rename genericArgs to typeParams

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

* Fix required path param handling

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

* Correctly generate AcknowledgedResponseBase

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

* Generate DeleteDanglingIndexRequest

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

* Correctly generate DeleteDanglingIndexResponse

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

* Generate import_dangling_index

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

* Generate ListDanglingIndicesRequest

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

* Generate ErrorCause

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

* Generate NodeStatistics

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

* Generate DanglingIndex

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

* Generate ListDanglingIndicesResponse

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

* Generate DanglingIndicesClient

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

* Fixes

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

* Changelog and Upgrading

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

* Fix javadoc

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

* Fix tests

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

---------

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 324f90a)
  • Loading branch information
Xtansia committed Aug 30, 2024
1 parent 106233a commit 52f245b
Show file tree
Hide file tree
Showing 26 changed files with 835 additions and 183 deletions.
664 changes: 551 additions & 113 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 @@ -31,7 +31,7 @@ public Collection<Type> getAnnotations() {

@Override
public Collection<Type> getImplementsTypes() {
return List.of(Types.Client.Json.JsonpSerializable);
return List.of(Types.Client.Json.PlainJsonSerializable);
}

public Field getValueBodyField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,32 @@ public class Field {
private final String description;
@Nullable
private final Deprecation deprecation;
private final boolean isAdditionalProperties;

public Field(
@Nonnull String wireName,
@Nonnull Type type,
boolean required,
@Nullable String description,
@Nullable Deprecation deprecation
) {
this(wireName, type, required, description, deprecation, false);
}

public Field(
@Nonnull String wireName,
@Nonnull Type type,
boolean required,
@Nullable String description,
@Nullable Deprecation deprecation,
boolean isAdditionalProperties
) {
this.wireName = Strings.requireNonBlank(wireName, "wireName must not be null");
this.type = Objects.requireNonNull(type, "type must not be null");
this.required = required;
this.description = description;
this.deprecation = deprecation;
this.isAdditionalProperties = isAdditionalProperties;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public List<Field> getParams() {
return Lists.filterMap(parts, Part::isParameter, Part::getParameter);
}

public Set<String> getParamNameSet() {
return parts.stream().filter(Part::isParameter).map(p -> p.getParameter().getName()).collect(Collectors.toSet());
public Set<String> getParamWireNameSet() {
return parts.stream().filter(Part::isParameter).map(p -> p.getParameter().getWireName()).collect(Collectors.toSet());
}

public Deprecation getDeprecation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.TreeMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.opensearch.client.codegen.exceptions.RenderException;
import org.opensearch.client.codegen.utils.Lists;
import org.opensearch.client.codegen.utils.Strings;
Expand Down Expand Up @@ -96,7 +97,7 @@ private String getClientClassName(boolean async, boolean base) {
private Type getClientType(boolean async, boolean base) {
var type = Type.builder().pkg(getPackageName()).name(getClientClassName(async, base));
if (base) {
type.genericArgs(getClientType(async, false));
type.typeParams(getClientType(async, false));
}
return type.build();
}
Expand All @@ -106,7 +107,7 @@ private static class Client extends Shape {
private final Collection<RequestShape> operations;

private Client(Namespace parent, boolean async, Collection<RequestShape> operations) {
super(parent, parent.getClientClassName(async, false), null, null);
super(parent, parent.getClientClassName(async, false), null, "Client for the " + parent.name + " namespace.");
this.async = async;
this.operations = operations;
}
Expand Down Expand Up @@ -137,6 +138,11 @@ public boolean isAsync() {
return this.async;
}

@Override
public String toString() {
return new ToStringBuilder(this).append("type", getType()).toString();
}

private static class ClientRef {
private final Type type;
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ public Type getExtendsType() {
return extendsType;
}

public boolean extendsOtherShape() {
return extendsType != null;
}

public boolean hasFieldsToSerialize() {
return !bodyFields.isEmpty() || additionalPropertiesField != null;
}

public Collection<Type> getImplementsTypes() {
return !bodyFields.isEmpty() ? List.of(Types.Client.Json.JsonpSerializable) : null;
return hasFieldsToSerialize() && !extendsOtherShape() ? List.of(Types.Client.Json.PlainJsonSerializable) : null;
}

public Collection<Type> getAnnotations() {
return !bodyFields.isEmpty() ? List.of(Types.Client.Json.JsonpDeserializable) : null;
return (hasFieldsToSerialize() || extendsOtherShape()) && !isAbstract() ? List.of(Types.Client.Json.JsonpDeserializable) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public String getId() {
return operationGroup.getName();
}

@Override
public boolean extendsOtherShape() {
return extendsType != Types.Client.OpenSearch._Types.RequestBase;
}

public String getHttpMethod() {
return Streams.sortedBy(httpMethods.stream(), m -> {
switch (m) {
Expand Down Expand Up @@ -144,6 +149,10 @@ public boolean hasAnyRequiredFields() {
return fields.values().stream().anyMatch(Field::isRequired);
}

public Type getJsonEndpointType() {
return Types.Client.Transport.JsonEndpoint(getType(), getResponseType(), Types.Client.OpenSearch._Types.ErrorResponse);
}

@Nonnull
private static String requestClassName(@Nonnull OperationGroup operationGroup) {
Objects.requireNonNull(operationGroup, "operationGroup must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public JavaClassKind getClassKind() {
return JavaClassKind.Class;
}

public boolean isAbstract() {
return this.className.endsWith("Base");
}

public String getTypedefName() {
return this.typedefName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.client.codegen.openapi.HttpStatusCode;
import org.opensearch.client.codegen.openapi.In;
import org.opensearch.client.codegen.openapi.JsonPointer;
import org.opensearch.client.codegen.openapi.MimeType;
import org.opensearch.client.codegen.openapi.OpenApiMediaType;
import org.opensearch.client.codegen.openapi.OpenApiOperation;
import org.opensearch.client.codegen.openapi.OpenApiParameter;
import org.opensearch.client.codegen.openapi.OpenApiPath;
import org.opensearch.client.codegen.openapi.OpenApiRefElement;
import org.opensearch.client.codegen.openapi.OpenApiRequestBody;
import org.opensearch.client.codegen.openapi.OpenApiResponse;
import org.opensearch.client.codegen.openapi.OpenApiSchema;
Expand Down Expand Up @@ -104,7 +106,16 @@ private void visit(@Nonnull OperationGroup group, @Nonnull List<OpenApiOperation
.flatMap(OpenApiResponse::getContent)
.flatMap(c -> c.get(MimeType.Json))
.flatMap(OpenApiMediaType::getSchema)
.map(OpenApiSchema::resolve)
.map(s -> {
if (s.get$ref()
.map(OpenApiRefElement.RelativeRef::getPointer)
.flatMap(JsonPointer::getLastKey)
.map("_common:AcknowledgedResponseBase"::equals)
.orElse(false)) {
return OpenApiSchema.builder().withPointer(s.getPointer()).withAllOf(s, OpenApiSchema.ANONYMOUS_OBJECT).build();
}
return s.resolve();
})
.orElse(OpenApiSchema.ANONYMOUS_OBJECT);

visit(parent, requestShape.getResponseType().getName(), group + ".Response", responseSchema);
Expand Down Expand Up @@ -139,12 +150,12 @@ private RequestShape visit(@Nonnull Namespace parent, @Nonnull OperationGroup gr

var httpPath = HttpPath.from(httpPathStr, variant, allPathParams);

(httpPath.getDeprecation() == null ? canonicalPaths : deprecatedPaths).put(httpPath.getParamNameSet(), httpPath);
(httpPath.getDeprecation() == null ? canonicalPaths : deprecatedPaths).put(httpPath.getParamWireNameSet(), httpPath);

if (requiredPathParams != null) {
requiredPathParams.retainAll(httpPath.getParamNameSet());
requiredPathParams.retainAll(httpPath.getParamWireNameSet());
} else {
requiredPathParams = new HashSet<>(httpPath.getParamNameSet());
requiredPathParams = new HashSet<>(httpPath.getParamWireNameSet());
}
}

Expand Down Expand Up @@ -277,16 +288,17 @@ private void visitInto(OpenApiSchema schema, ObjectShape shape) {
)
);

var additionalProperties = schema.getAdditionalProperties();
if (additionalProperties.isPresent()) {
var valueType = mapType(additionalProperties.get());
var additionalProperties = schema.getAdditionalProperties().orElse(null);
if (additionalProperties != null) {
var valueType = mapType(additionalProperties);
shape.setAdditionalPropertiesField(
new Field(
"metadata",
additionalProperties.getTitle().orElseThrow(),
Types.Java.Util.Map(Types.Java.Lang.String, valueType),
false,
additionalProperties.get().getDescription().orElse(null),
null
additionalProperties.getDescription().orElse(null),
null,
true
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Collection<Type> getAnnotations() {
public Collection<Type> getImplementsTypes() {
return List.of(
Types.Client.Util.TaggedUnion(getType().getNestedType("Kind"), Types.Java.Lang.Object),
Types.Client.Json.JsonpSerializable
Types.Client.Json.PlainJsonSerializable
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@ public static Builder builder() {

private final String pkg;
private final String name;
private final Type[] genericArgs;
private final Type[] typeParams;
private final boolean isEnum;

private Type(Builder builder) {
this.pkg = builder.pkg;
this.name = builder.name;
this.genericArgs = builder.genericArgs;
this.typeParams = builder.typeParams;
this.isEnum = builder.isEnum;
}

public Builder toBuilder() {
return new Builder().pkg(pkg).name(name).genericArgs(genericArgs).isEnum(isEnum);
return new Builder().pkg(pkg).name(name).typeParams(typeParams).isEnum(isEnum);
}

@Override
public String toString() {
String str = name;
if (genericArgs != null && genericArgs.length > 0) {
if (typeParams != null && typeParams.length > 0) {
str += "<";
str += Arrays.stream(genericArgs).map(Type::toString).collect(Collectors.joining(", "));
str += Arrays.stream(typeParams).map(Type::toString).collect(Collectors.joining(", "));
str += ">";
}
return str;
Expand Down Expand Up @@ -104,19 +104,19 @@ public boolean isMap() {
public Type getMapEntryType() {
if (!isMap()) return null;

return Java.Util.MapEntry(this.genericArgs[0], this.genericArgs[1]);
return Java.Util.MapEntry(this.typeParams[0], this.typeParams[1]);
}

public Type getMapKeyType() {
if (!isMap()) return null;

return this.genericArgs[0];
return this.typeParams[0];
}

public Type getMapValueType() {
if (!isMap()) return null;

return this.genericArgs[1];
return this.typeParams[1];
}

public boolean isList() {
Expand All @@ -126,7 +126,7 @@ public boolean isList() {
public Type getListValueType() {
if (!isList()) return null;

return this.genericArgs[0];
return this.typeParams[0];
}

public boolean isListOrMap() {
Expand Down Expand Up @@ -186,15 +186,15 @@ public void getRequiredImports(Set<String> imports, String currentPkg) {
var dotIdx = name.indexOf('.');
imports.add(pkg + '.' + (dotIdx > 0 ? name.substring(0, dotIdx) : name));
}
if (genericArgs != null) {
for (Type arg : genericArgs) {
if (typeParams != null) {
for (Type arg : typeParams) {
arg.getRequiredImports(imports, currentPkg);
}
}
}

public Type withGenericArgs(Type... genericArgs) {
return toBuilder().genericArgs(genericArgs).build();
public Type withTypeParams(Type... typeParams) {
return toBuilder().typeParams(typeParams).build();
}

public Mustache.Lambda queryParamify() {
Expand All @@ -204,7 +204,7 @@ public Mustache.Lambda queryParamify() {
public static final class Builder {
private String pkg;
private String name;
private Type[] genericArgs;
private Type[] typeParams;
private boolean isEnum;

public Builder pkg(String pkg) {
Expand All @@ -217,8 +217,8 @@ public Builder name(String name) {
return this;
}

public Builder genericArgs(Type... genericArgs) {
this.genericArgs = genericArgs;
public Builder typeParams(Type... typeParams) {
this.typeParams = typeParams;
return this;
}

Expand Down
Loading

0 comments on commit 52f245b

Please sign in to comment.