mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(eventbridge): resolve indexed input paths (#6929)
This commit is contained in:
1 parent
aecabcb783
commit
e2d65a6378
2 files changed
+15
-1
No files matched your search
+2
-1
@@ -450,7 +450,8 @@ public class EventBridgeInvoker {
|
||||
}
|
||||
|
||||
private static String toPointer(String jsonPath) {
|
||||
return (jsonPath.startsWith("$") ? jsonPath.substring(1) : jsonPath).replace('.', '/');
|
||||
return (jsonPath.startsWith("$") ? jsonPath.substring(1) : jsonPath)
|
||||
.replaceAll("\\[(\\d+)\\]", "/$1").replace('.', '/');
|
||||
}
|
||||
|
||||
String extractJsonPath(String jsonPath, String eventJson) {
|
||||
|
||||
+13
@@ -412,6 +412,19 @@ class EventBridgeInvokerTest {
|
||||
assertEquals("42", invoker.extractJsonPath("$.detail.size", event));
|
||||
}
|
||||
|
||||
@Test
|
||||
void indexedPathsAreSharedByInputPathAndInputTransformer() {
|
||||
String event = "{\"detail\":{\"items\":[{\"name\":\"first\"},{\"name\":\"second\"}]}}";
|
||||
assertEquals("second", invoker.applyInputPath("$.detail.items[1].name", event));
|
||||
|
||||
InputTransformer transformer = new InputTransformer();
|
||||
transformer.setInputPathsMap(Map.of("name", "$.detail.items[0].name"));
|
||||
transformer.setInputTemplate("{\"name\":<name>}");
|
||||
assertEquals("{\"name\":\"first\"}", invoker.applyInputTransformer(transformer, event));
|
||||
assertTrue(invoker.extractNode("$.detail.items[2]", event).isMissingNode());
|
||||
assertEquals("value", invoker.extractNode("$[0][0]", "[[\"value\"]]").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyInputPath_extractsNestedField() {
|
||||
String event = "{\"source\":\"aws.s3\",\"detail\":{\"bucket\":\"my-bucket\",\"key\":\"file.txt\"}}";
|
||||
|
||||
Reference in new issue
Block a user