Skip to main content

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.

VerdictMeaning
passEvery part of every interaction was compared, and the provider's document satisfies it.
partialNothing contradicts the pact, but something could not be compared in full. Each gap is listed in the fidelity list.
failThe 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 foundEvidenceStored verdictsuccess
pass or partialverifiedpass or partialtrue
pass or partialanything elseunverifiedtrue under the warn policy, false under fail
failanyfailfalse

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:

StepThe pact'sIs compared with the provider's
1. OperationRequest method and path, such as GET /invoices/1042Declared paths. /invoices/1042 resolves to /invoices/{invoiceId}, with or without a server base path. A literal path wins over a templated one.
2. Path parametersThe values in the pathEach path parameter's schema.
3. QueryThe query string (Pact 2) or query object (Pact 3 and 4)Each query parameter's schema and required.
4. Request headersThe request headersEach header parameter's schema and required.
5. Request bodyThe body and its content typeThe operation's requestBody: required, the declared media types, and the schema of the matching one.
6. StatusThe expected statusThe operation's responses: the exact code, then its range (2XX), then default.
7. Response headersThe expected headersThe response's headers and their schemas.
8. Response bodyThe expected body and its content typeThe response's content: the declared media types, and the schema of the matching one.
9. Matching rulesEvery rule of the request and the responseThe 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.

RequestResponse
requiredEnforced. 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 propertiesAllowed, 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.
oneOfExactly 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: true next to a type adds null to the type.
  • exclusiveMinimum: true and exclusiveMaximum: true become 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:

FieldPoints at
pactPointerThe offending part of the pact, such as /interactions/0/response/body/customer/email.
oasPointerThe place in the OpenAPI document, written from the operation down, as if every $ref were inlined.
resolvedPointerThe 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).

CodeThe provider's document contradicts the pact because
interaction.malformedThe interaction's request declares no method or no path.
request.operation.unknownThe provider declares no operation on the request's path.
request.method.undeclaredThe provider declares the path, but not with the request's method.
request.path-parameter.invalidA value in the request's path does not satisfy the path parameter's schema.
request.query.required-missingThe request leaves out a query parameter the provider requires.
request.query.invalidA query parameter's value does not satisfy its schema.
request.header.required-missingThe request leaves out a header the provider requires.
request.header.invalidA request header's value does not satisfy its schema.
request.content-type.undeclaredThe request's content type is not one the operation's request body declares.
request.accept.unsatisfiableThe request's Accept header matches none of the media types the response declares.
request.body.undeclaredThe request sends a body to an operation that declares none.
request.body.required-missingThe request has no body, but the operation's request body is required.
request.body.required-mismatchThe request body leaves out a property the provider requires.
request.body.nullable-mismatchThe request body sends null where the provider does not declare the value nullable.
request.body.unknown-propertyThe request body sends a property the provider's schema does not accept.
request.body.schema-mismatchThe request body breaks another keyword of the provider's schema (type, enum, pattern, a range …).
response.status.undeclaredThe operation declares neither the expected status, its range (2XX) nor default.
response.header.undeclaredThe consumer expects a response header the provider does not declare.
response.header.invalidAn expected response header's value does not satisfy the declared schema.
response.content-type.undeclaredThe expected response content type is not one the response declares.
response.body.undeclaredThe consumer expects a response body, but the response declares no content.
response.body.nullable-mismatchThe consumer expects null where the provider does not declare the value nullable.
response.body.unknown-propertyThe consumer expects a property the provider's response schema does not declare.
response.body.schema-mismatchThe 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.

CodeMeaning
request.query.undeclaredThe request sends a query parameter the provider does not declare.
request.header.undeclaredThe request sends a header the provider does not declare.
response.status.defaultThe 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​

