PHPackages                             swaggest/api-compat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. swaggest/api-compat

ActiveTool[API Development](/categories/api)

swaggest/api-compat
===================

API compatibility checker for swagger.json

v1.0.3(6y ago)416[1 issues](https://github.com/swaggest/api-compat/issues)MITPHPCI failing

Since Sep 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/swaggest/api-compat)[ Packagist](https://packagist.org/packages/swaggest/api-compat)[ RSS](/packages/swaggest-api-compat/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

API compatibility checker for swagger.json
==========================================

[](#api-compatibility-checker-for-swaggerjson)

A PHP implementation for finding breaking changes between two `swagger.json` documents.

[![Build Status](https://camo.githubusercontent.com/88b28b651a0d967965c3fc98247e21a3e21f48b3828d54635ec2abe1f00388fa/68747470733a2f2f7472617669732d63692e6f72672f73776167676573742f6170692d636f6d7061742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/swaggest/api-compat)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/be1867ce72ffd64e7679cae11a20ce61b25976aa4a5be480822bf027686a4cd4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73776167676573742f6170692d636f6d7061742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/swaggest/api-compat/?branch=master)[![Code Climate](https://camo.githubusercontent.com/2695c61b2241b743047ee15689cc4500e15af9f7a4faee0f84bfe42018037062/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73776167676573742f6170692d636f6d7061742f6261646765732f6770612e737667)](https://codeclimate.com/github/swaggest/api-compat)[![Test Coverage](https://camo.githubusercontent.com/fd02e037e0118d09a445f2a8f2c1830978f87f198aa50abafc7e5f794faa6fd3/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73776167676573742f6170692d636f6d7061742f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/swaggest/api-compat/coverage)[![Image Size](https://camo.githubusercontent.com/10ae53733d095ffb23a6aa70c099e2ec092509b68b0ff54e123e75276c49ba4e/68747470733a2f2f696d616765732e6d6963726f6261646765722e636f6d2f6261646765732f696d6167652f73776167676573742f6170692d636f6d7061742e737667)](https://microbadger.com/images/swaggest/api-compat)

CLI tool
--------

[](#cli-tool)

### Usage

[](#usage)

```
bin/api-compat --help
v1.0.0 api-compat
API compatibility checker for swagger.json, https://github.com/swaggest/api-compat
Usage:
   api-compat
   originalPath   Path to old (original) swagger.json file
   newPath        Path to new swagger.json file

Options:
   --verbose    Verbose output

Misc:
   --help               Show usage information
   --version            Show version
   --bash-completion    Generate bash completion
   --install            Install to /usr/local/bin/

```

### Example

[](#example)

After finding breaking changes, `api-compat` will exit with code `1`

```
bin/api-compat tests/resources/petstore1.json tests/resources/petstore2.json --verbose
Optional parameter became required at #/paths/'/pet/{petId}'/post/parameters/2/required
Parameter disposition has changed at #/paths/'/pet/{petId}/uploadImage'/post/parameters/1/in
original: "formData"
new: "header"
Parameter type has changed at #/paths/'/pet/{petId}/uploadImage'/post/parameters/1/type
original: "string"
new: "integer"
...
Breaking changes detected in new swagger schema

```

Installation
------------

[](#installation)

### Docker

[](#docker)

```
docker run -v $(pwd)/tests/resources:/code  swaggest/api-compat api-compat petstore1.json petstore2.json --verbose
Optional parameter became required at #/paths/'/pet/{petId}'/post/parameters/2/required
Parameter disposition has changed at #/paths/'/pet/{petId}/uploadImage'/post/parameters/1/in
original: "formData"
new: "header"
Parameter type has changed at #/paths/'/pet/{petId}/uploadImage'/post/parameters/1/type
original: "string"
new: "integer"
...

```

### Library

[](#library)

```
git clone https://github.com/swaggest/api-compat.git
```

### Composer

[](#composer)

[Install PHP Composer](https://getcomposer.org/doc/00-intro.md)

```
composer require swaggest/api-compat
```

Library usage
-------------

[](#library-usage)

Create `ApiCompat` object from two values (`original` and `new`).

```
$ac = new ApiCompat($original, $new);
```

On construction `ApiCompat` will check what has changed in new schema and detect breaking changes. After that you can access collected breaking changes with `$ac->getBreakingChanges()`.

Example
-------

[](#example-1)

```
$ac = new ApiCompat(
    json_decode(file_get_contents(__DIR__ . '/../resources/petstore1.json')),
    json_decode(file_get_contents(__DIR__ . '/../resources/petstore2.json'))
);

$breakingChanges = $ac->getBreakingChanges();
$log = '';
foreach ($breakingChanges as $breakingChange) {
    $log .= $breakingChange->message . ' at ' . Path::quoteUrldecode($breakingChange->path) . "\n";
    if ($breakingChange->originalValue) {
        $log .= 'original: ' . json_encode($breakingChange->originalValue, JSON_UNESCAPED_SLASHES) . "\n";
    }
    if ($breakingChange->newValue) {
        $log .= 'new: ' . json_encode($breakingChange->newValue, JSON_UNESCAPED_SLASHES) . "\n";
    }
}
$this->assertNotEmpty($breakingChanges);
$expectedLog =
