Skip to content

Commit

Permalink
Begin generating index CRUD operations (opensearch-project#1220)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
Xtansia committed Oct 31, 2024
1 parent 8512bbe commit 5e13754
Show file tree
Hide file tree
Showing 19 changed files with 375 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@

public class BooleanEndpoint<RequestT> extends SimpleEndpoint<RequestT, BooleanResponse> {

public BooleanEndpoint(
Function<RequestT, String> method,
Function<RequestT, String> requestUrl,
Function<RequestT, Map<String, String>> queryParameters,
Function<RequestT, Map<String, String>> headers
) {
super(method, requestUrl, queryParameters, headers, false, null);
}

public BooleanEndpoint(
String id,
Function<RequestT, String> method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
import javax.annotation.Nullable;
import org.opensearch.client.codegen.utils.JavaClassKind;
import org.opensearch.client.codegen.utils.Markdown;
import org.opensearch.client.codegen.utils.Strings;

public class EnumShape extends Shape {
Expand All @@ -38,14 +40,17 @@ public Collection<Type> getImplementsTypes() {
return List.of(Types.Client.Json.JsonEnum);
}

public void addVariant(String value, boolean deprecated) {
public void addVariant(String value, String description, boolean deprecated) {
var variant = variants.get(value.toLowerCase());
if (variant == null) {
variant = new Variant(value, deprecated);
variant = new Variant(value, description, deprecated);
variants.put(value.toLowerCase(), variant);
} else {
variant.addAlias(value);
variant.setDeprecated(variant.isDeprecated() || deprecated);
if (description != null) {
variant.setDescription(description);
}
}
}

Expand All @@ -61,16 +66,26 @@ public static class Variant {
private final String wireName;
private final Set<String> aliases = new HashSet<>();
private boolean deprecated;
private String description;

public Variant(String wireName, boolean deprecated) {
public Variant(String wireName, String description, boolean deprecated) {
this.wireName = wireName;
setDescription(description);
this.deprecated = deprecated;
}

public String getWireName() {
return wireName;
}

public String getDescription() {
return description;
}

public void setDescription(@Nullable String description) {
this.description = description != null ? Markdown.toJavaDocHtml(description) : null;
}

public Set<String> getAliases() {
return aliases;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class ObjectShape extends Shape {
protected final Map<String, Field> bodyFields = new TreeMap<>();
protected Field additionalPropertiesField;
private String shortcutProperty;

public ObjectShape(Namespace parent, String className, String typedefName, String description) {
super(parent, className, typedefName, description);
Expand Down Expand Up @@ -62,6 +63,14 @@ public Field getAdditionalPropertiesField() {
return additionalPropertiesField;
}

public String getShortcutProperty() {
return shortcutProperty;
}

public void setShortcutProperty(String shortcutProperty) {
this.shortcutProperty = shortcutProperty;
}

public boolean hasFieldsToSerialize() {
return !bodyFields.isEmpty() || additionalPropertiesField != null;
}
Expand Down Expand Up @@ -108,6 +117,10 @@ public Collection<Type> getAnnotations() {
return (hasFieldsToSerialize() || extendsOtherShape()) && !isAbstract() ? List.of(Types.Client.Json.JsonpDeserializable) : null;
}

public boolean shouldImplementPlainDeserializable() {
return Set.of("SourceField", "TypeMapping").contains(getClassName());
}

public static class ReferencingDiscriminatedUnion {
private final TaggedUnionShape union;
private final String discriminatorValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class RequestShape extends ObjectShape {
private final Map<String, Field> pathParams = new TreeMap<>();
@Nonnull
private final Map<String, Field> fields = new TreeMap<>();
private boolean isBooleanRequest;

public RequestShape(@Nonnull Namespace parent, @Nonnull OperationGroup operationGroup, @Nullable String description) {
super(parent, requestClassName(operationGroup), operationGroup.asTypedefPrefix() + ".Request", description);
Expand Down Expand Up @@ -72,8 +73,18 @@ public void addSupportedHttpMethod(String method) {
httpMethods.add(method);
}

public void setIsBooleanRequest() {
isBooleanRequest = true;
}

public boolean isBooleanRequest() {
return isBooleanRequest;
}

public Type getResponseType() {
return Type.builder().withPackage(getPackageName()).withName(responseClassName(operationGroup)).build();
return !isBooleanRequest
? Type.builder().withPackage(getPackageName()).withName(responseClassName(operationGroup)).build()
: Types.Client.Transport.Endpoints.BooleanResponse;
}

public boolean canBeSingleton() {
Expand Down Expand Up @@ -169,6 +180,10 @@ private static String responseClassName(@Nonnull OperationGroup operationGroup)
private static String classBaseName(@Nonnull OperationGroup operationGroup) {
Objects.requireNonNull(operationGroup, "operationGroup must not be null");
switch (operationGroup.toString()) {
case "indices.create":
return "CreateIndex";
case "indices.delete":
return "DeleteIndex";
case "indices.get":
return "GetIndex";
case "snapshot.clone":
Expand Down
Loading

0 comments on commit 5e13754

Please sign in to comment.