MatcherPactJSON Schema constraintNotes
type2, 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.
equality2, 3, 4{"const": <the example>}Stops a type cascade.
regex2, 3, 4{"type": "string", "pattern": <regex>}The expression as written.
include3, 4{"type": "string", "pattern": <escaped value>}The substring, escaped so that it is matched literally.
integer3, 4{"type": "integer"}—
number3, 4{"type": "number"}—
boolean4{"type": "boolean"}—
null3, 4{"type": "null"}—
notEmpty4{"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.

MatcherPactWhy it has no mapping
decimal3, 4JSON Schema cannot require a number to have a fractional part.
date / time / timestamp / datetime3, 4The format is a Java date pattern, which JSON Schema format cannot express.
semver4No JSON Schema keyword describes a semantic version.
values / eachKey / eachValue3, 4The rule nests further rules for keys and values.
arrayContains4Each variant carries its own nested rules.
contentType3, 4Compares bytes by sniffed media type.
statusCode4Applies 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:

reasonMeaning
no-lossless-mappingNo JSON Schema constraint says what the matcher says.
combined-with-orSeveral matchers are combined with OR.
path-not-understoodThe rule's path is not a JSONPath the engine reads.
unknown-locationThe 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.

reasonThe rule is not proven because
no-provider-schemaThe 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-exampleThe rule's path selects nothing in the example.
path-not-declaredThe provider's schema declares nothing at the rule's path.
compositionThe 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-narrowerRequest: 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-nullableResponse: the provider may return null where the rule expects a value.
provider-broaderResponse: the provider may return a type the rule does not accept.
provider-type-undeclaredResponse: the provider's schema declares no type here.
pattern-not-guaranteedResponse: the provider's schema does not declare the rule's expression as its pattern.
value-not-guaranteedResponse: the provider's schema does not fix the value with const.
bounds-not-guaranteedResponse: the provider's schema does not promise the length the rule requires.
budget-exhaustedThe 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.

CodeWhat was not compared in full
matching-rule-not-mappedA matching rule has no lossless JSON Schema mapping; only its example was compared.
matching-rule-unverifiedA matching rule was mapped, but the provider's schema does not prove it.
embedded-matcher-not-mappedA body carries a matcher embedded in the example (Pact 1 Ruby style); its value was compared, the matcher was not.
generator-not-appliedA generator replaces the example at verification time; only the example was compared.
body-not-comparedA 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-comparedA parameter or header was not validated: it declares no schema, is an object, or uses a style the engine does not parse.
schema-not-usableA provider schema could not be evaluated (it does not compile, or needs a $ref outside the document).
oneof-relaxedPart 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-httpA message interaction has no HTTP exchange to compare with an OpenAPI document.
findings-truncatedAn 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.

CheckCovers
Operation (method and path)The request resolves to a declared operation.
Path parametersThe values in the path against the path parameters' schemas.
Query parametersRequired, declared and valid query parameters.
Request headersRequired, declared and valid request headers.
Request bodyContent type and body against the request schema.
Response statusThe expected status, its range or default, and Accept.
Response headersExpected response headers against the declared ones.
Response bodyContent type and body against the response schema.
Request / Response matching rules and generatorsEach rule mapped to the schema, and each generator.

Each check has one status:

StatusMeaning
ComparedThe check ran and found nothing to report.
Partly comparedThe check ran, but a fidelity note says part of it was not compared in full.
FailedThe check ran and found a contradiction (a failure).
Not runThe 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:

ListCodes
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:

StrengthShown asWhen
fullCompared in fullThe verdict is pass and every core check of every interaction ran with nothing to report.
partialNot everything comparedNothing contradicts the pact, but something was not compared in full or did not run.
failedContradicts the pactThe verdict is fail.
noneNothing comparedThe 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 type matcher 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 unproven type rule 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 findings list 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​

CheckCovers
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​

CodeMeaning
message.channel.unknownThe message's metadata names a channel, topic or queue the provider declares no channel for.
message.unknownNo message the provider declares (on the named channel) accepts the pact's message.
message.ambiguousThe pact names neither a channel nor a declared message, and more messages could match than are tried one by one.
message.not-sentThe provider declares the message only as one it receives, never as one it sends.
message.content-type.mismatchThe message's content type is not the one the provider declares for the message.
message.metadata.invalidA metadata value does not satisfy the message's headers schema.
message.body.nullable-mismatchThe consumer expects null where the provider's payload schema does not allow it.
message.body.unknown-propertyThe consumer expects a property the provider's payload schema does not declare.
message.body.schema-mismatchThe 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​

CodeMeaning
message.metadata.undeclaredThe 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:

CodeWhat was not compared in full
message-direction-undeclaredThe 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-contentsThe pact named no declared message, so it was matched to the first message whose payload accepts its contents.
metadata-not-comparedA metadata value was not validated: the headers schema combines schemas there, or declares no schema at all.
interaction-not-messageAn HTTP or plugin interaction has no message to compare with an AsyncAPI document.
synchronous-message-not-comparedA 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:

OutcomeWhen
not-in-specA failure says the contract has no such operation or message: request.operation.unknown, request.method.undeclared, message.channel.unknown or message.unknown.
differsAny other failure or message failure.
matchNo 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 security asks for.
  • Cookies, and parameters that are objects or use the deepObject, pipeDelimited, spaceDelimited, matrix or label styles (listed as parameter-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).