Skip to content

fix: align v3/v4 schemas with what pact_models writes - #174

Draft
YOU54F wants to merge 1 commit into
mainfrom
fix/ffi-compat-v4
Draft

YOU54F wants to merge 1 commit into
mainfrom
fix/ffi-compat-v4

Conversation

@YOU54F

@YOU54F YOU54F commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

I wired these schemas into the pact-msw-adapter golden tests, which build
pacts through pact-js / pact_ffi and compare the rules against our own
matcher implementation. Running every FFI-written pact through the schemas
surfaced a few problems.

v4 rejected valid pacts (17 of the golden cases)

  • eachKey / eachValue: rules were Unknown[] (FIXME). value was
    required and had to look like a $ path, but pact_models writes a
    JSON-encoded example and leaves it out when it's empty. generator
    wasn't allowed.
  • arrayContains: variants were any[]. They're now typed as
    {index, rules, generators?}.
  • statusCode: status can be a class name (success, clientError
    etc.) or a list of codes, not just any string.
  • Date / Time / DateTime generators can carry an expression.
  • ProviderState generators can carry a dataType.
  • body contentTypeHint is optional, and pact_models omits it by default.

Plugin matchers/generators (v4 only)
Plugins can register their own match types and generators. These
serialise as {match: <name>, ...} / {type: <name>, ...}, so v4 now has
matchPlugin / genPlugin as an escape hatch. Known type names are
excluded via not: {enum: [...]}, so a malformed {match: "regex"}
without a regex still fails rather than passing as a "plugin". v3
doesn't get the escape hatch, and an unknown or v4 matcher in a v3 pact
still fails.

Nested rules
Matchers and generators nested under eachKey, eachValue and arrayContains
now $ref #/definitions/matcher / #/definitions/generator, so each
version's schema validates nested rules against its own set.

Pass/fail examples are added for each change. 372 tests pass.

Related: pact-foundation/pact-reference#613 stops the FFI from writing
v4-only rules into v3 pacts (and v3 into v2) in the first place.

Ran every pact the FFI writes (pact-js 16 / pact_ffi 0.5.x) through the
schemas via the pact-msw-adapter golden harness. v4 rejected 17 valid
pacts, and v3 accepted some it shouldn't.

- eachKey / eachValue: rules are real matchers (was Unknown/FIXME),
  value is optional and a JSON-encoded example (not a $-path), generator
  allowed
- arrayContains: variants typed as {index, rules, generators?}
- statusCode: status is a class name or a list of codes
- Date / Time / DateTime generators: optional expression
- ProviderState generator: optional dataType
- body: contentTypeHint optional, pact_models omits it by default
- v4 only: plugin matchers and generators as an escape hatch for unknown
  match/type values. Known types are excluded, so a malformed built-in
  still fails instead of falling through to the plugin shape
- matchers / generators nested inside eachKey, eachValue and arrayContains
  are referenced by $ref, so v3 stays v3 and v4 picks up v4 + plugins

Adds pass/fail examples for each of the above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant