Description
JsonMatchAssertionEvaluator.evaluate() ignores assertion.path() entirely. It always compares the entire response body JSON against the expected document, regardless of what path is specified in the assertion.
This means a path like response.body.json.[0].data has no effect — the evaluator matches against the full response body instead of the value at that JSONPath expression.
Steps to Reproduce
Define a json_match assertion with a sub-path, e.g.:
assertions:
- type: json_match
path: response.body.json.[0].data
expected:
type: inline
content: '{"id": 1}'
Expected: the evaluator extracts the value at [0].data from the response JSON and compares it to {"id": 1}.
Actual: the evaluator compares the entire response body to {"id": 1}, causing a spurious failure (or a false pass if the full body happens to match).
Root Cause
In JsonMatchAssertionEvaluator.java, line 114 hardcodes reading the full body:
JsonNode actualNode = objectMapper.valueToTree(response.body().json());
assertion.path() is stored but never read during evaluation.
Expected Fix
Add a private extractTarget(ApiResponse, FailureCollector) method that mirrors the one already implemented in JsonSchemaAssertionEvaluator (lines 147–179):
response.body.json → full parsed body (current behaviour, unchanged)
response.body.json.<jsonpath> → extract the sub-value using com.jayway.jsonpath.JsonPath.read() (already a compile dependency)
- Any other path → record a failure and return
null
Replace the hardcoded body read in evaluate() with a call to extractTarget().
Also remove the stale class-level JavaDoc "Current limitation" paragraph that acknowledges this gap.
Files to Change
src/main/java/io/github/snytkine/apitester/api_tester_cli/service/assertion/JsonMatchAssertionEvaluator.java
src/test/java/io/github/snytkine/apitester/api_tester_cli/service/assertion/JsonMatchAssertionEvaluatorTest.java — add tests for path-based extraction, path-not-found, and unsupported path
Description
JsonMatchAssertionEvaluator.evaluate()ignoresassertion.path()entirely. It always compares the entire response body JSON against the expected document, regardless of what path is specified in the assertion.This means a path like
response.body.json.[0].datahas no effect — the evaluator matches against the full response body instead of the value at that JSONPath expression.Steps to Reproduce
Define a
json_matchassertion with a sub-path, e.g.:Expected: the evaluator extracts the value at
[0].datafrom the response JSON and compares it to{"id": 1}.Actual: the evaluator compares the entire response body to
{"id": 1}, causing a spurious failure (or a false pass if the full body happens to match).Root Cause
In
JsonMatchAssertionEvaluator.java, line 114 hardcodes reading the full body:assertion.path()is stored but never read during evaluation.Expected Fix
Add a private
extractTarget(ApiResponse, FailureCollector)method that mirrors the one already implemented inJsonSchemaAssertionEvaluator(lines 147–179):response.body.json→ full parsed body (current behaviour, unchanged)response.body.json.<jsonpath>→ extract the sub-value usingcom.jayway.jsonpath.JsonPath.read()(already a compile dependency)nullReplace the hardcoded body read in
evaluate()with a call toextractTarget().Also remove the stale class-level JavaDoc "Current limitation" paragraph that acknowledges this gap.
Files to Change
src/main/java/io/github/snytkine/apitester/api_tester_cli/service/assertion/JsonMatchAssertionEvaluator.javasrc/test/java/io/github/snytkine/apitester/api_tester_cli/service/assertion/JsonMatchAssertionEvaluatorTest.java— add tests for path-based extraction, path-not-found, and unsupported path