Skip to content

Commit 18a68b1

Browse files
Fix BDD test lookup to handle oneOf wrappers for array indexing
When a oneOf schema wraps an array type, the World.lookup method needs to unwrap the getActualInstance() before casting to List. This fixes ClassCastException when BDD steps navigate paths like group_by[0].facet where group_by is now a oneOf wrapper. This matches the spec change in datadog-api-spec PR #5141.
1 parent 97093fc commit 18a68b1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/test/java/com/datadog/api/World.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,17 @@ public static Object lookup(Object data, String path)
681681
}
682682
if (part.contains("]")) {
683683
int index = Integer.parseInt(part.replaceAll("]", ""));
684-
result = List.class.cast(result).get(index);
684+
// Unwrap oneOf wrapper before indexing into array
685+
try {
686+
result = List.class.cast(result).get(index);
687+
} catch (ClassCastException e) {
688+
try {
689+
Object unwrapped = result.getClass().getMethod("getActualInstance").invoke(result);
690+
result = List.class.cast(unwrapped).get(index);
691+
} catch (Exception ex) {
692+
throw e;
693+
}
694+
}
685695
} else {
686696
try {
687697
result = HashMap.class.cast(result).get(part);

0 commit comments

Comments
 (0)