PactFlow Contract Testing

Last modified on September 27, 2023

Availability: Enterprise, Team and Trial plans

SwaggerHub now supports contract testing with PactFlow's Bi-Directional Contract Testing feature. API designers and developers can use PactFlow to ensure that changes to their API will not break applications and can be deployed with confidence. This is available for:

  • Private APIs
  • OpenAPI 2.0, 3.0, and 3.1 API definitions

In order to perform contract testing with PactFlow, you must first set up an account at PactFlow. Your account must be set up with the correct role, as described in the Setting up your PactFlow account for use with SwaggerHub documentation.

A Video Introduction


Setting up PactFlow

To set up contract checking for an API, use the button at the top of the editing pane for the API definition file, as shown below.

The first time you use PactFlow with your API, hover over the button and click Set up Integration.

Choose PactFlow from the pulldown of possible integration types.

The Manage Integrations screen will appear.

From the setup dialog, you must specify:

  • Name – a name for this integration
  • URL – PactFlow Base URL. This can be retrieved from PactFlow with the command Settings > API Tokens > Copy PactFlow Base URL.
  • PactFlow Token – the read/write authentication token for your PactFlow account. This can be retrieved from PactFlow with the command Settings > API Tokens > Read/write token > Copy.

Once you have entered these values, click Next and SwaggerHub will retrieve the applications that are available (as defined in PactFlow). You can then choose the desired application from the pulldown list.

Once the setup is complete, click CREATE to save your PactFlow settings.

Checking Compatibility

Once you have set up PactFlow, hover over the button and click on Check Compatibility to verify that the API is compatible with its consumers. Compatibility is checked across all consumers of the application on the main branch and those that have been deployed or released. If your API is compatible with its consumers, the button will turn green, Compatible will display in the dialog, and you can click View Compatibility Check Result to see the details.

Note: When compatibility is checked, SwaggerHub coordinates with PactFlow to discover all known consumers of the current application (providers in PactFlow terminology). This process is called "cross-contract validation" or simply "contract comparison". For more information on selectors, consult the PactFlow documentation.

If there is an error, the button will turn red. Some details of the problem(s) are provided within SwaggerHub and you can also go to your PactFlow account to determine additional details.

Note that contract testing will not be performed automatically. You must save your file and use the button to run your test.

See Also

Public and Private APIs

Highlight search results