Testing API versioning and catching breaking changes

A breaking change rarely looks like one in the pull request. A field is renamed for clarity. A nullable field becomes required. An enum gains a value. Each one is a one-line diff, and each one can take down a mobile app version you can't force anyone to update.

Testing for breaking changes comes down to two things: knowing what counts as breaking, and running the old contract against the new code.

What breaks clients

ChangeBreaking?
Remove or rename a response fieldYes
Change a field's type ("42" → 42)Yes
Make a response field nullableYes, for clients that don't check
Add a new enum value in a responseOften: clients with a switch hit the default case
Make an optional request field requiredYes
Change a status code (200 → 201, 404 → 403)Yes, for clients that check it
Change the default page size or sort orderOften
Add a new optional response fieldUsually not
Add a new endpointNo

"Usually" matters: a strict client that rejects unknown fields breaks even on additions. Know your clients.

One collection, several versions

Most APIs version in the URL (/v1/orders), a header (Api-Version: 2026-11-01) or a media type. Either way, put the version in a variable:

Output
GET {{baseUrl}}/{{apiVersion}}/orders/{{orderId}}
HTTP
GET {{baseUrl}}/orders/{{orderId}}
Api-Version: {{apiVersion}}

Set apiVersion in the collection variables as the default, and override it per run:

Terminal
requestarium run-collection "Orders API" --env Staging --var apiVersion=v1
requestarium run-collection "Orders API" --env Staging --var apiVersion=v2

The same requests now run against both versions, and every test that passes on v1 keeps passing, or you know exactly which one changed.

Lock the shape with a schema

Field-by-field tests miss renames: the old test checks customer_id, nobody checks that customerId appeared instead. A JSON schema with required fields catches a removed or renamed field, whatever it was renamed to.

In the request's Tests tab, add an assertion on path $ with matches JSON schema:

JSON
{
  "type": "object",
  "required": ["id", "status", "total", "customer_id"],
  "properties": {
    "id": { "type": "string" },
    "status": { "enum": ["pending", "paid", "refunded"] },
    "total": { "type": "number" },
    "customer_id": { "type": "string" }
  }
}

The enum on status is deliberate: when someone adds "disputed", this test fails, and the team has to decide on purpose whether old clients can handle it.

Catch it in the pull request

The point is to find out before merge. Run the old version's tests against the branch's preview or staging deploy in CI:

.github/workflows/api-contract.yml
name: API contract
on: pull_request
jobs:
  contract:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version: [v1, v2]
    steps:
      - run: npm install -g @requestarium/cli
      - run: requestarium run-collection "Orders API" --env Staging --var apiVersion=${{ matrix.version }} --junit results-${{ matrix.version }}.xml
        env:
          REQUESTARIUM_TOKEN: ${{ secrets.REQUESTARIUM_TOKEN }}

A pull request that renames a field fails the v1 job, with the failing assertion in the job log.

Keep the collection and the spec in step

If you have an OpenAPI spec, keep the collection in sync with it, so new fields and endpoints show up as requests to review. See Keep an API collection in sync with its OpenAPI spec. And keep the collection in the same repository as the code, so the test change is reviewed next to the API change: Keep API collections in Git.

Deprecations

When you do retire a version, test the deprecation too: old-version responses should carry Deprecation and Sunset headers well before the switch-off date, so clients get a warning in their logs.

JavaScript
pm.test('v1 announces its sunset', () => {
  if (pm.environment.get('apiVersion') !== 'v1') return;
  pm.response.to.have.header('Sunset');
});