PHPackages                             byjg/swagger-test - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. byjg/swagger-test

ActiveLibrary[Testing &amp; Quality](/categories/testing)

byjg/swagger-test
=================

A set of tools for testing your REST calls based on the OpenApi specification using PHPUnit. Currently, this library supports the OpenApi specifications 2.0 (formerly swagger) and 3.0.

6.0.0(8mo ago)104429.6k↓24.3%35[10 issues](https://github.com/byjg/php-swagger-test/issues)[4 PRs](https://github.com/byjg/php-swagger-test/pulls)5MITPHPPHP &gt;=8.3 &lt;8.6CI passing

Since May 22Pushed 2w ago3 watchersCompare

[ Source](https://github.com/byjg/php-swagger-test)[ Packagist](https://packagist.org/packages/byjg/swagger-test)[ GitHub Sponsors](https://github.com/byjg)[ RSS](/packages/byjg-swagger-test/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (4)Versions (28)Used By (5)

   sidebar\_key swagger-test   tags    php

 http

 testing

    Swagger Test
============

[](#swagger-test)

A set of tools for testing your REST calls based on the OpenApi specification using PHPUnit. Currently, this library supports the OpenApi specifications `2.0` (formerly swagger), `3.0.x`, and **`3.1.x`**.

[![Sponsor](https://camo.githubusercontent.com/fab14b7f7f475072ada0473f193d6f322561fd4a2958e0cc89910d053347cf27/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d2532336561346161613f6c6f676f3d67697468756273706f6e736f7273266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d306431313137)](https://github.com/sponsors/byjg)[![Build Status](https://github.com/byjg/php-swagger-test/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-swagger-test/actions/workflows/phpunit.yml)[![Opensource ByJG](https://camo.githubusercontent.com/425c1bbccc0f292bf4d20569ae74a6b2e384fd648f1af8911bc61de9a8dcfc0b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f70656e736f757263652d62796a672d737563636573732e737667)](http://opensource.byjg.com)[![GitHub source](https://camo.githubusercontent.com/88e61eb211719144efdd570290a0456b6e13099c2df8d973f1bb43fe33bf0039/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4769746875622d736f757263652d696e666f726d6174696f6e616c3f6c6f676f3d676974687562)](https://github.com/byjg/php-swagger-test/)[![GitHub license](https://camo.githubusercontent.com/7ebb861cab4df16ee54a53dd1d565b33b9b76aa8496a4194afaf3aa1b2f672ea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f62796a672f7068702d737761676765722d746573742e737667)](https://opensource.byjg.com/opensource/licensing.html)[![GitHub release](https://camo.githubusercontent.com/2fcfb1b5d8e50b98551e969c0a375efb9bf2b901e9c9caa36dd9d8a3075be9f5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f62796a672f7068702d737761676765722d746573742e737667)](https://github.com/byjg/php-swagger-test/releases/)

OpenAPI Version Support
-----------------------

[](#openapi-version-support)

- **Swagger 2.0** - Full support
- **OpenAPI 3.0.x** - Full support (3.0.0, 3.0.1, 3.0.2, 3.0.3)
- **OpenAPI 3.1.x** - Full support with JSON Schema 2020-12 features ✨

### OpenAPI 3.1 Features

[](#openapi-31-features)

OpenAPI 3.1 brings full JSON Schema 2020-12 compatibility. Key features supported:

- **Nullable Types**: Use JSON Schema union types `["string", "null"]` instead of the deprecated `nullable` keyword
- **Webhooks**: Describe and validate incoming HTTP requests your API will receive
- **`const` Keyword**: Validate constant values
- **Conditional Schemas**: Use `if/then/else` for conditional validation
- **Tuple Validation**: Validate arrays with specific types at specific positions using `prefixItems`
- **`$ref` with Sibling Keywords**: References can have additional properties alongside them

For detailed documentation on OpenAPI 3.1 features, see [OpenAPI 3.1 Features Guide](docs/openapi-3.1-features.md).

### Limitations

[](#limitations)

Some features of the OpenAPI specification are not fully implemented:

- Callbacks (OpenAPI 3.0/3.1)
- Links (OpenAPI 3.0/3.1)
- References to external documents/objects
- Some advanced JSON Schema 2020-12 keywords (e.g., `unevaluatedProperties`, `dependentSchemas`)

For details on the schema classes and their specific features, see [Schema Classes](docs/schema-classes.md).

PHP Swagger Test can help you to test your REST API. You can use this tool both for Unit Tests or Functional Tests.

This tool reads an OpenAPI/Swagger specification in JSON format (not YAML) and enables you to test the request and response. You can use the tool "" for creating the JSON file when you are developing your REST API.

The ApiTestCase's assertion process is based on throwing exceptions if some validation or test failed.

Documentation
-------------

[](#documentation)

- [Functional test cases](docs/functional-tests.md) - Testing your API with HTTP requests
- [Contract test cases](docs/contract-tests.md) - Testing without HTTP using custom requesters
- [Runtime parameters validator](docs/runtime-parameters-validator.md) - Validating requests in production
- [Mocking Requests](docs/mock-requests.md) - Testing with mocked responses
- [Schema classes](docs/schema-classes.md) - Working with OpenAPI 2.0, 3.0, and 3.1 schemas
- [OpenAPI 3.1 features](docs/openapi-3.1-features.md) - Webhooks, const, if/then/else, tuple validation, and more
- [Using the OpenApiValidation trait](docs/trait-usage.md) - Flexible validation without extending ApiTestCase
- [Advanced usage](docs/advanced-usage.md) - File uploads, custom clients, authentication, and more
- [Exception handling](docs/exceptions.md) - Understanding and handling validation exceptions
- [Migration guide](docs/migration-guide.md) - Upgrading from older versions
- [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
- [Version comparison](docs/version-comparison.md) - Feature support matrix across OpenAPI versions

Who is using this library?
--------------------------

[](#who-is-using-this-library)

- [ByJG Gluo — PHP REST API starter](https://github.com/byjg/php-gluo)
- [ByJG Gluo for Laravel — contract testing and runtime validation inside a Laravel app](https://github.com/byjg/php-gluo-laravel)
- [Laravel Swagger Test](https://github.com/pionl/laravel-swagger-test)

Install
-------

[](#install)

```
composer require "byjg/swagger-test"
```

Tests
-----

[](#tests)

```
SPEC=swagger php -S 127.0.0.1:8080 tests/rest/app.php &
SPEC=openapi php -S 127.0.0.1:8081 tests/rest/app.php &
vendor/bin/phpunit
```

References
----------

[](#references)

This project uses the [byjg/webrequest](https://github.com/byjg/webrequest) component. It implements the PSR-7 specification, and a HttpClient / MockClient to do the requests. Check it out to get more information.

Questions?
----------

[](#questions)

Please raise your issue on [Github issue](https://github.com/byjg/php-swagger-test/issues).

Dependencies
------------

[](#dependencies)

 ```
flowchart TD
    byjg/swagger-test --> byjg/webrequest
```

      Loading ---

[Open source ByJG](http://opensource.byjg.com)

###  Health Score

67

—

FairBetter than 99% of packages

Maintenance78

Regular maintenance activity

Popularity52

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 80.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~122 days

Recently: every ~155 days

Total

27

Last Release

181d ago

Major Versions

1.2.5 → 2.0.02019-10-21

2.0.1 → 3.0.02020-04-02

3.1.4 → 4.9.02023-05-21

4.9.2 → 5.0.02024-10-27

5.0.x-dev → 6.0.02025-11-25

PHP version history (4 changes)1.2.4PHP &gt;=5.6

4.9.1PHP &gt;=7.4

5.0.0PHP &gt;=8.1 &lt;8.4

6.0.0PHP &gt;=8.3 &lt;8.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/981924?v=4)[Joao Gilberto Magalhaes](/maintainers/byjg)[@byjg](https://github.com/byjg)

---

Top Contributors

[![byjg](https://avatars.githubusercontent.com/u/981924?v=4)](https://github.com/byjg "byjg (228 commits)")[![UlrichEckhardt](https://avatars.githubusercontent.com/u/8566055?v=4)](https://github.com/UlrichEckhardt "UlrichEckhardt (14 commits)")[![vitormattos](https://avatars.githubusercontent.com/u/1079143?v=4)](https://github.com/vitormattos "vitormattos (14 commits)")[![malinink](https://avatars.githubusercontent.com/u/5726553?v=4)](https://github.com/malinink "malinink (4 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (4 commits)")[![Hordev](https://avatars.githubusercontent.com/u/66357476?v=4)](https://github.com/Hordev "Hordev (3 commits)")[![ODAEL](https://avatars.githubusercontent.com/u/4458995?v=4)](https://github.com/ODAEL "ODAEL (3 commits)")[![antonio-rylke-vgl](https://avatars.githubusercontent.com/u/28530190?v=4)](https://github.com/antonio-rylke-vgl "antonio-rylke-vgl (3 commits)")[![domingojimenez](https://avatars.githubusercontent.com/u/113131435?v=4)](https://github.com/domingojimenez "domingojimenez (2 commits)")[![gustavoporcides](https://avatars.githubusercontent.com/u/48253490?v=4)](https://github.com/gustavoporcides "gustavoporcides (1 commits)")[![artjomsimon](https://avatars.githubusercontent.com/u/2609170?v=4)](https://github.com/artjomsimon "artjomsimon (1 commits)")[![BendeRsay](https://avatars.githubusercontent.com/u/8289955?v=4)](https://github.com/BendeRsay "BendeRsay (1 commits)")[![Fantom409](https://avatars.githubusercontent.com/u/14968877?v=4)](https://github.com/Fantom409 "Fantom409 (1 commits)")[![89409](https://avatars.githubusercontent.com/u/84925319?v=4)](https://github.com/89409 "89409 (1 commits)")[![steveplevno](https://avatars.githubusercontent.com/u/57771690?v=4)](https://github.com/steveplevno "steveplevno (1 commits)")[![thePanz](https://avatars.githubusercontent.com/u/226021?v=4)](https://github.com/thePanz "thePanz (1 commits)")

---

Tags

hacktoberfestphpphpunitswagger

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/byjg-swagger-test/health.svg)

```
[![Health](https://phpackages.com/badges/byjg-swagger-test/health.svg)](https://phpackages.com/packages/byjg-swagger-test)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
