Skip to content

Commit 4dc54b3

Browse files
committed
fix: use correct matching rule serialisation
The serialisation used internally for `with_matching_rules` used the default JSON encoder. This now has been fixed and allows for matchers to be used directly. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent 7be0ff6 commit 4dc54b3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/pact/interaction/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from typing import TYPE_CHECKING, Any, Literal
1717

1818
import pact_ffi
19-
from pact.match.matcher import IntegrationJSONEncoder
19+
from pact.match.matcher import IntegrationJSONEncoder, MatchingRuleJSONEncoder
2020

2121
if TYPE_CHECKING:
2222
from pathlib import Path
@@ -556,7 +556,7 @@ def with_matching_rules(
556556
response.
557557
"""
558558
if isinstance(rules, dict):
559-
rules = json.dumps(rules)
559+
rules = json.dumps(rules, cls=MatchingRuleJSONEncoder)
560560

561561
pact_ffi.with_matching_rules(
562562
self._handle,

src/pact/match/matcher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,12 @@ def default(self, o: Any) -> Any: # noqa: ANN401
424424
Returns:
425425
The encoded object.
426426
"""
427-
if isinstance(o, AbstractMatcher):
427+
if isinstance(o, AndMatcher):
428428
return o.to_matching_rule()
429+
if isinstance(o, AbstractMatcher):
430+
# We need to convert all matchers in AndMatchers (even if there is
431+
# only one).
432+
return AndMatcher(o).to_matching_rule()
429433
return super().default(o)
430434

431435

0 commit comments

Comments
 (0)