Pact Specification
Introductionβ
The Pact Specification (or simply, "Specification" or "spec") is a document that governs the structure of the actual generated contracts (pact files), and also as a test suite for matching logic, to allow for interoperability between languages such as Node and Java. It is versioned to indicate breaking changes and new features introduced that previous versions do not support.
The version of the specification required to verify a pact is written into the pact file itself (under the key metadata.pactSpecification.version
).
Each language implementation of Pact needs to implement the rules of this specification, and advertise which version(s) are supported, corresponding closely to which features are available. See the current supported language features for more.
Language Compatibilityβ
A provider using a language that can support a particular version of the Pact specification, can interoperate with consumers with all previous versions, up to and including, the same as that of the provider.
The reverse is not true. That is, for two languages to use Pact effectively, they must both be able to understand the specification version of the pact generated by the consumer.
The following compatibility matrix illustrates this point, by showing what can be tested given the version of the specification a given client language can support:
Generated pact file spec version (Client) π | 1 | 1.1 | 2 | 3 | 4 |
---|---|---|---|---|---|
Provider spec support π | |||||
1 | β | ||||
1.1 | β | β | |||
2 | β | β | β | ||
3 | β | β | β | β | |
4 | β | β | β | β | β |
What if My Consumer Client Language is Incompatible with my Provider Client Language?β
If you require a feature only available in a version higher than that of the Specification your provider client supports, you have several choices:
- Check you have the latest provider client available to your language.
- If you don't need a feature present in a later version of the spec, you can choose to serialise your contract in a different version. For example, if your provider supports up to v3 and your consumer supports v4 by default, you can choose to serialise a pact with version v3. Consult your language documentation for how to do this.
- If you need a feature available in a later version, you can verify your provider using the Provider Verifier CLI which will always support the latest version of the spec.
Client Language Supportβ
The following table shows the current specification compliance for each of the supported languages:
Implementation | v1 | v1.1 | v2 | v3 | v4 |
---|---|---|---|---|---|
Pact-rust | β | β | |||
Pact-jvm | 0 | β | β | ||
Pact-ruby | β | ||||
Pact-js | β | β | β * | ||
Pact-net | β | β | β * | ||
Pact-python | β | ||||
Pact-php | β | ||||
Pact-go | β | β | β * | ||
Pact-C++ | β | β | |||
scala (scala-pact) | β | ||||
scala (pact4s) | β | β * | |||
swift (pact-consumer-swift) | β | ||||
swift (pact-swift) | β |
- β - Implemented and actively supported
- β * - Implemented in beta
- 0 - Implemented and not actively supported
All new Pact implementations should wrap the Rust implementation using FFI calls, to allow us to roll out new features quickly and consistently across our 10+ Pact languages.
Support is appreciated if you wish to contribute in migrating a language from the Ruby to Rust core, or wish to create a new language implementation
The Specificationβ
Pact Specificaton Philosophyβ
The Pact matching rules follow Postel's Law.
Be as strict as we reasonably can with what we send out (requests).
We should know and be able to control exactly what a consumer is sending out. Information should not be allowed to "leak" silently.
Be as loose as we reasonably can with what we accept (responses).
A provider should be able to send extra information that this particular consumer does not care about, without breaking this consumer.
When writing the matching rules, err on the side of being more strict now, because it will break fewer things to be looser later, than to get stricter later.
Note: One implications of this philosophy is that you cannot verify, using pact, that a key or a header will not be present in a response. You can only verify what is.
Migration Guidesβ
In order to faciliate the move to from v2 to v3 specification, in the respective client libraries, migration guides have been written to help to transition across.
Β General Notesβ
- A migration between pact specifications, for existing published contracts, will trigger a rule
content_that_affects_verification_results
causing acontract_content_changed
/contract_requiring_verification_published
event type as the generated matcher rules may have changed between specifications.