Swagger Contract Testing

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

  • Private APIs,

  • OpenAPI 2.0/3.0 API definitions.

To perform contract testing, your account must be set up with the correct role inSwagger Contract Testing, as described in: Setting up your Swagger Contract Testing account for use with Swagger Studio.Integrations

Setup

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

API_screenshot_Pactflow_setting_01.png

The first time you use Swagger Contract Testing with your API, hover over the pactflow-button.png button and click Set up Integration.

The Manage Integrations screen will appear.

API_screenshot_Pactflow_setting_02.png

From the setup dialog, you must specify:

  • Name – a name for this integration.

  • PactFlow Base URLSwagger Contract Testing Base URL. This can be retrieved from Swagger Contract Testing with the command Settings > API Tokens > Copy Swagger Contract Testing Base URL.

  • Read/Write Token – the read/write authentication token for your Swagger Contract Testing account. This can be retrieved from Swagger Contract Testing with the command Settings > API Tokens > Read/write token > Copy.

Once you have entered these values, click Next and Swagger Studio will retrieve the available applications (as defined in Swagger Contract Testing). You can then choose the desired option from the Applications dropdown list.

Once the setup is complete, click Create to save your Swagger Contract Testing settings.

Compatibility

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

compatibility-ok.png

Note

Swagger Studio coordinates with Swagger Contract Testing when compatibility is checked to discover all known consumers of the current application (providers in Swagger Contract Testing terminology). This process is called "cross-contract validation" or simply "contract comparison." For more information on selectors, consult the Swagger Contract Testing documentation.

If there is an error, the pactflow-button.png button will turn red. Some details of the problems are provided within Swagger Studio and you can also go to your Swagger Contract Testing account to determine additional details.

compatibility-error.png

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

See Also

Publication date: