Skip to content

Commit e80aa24

Browse files
committed
feat(api): add JSON object and array detection for template variables in evaluator
1 parent 21b8de0 commit e80aa24

4 files changed

Lines changed: 576 additions & 0 deletions

File tree

core/dbio/api/api_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,37 @@ func TestAPIConnectionRender(t *testing.T) {
177177
expected: "2025-01-01",
178178
expectError: false,
179179
},
180+
{
181+
name: "json_payload_with_template_vars",
182+
input: `{"filters":{"from":"{state.from_date}"},"limit":{state.limit},"sort_order":"asc"}`,
183+
expected: `{"filters":{"from":"2025-01-01"},"limit":100,"sort_order":"asc"}`,
184+
setup: func(ac *APIConnection) {
185+
ac.State.State["from_date"] = "2025-01-01"
186+
ac.State.State["limit"] = 100
187+
},
188+
},
189+
{
190+
// YAML map payload (not a JSON string) - this is how YAML parses:
191+
// payload:
192+
// "filters": {"from": "{state.from_date}"}
193+
// "limit": "{state.limit}"
194+
// "sort_order": "asc"
195+
name: "yaml_map_payload_with_template_vars",
196+
input: map[string]any{
197+
"filters": map[string]any{"from": "{state.from_date}"},
198+
"limit": "{state.limit}",
199+
"sort_order": "asc",
200+
},
201+
expected: map[string]any{
202+
"filters": map[string]any{"from": "2025-01-01"},
203+
"limit": 100.0,
204+
"sort_order": "asc",
205+
},
206+
setup: func(ac *APIConnection) {
207+
ac.State.State["from_date"] = "2025-01-01"
208+
ac.State.State["limit"] = 100
209+
},
210+
},
180211
}
181212

182213
for _, tt := range tests {

0 commit comments

Comments
 (0)