Comparison rules
Bi-directional contract testing decides whether a provider can serve a consumer without running either. The consumer publishes a pact, the provider publishes its OpenAPI document as a provider contract, and Apiome compares the two. This page is the complete rule set of that comparison: what is checked, what each failure means, and how Pact matching rules are read. A message pact compared with an AsyncAPI document follows the same rules, with its own checks and codes: see Message pacts and AsyncAPI.
Apiome runs the comparison whenever a pact or a provider contract is published, and stores each
verdict as a verification result that the matrix and can-i-deploy
read like any other. fail is a failed result; pass and partial are successful ones. The
Pact comparisons page lists recent comparisons and opens each one's
fidelity report.
The same comparison also runs before a pact is published: a check compares an unpublished pact with several provider versions — the provider's main branch, what is deployed, a named version, a draft of its project — and stores nothing. Its verdict for a version is the one a publish would record against it, by the rules on this page.
The verdict
Each interaction of the pact is compared on its own, then the pact gets the worst result of its interactions.
| Verdict | Meaning |
|---|---|
pass | Every part of every interaction was compared, and the provider's document satisfies it. |
partial | Nothing contradicts the pact, but something could not be compared in full. Each gap is listed in the fidelity list. |
fail | The provider's document contradicts at least one interaction. Each contradiction is a failure. |
A partial verdict is a success with caveats. It is never reported as pass, so that a green
result is not read as stronger than the evidence behind it.
When the provider contract is unverified
The comparison trusts the provider's document. Apiome trusts the document only when the provider
sent self-verification evidence that it
passed. Without it — no report, a failing report, or one that proves nothing — the stored verdict
is unverified:
| Comparison found | Evidence | Stored verdict | success |
|---|---|---|---|
pass or partial | verified | pass or partial | true |
pass or partial | anything else | unverified | true under the warn policy, false under fail |
fail | any | fail | false |
comparison.comparisonVerdict keeps what the comparison found, and
comparison.providerContractEvidence the evidence it was weighed against. The policy is set by
APIOME_PACT_UNVERIFIED_PROVIDER_CONTRACT (warn unless your operator changed it).
What is compared
For every interaction, in this order:
| Step | The pact's | Is compared with the provider's |
|---|---|---|
| 1. Operation | Request method and path, such as GET /invoices/1042 | Declared paths. /invoices/1042 resolves to /invoices/{invoiceId}, with or without a server base path. A literal path wins over a templated one. |
| 2. Path parameters | The values in the path | Each path parameter's schema. |
| 3. Query | The query string (Pact 2) or query object (Pact 3 and 4) | Each query parameter's schema and required. |
| 4. Request headers | The request headers | Each header parameter's schema and required. |
| 5. Request body | The body and its content type | The operation's requestBody: required, the declared media types, and the schema of the matching one. |
| 6. Status | The expected status | The operation's responses: the exact code, then its range (2XX), then default. |
| 7. Response headers | The expected headers | The response's headers and their schemas. |
| 8. Response body | The expected body and its content type | The response's content: the declared media types, and the schema of the matching one. |
| 9. Matching rules | Every rule of the request and the response | The schema at the rule's path. See Matching rules. |
If step 1 finds no operation, steps 2 to 8 are skipped and the interaction fails. If step 6 finds no response, steps 7 and 8 are skipped.
Parameters travel as text, so limit=25 is read as the integer 25 for a schema of
type: integer and as the string "25" for one of type: string. An array parameter is split on
commas, or read from repeated query parameters when it is explode: true.
Requests and responses are read differently
A request is something the consumer sends; a response is something it reads. The same schema is therefore held against them in two ways.
| Request | Response | |
|---|---|---|
required | Enforced. A request that leaves out a required property is refused by the provider. | Not enforced. A consumer may read two of the six properties the provider returns. |
| Undeclared properties | Allowed, unless the provider set additionalProperties: false. | Refused, unless the provider opened the object with additionalProperties. A consumer that reads a property the provider never declares will break. |
oneOf | Exactly one branch must accept the body. | Compared as anyOf: at least one branch must accept it. With required not enforced, branches often cannot be told apart. Listed as oneof-relaxed. |
An optional response property the consumer reads is not a failure: the provider declares it, and the comparison cannot know whether it is sent.
OpenAPI 3.0, 3.1 and 3.2
Every schema is validated as JSON Schema 2020-12. An OpenAPI 3.0 document is read into it first:
nullable: truenext to atypeaddsnullto the type.exclusiveMinimum: trueandexclusiveMaximum: truebecome the numeric forms of 2020-12.
A $ref is followed inside the document only. A schema that needs a $ref to another file is not
used; the value it describes is listed as schema-not-usable, never treated as valid.
Failures
Every failure has a stable code, a sentence in message, and three
JSON Pointers:
| Field | Points at |
|---|---|
pactPointer | The offending part of the pact, such as /interactions/0/response/body/customer/email. |
oasPointer | The place in the OpenAPI document, written from the operation down, as if every $ref were inlined. |
resolvedPointer | The same place where it actually lives, such as /components/schemas/Party. This is the node to edit. |
A schema failure also carries keyword (the JSON Schema keyword that failed) and detail (the
validator's own message).
| Code | The provider's document contradicts the pact because |
|---|---|
interaction.malformed | The interaction's request declares no method or no path. |
request.operation.unknown | The provider declares no operation on the request's path. |
request.method.undeclared | The provider declares the path, but not with the request's method. |
request.path-parameter.invalid | A value in the request's path does not satisfy the path parameter's schema. |
request.query.required-missing | The request leaves out a query parameter the provider requires. |
request.query.invalid | A query parameter's value does not satisfy its schema. |
request.header.required-missing | The request leaves out a header the provider requires. |
request.header.invalid | A request header's value does not satisfy its schema. |
request.content-type.undeclared | The request's content type is not one the operation's request body declares. |
request.accept.unsatisfiable | The request's Accept header matches none of the media types the response declares. |
request.body.undeclared | The request sends a body to an operation that declares none. |
request.body.required-missing | The request has no body, but the operation's request body is required. |
request.body.required-mismatch | The request body leaves out a property the provider requires. |
request.body.nullable-mismatch | The request body sends null where the provider does not declare the value nullable. |
request.body.unknown-property | The request body sends a property the provider's schema does not accept. |
request.body.schema-mismatch | The request body breaks another keyword of the provider's schema (type, enum, pattern, a range …). |
response.status.undeclared | The operation declares neither the expected status, its range (2XX) nor default. |
response.header.undeclared | The consumer expects a response header the provider does not declare. |
response.header.invalid | An expected response header's value does not satisfy the declared schema. |
response.content-type.undeclared | The expected response content type is not one the response declares. |
response.body.undeclared | The consumer expects a response body, but the response declares no content. |
response.body.nullable-mismatch | The consumer expects null where the provider does not declare the value nullable. |
response.body.unknown-property | The consumer expects a property the provider's response schema does not declare. |
response.body.schema-mismatch | The expected response body breaks another keyword of the provider's schema. |
A failure in a path, query or header parameter names it as <in>:<name> in oasPointer, such as
/paths/~1invoices~1{invoiceId}/get/parameters/path:invoiceId.
At most 50 failures are listed per interaction. Any more are counted in a findings-truncated
entry of the fidelity list.
An example
A consumer expects customer.email in an invoice, and the provider's Party schema has no such
property:
{
"code": "response.body.unknown-property",
"message": "the response body at /customer expects property 'email', which the provider does not declare",
"pactPointer": "/interactions/0/response/body/customer/email",
"oasPointer": "/paths/~1invoices~1{invoiceId}/get/responses/200/content/application~1json/schema/properties/customer/unevaluatedProperties",
"resolvedPointer": "/components/schemas/Party",
"keyword": "unevaluatedProperties",
"detail": "Unevaluated properties are not allowed ('email' was unexpected)"
}
Warnings
A warning never changes the verdict.
| Code | Meaning |
|---|---|
request.query.undeclared | The request sends a query parameter the provider does not declare. |
request.header.undeclared | The request sends a header the provider does not declare. |
response.status.default | The expected status is covered only by the operation's default response. |
Accept, Authorization, Content-Type, User-Agent and the other headers every HTTP client
sends are not reported as undeclared.
Matching rules
An example says "the consumer saw this value". A matching rule widens that to "any value like this one". Comparing only the example would ignore the widening, so each rule is turned into the JSON Schema constraint that says the same thing, and the provider's schema at the rule's path is asked to prove it:
- In a request, the consumer may send any value the rule allows. The provider's schema must accept all of them: it may not be narrower than the rule.
- In a response, the consumer accepts only what the rule allows. The provider's schema must promise nothing else: it may not be broader than the rule.
Rules are read from Pact specification 2 ($.body.items[*].id), 3 and 4 (body, header,
query, path and status categories).
Matchers that are mapped
| Matcher | Pact | JSON Schema constraint | Notes |
|---|---|---|---|
type | 2, 3, 4 | {"type": <type of the example>} | Cascades to every value below it that has no rule of its own. A number example allows any number in a response and an integer in a request. With min / max on an array it adds minItems / maxItems. |
equality | 2, 3, 4 | {"const": <the example>} | Stops a type cascade. |
regex | 2, 3, 4 | {"type": "string", "pattern": <regex>} | The expression as written. |
include | 3, 4 | {"type": "string", "pattern": <escaped value>} | The substring, escaped so that it is matched literally. |
integer | 3, 4 | {"type": "integer"} | — |
number | 3, 4 | {"type": "number"} | — |
boolean | 4 | {"type": "boolean"} | — |
null | 3, 4 | {"type": "null"} | — |
notEmpty | 4 | {"minLength": 1}, {"minItems": 1} or {"minProperties": 1} | By the type of the example, together with that type. |
Matchers that are not mapped
These have no JSON Schema constraint that says the same thing without loss. The example is still
validated, and the rule is listed as matching-rule-not-mapped.
| Matcher | Pact | Why it has no mapping |
|---|---|---|
decimal | 3, 4 | JSON Schema cannot require a number to have a fractional part. |
date / time / timestamp / datetime | 3, 4 | The format is a Java date pattern, which JSON Schema format cannot express. |
semver | 4 | No JSON Schema keyword describes a semantic version. |
values / eachKey / eachValue | 3, 4 | The rule nests further rules for keys and values. |
arrayContains | 4 | Each variant carries its own nested rules. |
contentType | 3, 4 | Compares bytes by sniffed media type. |
statusCode | 4 | Applies to the response status, which is compared by example. |
A matcher the engine does not know is treated the same way, with one of these reasons:
reason | Meaning |
|---|---|
no-lossless-mapping | No JSON Schema constraint says what the matcher says. |
combined-with-or | Several matchers are combined with OR. |
path-not-understood | The rule's path is not a JSONPath the engine reads. |
unknown-location | The rule is filed under a part of the message the engine does not know. |
When a mapped rule is not proven
A mapped rule the provider's schema does not prove is listed as matching-rule-unverified, with
the constraint it mapped to and one of these reasons. It is not a failure: the example itself was
validated.
reason | The rule is not proven because |
|---|---|
no-provider-schema | The provider declares no schema where the rule applies: the body was not compared, or the header, query or path parameter is not declared. |
path-not-in-example | The rule's path selects nothing in the example. |
path-not-declared | The provider's schema declares nothing at the rule's path. |
composition | The provider's schema at the rule's path is combined with allOf, anyOf, oneOf, not or if; the engine does not reason across combinations. |
provider-narrower | Request: the provider's schema refuses some values the rule lets the consumer send (an enum, a pattern, a length or range limit, another type). |
provider-nullable | Response: the provider may return null where the rule expects a value. |
provider-broader | Response: the provider may return a type the rule does not accept. |
provider-type-undeclared | Response: the provider's schema declares no type here. |
pattern-not-guaranteed | Response: the provider's schema does not declare the rule's expression as its pattern. |
value-not-guaranteed | Response: the provider's schema does not fix the value with const. |
bounds-not-guaranteed | Response: the provider's schema does not promise the length the rule requires. |
budget-exhausted | The pact's rules apply at more than 100,000 locations; the rules past that were not checked. |
A regular expression is proven only by the same expression as the schema's pattern. Apiome does
not evaluate a pact's expression against the provider's values.
The fidelity list
Everything the comparison could not vouch for is recorded here, per interaction. Nothing is dropped silently.
| Code | What was not compared in full |
|---|---|
matching-rule-not-mapped | A matching rule has no lossless JSON Schema mapping; only its example was compared. |
matching-rule-unverified | A matching rule was mapped, but the provider's schema does not prove it. |
embedded-matcher-not-mapped | A body carries a matcher embedded in the example (Pact 1 Ruby style); its value was compared, the matcher was not. |
generator-not-applied | A generator replaces the example at verification time; only the example was compared. |
body-not-compared | A body was not validated: its content type is not JSON, it could not be decoded, the provider declares no schema for it, or it nests too deeply. |
parameter-not-compared | A parameter or header was not validated: it declares no schema, is an object, or uses a style the engine does not parse. |
schema-not-usable | A provider schema could not be evaluated (it does not compile, or needs a $ref outside the document). |
oneof-relaxed | Part of the expected response body is described by a oneOf. With required lifted its branches cannot be told apart, so it was compared as anyOf. |
interaction-not-http | A message interaction has no HTTP exchange to compare with an OpenAPI document. |
findings-truncated | An interaction produced more failures than are listed. |
An entry has code, message and pactPointer, and where they apply reason, oasPointer,
matcher and the constraint a rule mapped to.
The fidelity report
The fidelity report reads the stored comparison and lays it out per interaction, so a green verdict is never read as stronger than it is. Open it on the Pact comparisons page or read it from the API: see Read the fidelity report.
Checks
Every HTTP interaction gets the eight core checks, in the order they run. The two matching-rule checks appear when the interaction declares matching rules or generators.
| Check | Covers |
|---|---|
| Operation (method and path) | The request resolves to a declared operation. |
| Path parameters | The values in the path against the path parameters' schemas. |
| Query parameters | Required, declared and valid query parameters. |
| Request headers | Required, declared and valid request headers. |
| Request body | Content type and body against the request schema. |
| Response status | The expected status, its range or default, and Accept. |
| Response headers | Expected response headers against the declared ones. |
| Response body | Content type and body against the response schema. |
| Request / Response matching rules and generators | Each rule mapped to the schema, and each generator. |
Each check has one status:
| Status | Meaning |
|---|---|
| Compared | The check ran and found nothing to report. |
| Partly compared | The check ran, but a fidelity note says part of it was not compared in full. |
| Failed | The check ran and found a contradiction (a failure). |
| Not run | The check did not run. The reason says why: an earlier check failed (an unknown operation stops the rest), or the interaction has no HTTP exchange. |
Every failure and warning code belongs to exactly one check, and every fidelity note names the
check it belongs to (check), or null for a note about the whole interaction.
Two lists
The fidelity list is split in two:
| List | Codes |
|---|---|
Unsupported matching rules (unsupportedMatchingRules) | matching-rule-not-mapped, matching-rule-unverified, embedded-matcher-not-mapped, generator-not-applied |
Could not compare (couldNotCompare) | body-not-compared, parameter-not-compared, schema-not-usable, oneof-relaxed, interaction-not-http, findings-truncated, and the message codes message-direction-undeclared, message-resolved-by-contents, metadata-not-compared, interaction-not-message, synchronous-message-not-compared |
A code the report does not know (from a newer engine) is still listed under Could not compare.
Strength
The report's strength says how much the verdict is worth:
| Strength | Shown as | When |
|---|---|---|
full | Compared in full | The verdict is pass and every core check of every interaction ran with nothing to report. |
partial | Not everything compared | Nothing contradicts the pact, but something was not compared in full or did not run. |
failed | Contradicts the pact | The verdict is fail. |
none | Nothing compared | The comparison could not run, the pact has no interactions, or none is the kind the contract describes (an HTTP exchange for OpenAPI, a message for AsyncAPI). |
An unverified verdict (see above) keeps the
comparison's own strength; comparisonVerdict holds the verdict before the evidence was weighed,
and selfVerification the evidence status.
Pacts generated from a declared surface
A consumer declared in the picker can export or publish a generated pact. That pact is compared by exactly the rules on this page. Three things about it are worth knowing when you read its verdict:
- Its response bodies carry one
typematcher at$. The sample values are the provider's own examples, so the comparison checks that the provider promises the same shape — every declared field with the same type — not the example values. A nullable field the consumer reads shows as an unproventyperule in the fidelity list. - Its request bodies carry no matcher. They are what the consumer sends, so each value is checked against the request schema as it is.
- A placeholder is still compared. A field with no example gets a value of its declared type,
which the schema accepts, so a placeholder does not fail the comparison — but it only proves the
type. The export's
findingslist every placeholder; add examples to the specification to compare real values.
Generated from the same specification it is compared with, the pact normally passes. It fails when the provider's contract has since dropped or changed something the consumer declared.
Message pacts and AsyncAPI
When the provider contract is an AsyncAPI 2.x or 3.x document, the pact's messages (Pact 3
messages, Pact 4 Asynchronous/Messages) are compared with it instead. How a message is matched
to a message of the document, and why, is on Message pacts. The verdict,
the fidelity list and the matching-rule mappings are the ones above; the checks and codes are
these.
Message checks
| Check | Covers |
|---|---|
Channel and message (message.channel) | The message resolves to a message the provider sends. |
Content type (message.content-type) | The message's content type against the declared one. |
Metadata (message headers) (message.metadata) | Each metadata entry against the message's headers schema. |
Message contents (message.body) | The contents against the payload, read like a response body. |
Matching rules and generators (message.matching-rules) | Each rule mapped to the payload or headers schema, and each generator. |
An interaction the contract does not describe — an HTTP or plugin interaction, or a synchronous message — has every message check Not run.
Message failures
| Code | Meaning |
|---|---|
message.channel.unknown | The message's metadata names a channel, topic or queue the provider declares no channel for. |
message.unknown | No message the provider declares (on the named channel) accepts the pact's message. |
message.ambiguous | The pact names neither a channel nor a declared message, and more messages could match than are tried one by one. |
message.not-sent | The provider declares the message only as one it receives, never as one it sends. |
message.content-type.mismatch | The message's content type is not the one the provider declares for the message. |
message.metadata.invalid | A metadata value does not satisfy the message's headers schema. |
message.body.nullable-mismatch | The consumer expects null where the provider's payload schema does not allow it. |
message.body.unknown-property | The consumer expects a property the provider's payload schema does not declare. |
message.body.schema-mismatch | The message contents break another keyword of the provider's payload schema. |
At most 50 candidate messages are tried one by one (message.ambiguous past that); name the
channel in the message's metadata to narrow it.
Message warnings
| Code | Meaning |
|---|---|
message.metadata.undeclared | The message's metadata carries an entry the message's headers schema does not declare. |
Message fidelity codes
The fidelity codes matching-rule-not-mapped, matching-rule-unverified,
embedded-matcher-not-mapped, generator-not-applied, body-not-compared, schema-not-usable,
oneof-relaxed and findings-truncated mean what the fidelity list says.
body-not-compared also covers a payload written in Avro, Protobuf or another language that is not
JSON Schema (reason: schema-format). The message comparison adds:
| Code | What was not compared in full |
|---|---|
message-direction-undeclared | The provider's document does not say whether it sends or receives the message; it was compared as a message the provider sends. |
message-resolved-by-contents | The pact named no declared message, so it was matched to the first message whose payload accepts its contents. |
metadata-not-compared | A metadata value was not validated: the headers schema combines schemas there, or declares no schema at all. |
interaction-not-message | An HTTP or plugin interaction has no message to compare with an AsyncAPI document. |
synchronous-message-not-compared | A Pact 4 synchronous message (a request and its reply) is not compared yet. |
In a check before publishing
A check reports each interaction with one of three outcomes, read from its failures:
| Outcome | When |
|---|---|
not-in-spec | A failure says the contract has no such operation or message: request.operation.unknown, request.method.undeclared, message.channel.unknown or message.unknown. |
differs | Any other failure or message failure. |
match | No failure — a pass or a partial interaction (its fidelity notes still count). |
A row that does not match carries expected (the pact's response, or a message's contents) and
declared (the contract's response for the expected status — exact, its range such as 2XX, or
default — with local $refs inlined), each cut off past 8 KB with its size. These are what the
Publish page's difference drawer shows.
What is not compared
- Security requirements. Whether a request carries the credentials the operation's
securityasks for. - Cookies, and parameters that are objects or use the
deepObject,pipeDelimited,spaceDelimited,matrixorlabelstyles (listed asparameter-not-compared). - Bodies that are not JSON: form data, XML, text and binary (listed as
body-not-compared). - Provider states. The comparison does not know which data a state sets up.
- Whether the provider behaves as its document says. That is the job of the provider's
self-verification evidence. Without passing
evidence the verdict reads
unverified(see below).
Related
- Publish a provider contract — the provider's side of the comparison.
- Message pacts — message pacts compared with an AsyncAPI document.
- Publish and fetch pacts — the consumer's side.
- Pact Broker concepts — pacticipants, versions and contracts.
- can-i-deploy — where the verdict will be used.