Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

OpenAPI HttpFoundation Testing – a Laravel Example

This repository demonstrates how to use the OpenAPI HttpFoundation Testing package in a Laravel project.

It uses L5 Swagger to expose an OpenAPI-based documentation through Swagger UI.

Please refer to this blog post for a detailed explanation.


Clone the repository:

$ git clone

Instal the project's dependencies from the root folder:

$ composer install


Start the PHP development server using Laravel's Artisan command:

$ php artisan serve

Swagger UI should now be available at localhost:8000/api/documentation (you might need to replace api-docs.json with api-docs.yaml in the "explore" bar at the top, so it loads the YAML definition instead of the JSON one, that we haven't provided).

There is an example test which you can run:

$ ./vendor/bin/phpunit tests/Feature

This test queries the /api/test endpoint and validates the response against the provided YAML OpenAPI definition.

Now alter that endpoint's behaviour by changing its route in routes/api.php for this one:

Route::get('/test', function (Request $request) {
    return response()->json(['baz' => 'bar']);

Run the test again – it should now fail because the response contains a baz key where foo is expected, as per the OpenAPI definition.