Skip to main content
Swagger
All documentation pages

Quick Start

Enabling the feature

This feature is enabled by default in all organizations. However, if your organization is older, it may be disabled.

To enable the feature and ensure access, follow these steps:

  1. In the UI, navigate to Settings -> Preferences -> System Preferences.

  2. Check the Test Generation checkbox.

  3. Save the settings.

  4. In the UI, navigate to Settings -> Roles -> Administrator.

  5. Check the “Access all AI Capabilities” checkbox (or specify the granular permissions).

  6. Save the settings.

  7. Repeat the process for any other role that you want to give access to.

You must be an Administrator or a user with the system_preference:manage:* permission to perform this action.

The Model Context Protocol (MCP) is the recommended way to use AI. It provides seamless integration with IDEs and modern developer environments.

MCP Server exposes AI as a local endpoint and works with tools like VS Code, IntelliJ, Cursor, and other MCP-compatible agents.

Follow the official MCP Server documentation to perform the following steps:

  • Install the MCP Server.

  • Configure and start the local service.

  • Connect with MCP clients.

This option is ideal for teams working with AI copilots or looking to automate testing workflows.

Option 2: CLI

You can also use AI using the CLI. It supports test generation and review from the terminal.

For *nix users (including Windows users running WSL/msys2/mingw), use the following command to download and install:

curl https://download.pactflow.io/ai/get.sh | sh

For Windows PowerShell users, use the following command to download and install:

Invoke-WebRequest -Uri https://download.pactflow.io/ai/get.ps1 | Invoke-Expression

Installation Options

You can customize the installation using the options below.

For a full list, see the --help/-h command

curl https://download.pactflow.io/ai/get.sh | sh -s -- -h
  • --verbose / -v / PACTFLOW_AI_VERBOSE: Enable verbose output.

  • --quiet / -q / PACTFLOW_AI_QUIET: Disable progress output.

  • --yes / -y / PACTFLOW_AI_YES: Disable confirmation prompt and assume ‘yes’.

  • --destination / -d / PACTFLOW_AI_DESTINATION: Specify the directory to install the binary.

  • --default-host / PACTFLOW_AI_DEFAULT_HOST: Choose a default host triple rather than autodetecting.

  • --no-modify-path / PACTFLOW_AI_NO_MODIFY_PATH: Don’t configure the PATH environment variable.

Verify the installation by running pactflow-ai to ensure it executes successfully.

Manual installation

Alternatively, download the latest version for your OS and architecture from the table below. Be sure to add it to your environment’s PATH:

Table 2. 

OS Architecture Link
Apple Darwin aarch64 InlineImage_Download_01
Apple Darwin x86_64 InlineImage_Download_01
Windows MSVC x86_64 InlineImage_Download_01
Windows MSVC aarch64 InlineImage_Download_01
Linux GNU x86_64 InlineImage_Download_01
Linux MUSL x86_64 InlineImage_Download_01
Linux GNU aarch64 InlineImage_Download_01
Linux MUSL aarch64 InlineImage_Download_01

Linux GNU users need glibc version 2.23 or later.

For systems without glibc or with an older version, use the musl variant instead.

Find the Latest Version

  1. Open the URL for your operating system and architecture. For example, for Apple Silicon (aarch64):

    https://download.pactflow.io/ai/dist/aarch64-apple-darwin/latest
  2. The endpoint returns the latest build version, for example:

    2.0.15+cc48b93c
  3. Remove everything after the + character to obtain the release version:

    2.0.15
  4. Insert the version into the download URL:

    https://download.pactflow.io/ai/dist/aarch64-apple-darwin/2.0.15/pactflow-ai
  5. Download the binary and add it to your environment’s PATH.

Getting Started

Running pactflow-ai --help shows detailed usage for any subcommands.

Authenticating to Swagger Contract Testing

Authentication requires valid Swagger Contract Testing API Tokens, which can be obtained from the Settings > Tokens page of your Swagger Contract Testing organization.

Set the following environment variables, and the CLI will use them to communicate with Swagger Contract Testing:

export PACT_BROKER_BASE_URL="https://YOUR_ORG.pactflow.io"
export PACT_BROKER_TOKEN="YOUR_TOKEN"

Learn more about other ways of configuring AI.

Generating Pact Tests

To generate Pact tests use the pactflow-ai generate subcommand. There are 3 sources that may be used for generation, including openapi, code and request-response.

Let’s assume we have a simple Product API for which we would like to create Pact tests, described by the following OpenAPI description:

products.yml

openapi: 3.0.1
info:
  title: Product API
  description: Pactflow Product API demo
  version: 1.0.0
paths:
  /product/{id}:
    get:
      summary: Find product by ID
      description: Returns a single product
      operationId: getProductByID
      parameters:
      - name: id
        in: path
        description: Product ID
        schema:
          type: string
        required: true
      responses:
        "200":
          description: successful operation
          content:
            "application/json; charset=utf-8":
              schema:
                $ref: '#/components/schemas/Product'
        "404":
          description: Product not found
          content: {}
components:
  schemas:
    Product:
      type: object
      required:
        - id
        - name
        - price
      properties:
        id:
          type: string
        type:
          type: string
        name:
          type: string
        version:
          type: string
        price:
          type: number
  1. Download and save this file as /tmp/products.yml.

  2. Generate a Pact test for the HTTP 200 use case (default) using the following command:

    pactflow-ai generate \
      --openapi     /tmp/products.yml \
      --endpoint "/product/{id}" \
      --output   /tmp/api.pact.spec.ts \
      --language typescript

Be sure to update the paths as necessary. Executing the command should produce something like this:

// Generated by PactFlow// Timestamp: 2025-02-11T00:34:14.067426+00:00// Reference: 06TzSdaSlI4iKH1zIdghimport { PactV3, MatchersV3 } from "@pact-foundation/pact";import { API } from "./src/api";describe('Consumer Pact with Product Service', () => {  const provider = new PactV3({    consumer: 'ProductConsumer',    provider: 'ProductService',  });  describe('Pact for getProductByID', () => {    it('returns a product by ID', () => {      provider        .given('a product with ID exists')        .uponReceiving('a request to get a product by ID')        .withRequest({          method: 'GET',          path: MatchersV3.regex('/product/[a-zA-Z0-9]+', '/product/123'),          headers: {            'Authorization': MatchersV3.regex('Bearer [a-zA-Z0-9]+', 'Bearer token123'),            'Content-Type': 'application/json; charset=utf-8'          }        })        .willRespondWith({          status: 200,          headers: {            'Content-Type': 'application/json; charset=utf-8'          },          body: MatchersV3.like({            id: MatchersV3.string('123'),            name: MatchersV3.string('Product Name'),            price: MatchersV3.number(99.99),            type: MatchersV3.string('Product Type'),            version: MatchersV3.string('1.0')          })        });      return provider.executeTest(async (mockserver) => {        const api = new API(mockserver.url);        const product = await api.getProduct('123');        expect(product).to.deep.equal({          id: '123',          name: 'Product Name',          price: 99.99,          type: 'Product Type',          version: '1.0'        });      });    });  });});

And it’s done! Of course, this test won’t work without being a part of a real project, but hopefully, you can see how you can quickly generate Pact tests using AI, saving time and improving accuracy.

Was this page helpful?