Skip to content

Commit

Permalink
Fix GetIndexRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Sep 26, 2024
1 parent 4bdcb4d commit e0c062e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import org.opensearch.client.opensearch._types.ErrorResponse;
Expand Down Expand Up @@ -437,7 +438,7 @@ public GetIndexRequest build() {
params.put("cluster_manager_timeout", request.clusterManagerTimeout._toJsonString());
}
if (ApiTypeHelper.isDefined(request.expandWildcards)) {
params.put("expand_wildcards", request.expandWildcards.jsonValue());
params.put("expand_wildcards", request.expandWildcards.stream().map(v -> v.jsonValue()).collect(Collectors.joining(",")));
}
if (request.flatSettings != null) {
params.put("flat_settings", String.valueOf(request.flatSettings));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ private Shape visit(Namespace parent, String className, String typedefName, Open
var description = schema.getDescription().orElse(null);

var oneOf = schema.getOneOf();
var isTaggedUnion = oneOf.isPresent()
&& (schema.getDiscriminator().isPresent() || oneOf.orElseThrow().stream().allMatch(OpenApiSchema::hasTitle));

if (schema.isArray()) {
shape = new ArrayShape(parent, className, mapType(schema), typedefName, description);
Expand All @@ -276,47 +278,44 @@ private Shape visit(Namespace parent, String className, String typedefName, Open

shape = new EnumShape(parent, className, variants, typedefName, description);
visitedSchemas.putIfAbsent(schema, shape);
} else if (oneOf.isPresent()
&& (schema.getDiscriminator().isPresent() || oneOf.orElseThrow().stream().allMatch(OpenApiSchema::hasTitle))) {
var discriminatingField = schema.getDiscriminator().flatMap(OpenApiDiscriminator::getPropertyName).orElse(null);
var taggedUnion = new TaggedUnionShape(parent, className, typedefName, description, discriminatingField);
shape = taggedUnion;
visitedSchemas.putIfAbsent(schema, shape);
} else if (isTaggedUnion) {
var discriminatingField = schema.getDiscriminator().flatMap(OpenApiDiscriminator::getPropertyName).orElse(null);
var taggedUnion = new TaggedUnionShape(parent, className, typedefName, description, discriminatingField);
shape = taggedUnion;
visitedSchemas.putIfAbsent(schema, shape);

oneOf.get().forEach(s -> {
String name;
if (discriminatingField != null) {
var props = new HashMap<String, OpenApiSchema>();
collectObjectProperties(s, props, new ArrayList<>());
name = Maps.tryGet(props, discriminatingField)
.flatMap(OpenApiSchema::getEnums)
.flatMap(enums -> enums.stream().findFirst())
.orElseThrow(
() -> new IllegalStateException(
"oneOf variant ["
+ s.getPointer()
+ "] is missing the `"
+ discriminatingField
+ "` property as a single value enum"
)
);
} else {
name = s.getTitle()
.orElseThrow(
() -> new IllegalStateException("oneOf variant [" + s.getPointer() + "] is missing a `title` tag")
);
}
taggedUnion.addVariant(name, mapType(s));
});
} else if (schema.determineSingleType().orElse(null) == OpenApiSchemaType.Object) {
var objShape = new ObjectShape(parent, className, typedefName, description);
shape = objShape;
visitedSchemas.putIfAbsent(schema, shape);
oneOf.get().forEach(s -> {
String name;
if (discriminatingField != null) {
var props = new HashMap<String, OpenApiSchema>();
collectObjectProperties(s, props, new ArrayList<>());
name = Maps.tryGet(props, discriminatingField)
.flatMap(OpenApiSchema::getEnums)
.flatMap(enums -> enums.stream().findFirst())
.orElseThrow(
() -> new IllegalStateException(
"oneOf variant ["
+ s.getPointer()
+ "] is missing the `"
+ discriminatingField
+ "` property as a single value enum"
)
);
} else {
name = s.getTitle()
.orElseThrow(() -> new IllegalStateException("oneOf variant [" + s.getPointer() + "] is missing a `title` tag"));
}
taggedUnion.addVariant(name, mapType(s));
});
} else if (schema.determineSingleType().orElse(null) == OpenApiSchemaType.Object) {
var objShape = new ObjectShape(parent, className, typedefName, description);
shape = objShape;
visitedSchemas.putIfAbsent(schema, shape);

visitInto(schema, objShape);
} else {
throw new NotImplementedException("Unsupported schema: " + schema);
}
visitInto(schema, objShape);
} else {
throw new NotImplementedException("Unsupported schema: " + schema);
}

parent.addShape(shape);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public static final class Util {
public static Type Map(Type keyType, Type valueType) {
return Map.toBuilder()
.withTypeParameters(keyType, valueType)
.withTargetShape(valueType.getTargetShape().orElse(null))
.build();
}

Expand All @@ -92,7 +91,6 @@ public static Type List(Type valueType) {
.withPackage(PACKAGE)
.withName("List")
.withTypeParameters(valueType)
.withTargetShape(valueType.getTargetShape().orElse(null))
.build();
}

Expand Down

0 comments on commit e0c062e

Please sign in to comment.