Generator¶
Implementations of generators for the V3 and V4 specifications.
Attributes¶
Classes¶
Generator
¶
Bases: ABC
Abstract generator.
In Pact, a generator is used by Pact to generate data on-the-fly during the contract verification process. Generators are used in combination with matchers to provide more flexible matching of data.
This class is abstract and should not be used directly. Instead, use one of the concrete generator classes. Alternatively, you can create your own generator by subclassing this class
The matcher provides methods to convert into an integration JSON object and a matching rule. These methods are used internally by the Pact library when communicating with the FFI and generating the Pact file.
Functions¶
to_generator_json() -> dict[str, Any]
abstractmethod
¶
Convert the generator to a generator JSON object.
This method is used internally to convert the generator to a JSON object which can be embedded directly in a number of places in the Pact FFI.
For more information about this format, see the docs:
https://github.com/pact-foundation/pact-specification/tree/version-4
and
https://github.com/pact-foundation/pact-specification/tree/version-2?tab=readme-ov-file#matchers
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
The generator as a generator JSON object. |
Source code in src/pact/v3/generate/generator.py
to_integration_json() -> dict[str, Any]
abstractmethod
¶
Convert the matcher to an integration JSON object.
This method is used internally to convert the matcher to a JSON object which can be embedded directly in a number of places in the Pact FFI.
For more information about this format, see the docs:
https://docs.pact.io/implementation_guides/rust/pact_ffi/integrationjson
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
The matcher as an integration JSON object. |
Source code in src/pact/v3/generate/generator.py
GenericGenerator(type: GeneratorType, /, extra_fields: Mapping[str, Any] | None = None, **kwargs: Any)
¶
Bases: Generator
Generic generator.
A generic generator, with the ability to specify the generator type and additional configuration elements.
PARAMETER | DESCRIPTION |
---|---|
type
|
The type of the generator.
TYPE:
|
extra_fields
|
Additional configuration elements to pass to the generator. These fields will be used when converting the generator to both an integration JSON object and a generator JSON object. |
**kwargs
|
Alternative way to pass additional configuration elements to the
generator. See the
TYPE:
|
Source code in src/pact/v3/generate/generator.py
Attributes¶
type = type
instance-attribute
¶
The type of the generator.
Functions¶
to_generator_json() -> dict[str, Any]
¶
Convert the generator to a generator JSON object.
This method is used internally to convert the generator to a JSON object which can be embedded directly in a number of places in the Pact FFI.
For more information about this format, see the docs:
https://github.com/pact-foundation/pact-specification/tree/version-4
and
https://github.com/pact-foundation/pact-specification/tree/version-2?tab=readme-ov-file#matchers
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
The generator as a generator JSON object. |
Source code in src/pact/v3/generate/generator.py
to_integration_json() -> dict[str, Any]
¶
Convert the matcher to an integration JSON object.
This method is used internally to convert the matcher to a JSON object which can be embedded directly in a number of places in the Pact FFI.
For more information about this format, see the docs:
https://docs.pact.io/implementation_guides/rust/pact_ffi/integrationjson
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
The matcher as an integration JSON object. |