Package org.mockserver.mock.pact
Class PactExporter
java.lang.Object
org.mockserver.mock.pact.PactExporter
Exports MockServer response expectations as a
Pact v3 consumer contract (JSON), so traffic mocked or
recorded in MockServer can be published to a Pact Broker / PactFlow and used for
consumer-driven contract testing.
Only expectations with an HttpResponse action and a concrete HttpRequest
matcher are exported — forward, callback, and template actions have no Pact equivalent and are
skipped. Matcher values are emitted as concrete example values (Pact's default exact matching).
matchingRules
Non-literal MockServer matchers are translated into a Pact v3 interaction-levelmatchingRules object (categories path / query / header /
body, split across matchingRules.request and matchingRules.response), the
inverse of the mapping in PactImporter:
- a path/query/header value that MockServer would treat as a regex (it contains a regex
metacharacter) →
{"match":"regex","regex":"<value>"}; - a
NottableSchemaStringparam/header (a JSON-schema matcher) →{"match":"type"}(orinteger/number/decimal/booleanper the schematype); - a
JsonSchemaBodyrequest/response body → one{"match":"type"}per top-level schema property (keyed$.field), or a single$rule when the schema declares no properties; - an
XPathBodyrequest/response body → a body-categoryregexrule keyed by the XPath expression.
matchingRules object at all, so its output is
byte-identical to before this mapping existed (Pact's default is exact matching).-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
PactExporter
public PactExporter()
-
-
Method Details
-
export
- Parameters:
expectations- the expectations to export (typically the active expectations)consumer- the consumer name (defaults to "consumer" when blank)provider- the provider name (defaults to "provider" when blank)- Returns:
- the Pact contract as pretty-printed JSON
-