# Wildcard vs. Fixture Refactor: Asserting Evolving API Schemas in Karate
0 reputation · 10 Mar 2022, 16:11 UTC
0 reputation · 10 Mar 2022, 16:11 UTC
In Karate 1.x, the match keyword provides a # wildcard that tolerates unspecified fields in API responses, allowing limited schema change tolerance without test failure. However, when a new required field is introduced, the same match block fails, indicating the need for manual updates. The call and callonce mechanisms reduce duplication by reusing request and response fixtures, which can mitigate drift when schemas evolve across multiple test files. Despite these documented features, Karate does not automatically version or migrate expected JSON schemas when the API contract changes, leaving the choice of assertion strategy to test authors. This creates a practical constraint: balancing schema tolerance against fixture maintenance as the API surface grows.
Does relying on the # wildcard in match assertions risk masking breaking changes in downstream API versions? When should a team restructure fixtures via call/callonce versus accepting wildcard tolerance for evolving schemas? How does Karate version affect the reliability of wildcard matching in complex nested JSON structures?
30775 reputation · 10 Mar 2022, 18:47 UTC
Yes. Using the # wildcard in a Karate match lets the test ignore extra or missing fields, so a newly added field (even if it becomes required by the API) will not cause the test to fail. The test will still fail if a field is removed, its type changes, or a required field you explicitly asserted is missing.
call/callonceRefactor when:
# tolerance.Keep wildcard tolerance when:
Karate 0.9.6+ introduced recursive # matching, meaning # works at any depth in nested JSON without needing explicit path wildcards. In versions prior to 0.9.6, # only matched at the literal position you wrote it; nested structures required you to repeat # at each level or use a custom predicate, making complex assertions less reliable and more verbose. Therefore, if you are on Karate 0.9.6 or later, you can safely use # deep inside objects and arrays and expect the same tolerance behavior. On older versions, verify that the wildcard behaves as expected by checking the rendered match expression.
* def karateVersion = karate.version and ensure it is >= 0.9.6 for recursive behavior.# at multiple levels, run it against a known‑good response and against a response where a new required field is added; observe that the test passes in both cases (showing the masking effect).match block into a callonce fixture, update the fixture once, and re‑run all referencing tests to confirm they still pass.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.