PHPackages                             epfremme/swagger-bundle - 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. epfremme/swagger-bundle

ActiveSymfony-bundle[API Development](/categories/api)

epfremme/swagger-bundle
=======================

Symfony 2 bundle for leveraging swagger library test/mock API contracts

v1.0.2(10y ago)05.4k1[2 issues](https://github.com/epfremmer/swagger-bundle/issues)NerderyPHPPHP &gt;=5.5

Since Jul 2Pushed 9y ago1 watchersCompare

[ Source](https://github.com/epfremmer/swagger-bundle)[ Packagist](https://packagist.org/packages/epfremme/swagger-bundle)[ RSS](/packages/epfremme-swagger-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (11)Used By (0)

Swagger Bundle
==============

[](#swagger-bundle)

Symfony 2 bundle for leveraging swagger development &amp; testing tools

Installation
============

[](#installation)

- Require package `composer require epfremme/swagger-bundle`
- Install packages `composer install`

Note: This bundle should only be used in dev mode and be included as a dev only dependency. The purpose of these resources are to assist the creation of an API symfony application during development

Usage
=====

[](#usage)

There are 2 main bundle parameters to you can override in your parameters.yml:

1. `swagger_bundle.swagger_file` default: Resources/docs/swagger.yaml - specify swagger file
2. `swagger_bundle.mock_api` default: true - turn on/off to deactivate the mock API listener

More deatils on each below...

Behat Usage
===========

[](#behat-usage)

Behat documentation: [behat](http://docs.behat.org/en/master/)

- Add the SwaggerContext file to your behat.yml config suite(s)

Sample Behat Config
-------------------

[](#sample-behat-config)

Sample Behat configuration using the SwaggerContext for validating json schemas

```
default:
    suites:
        app:
            paths:
                - %paths.base%/src/AppBundle/Tests/Features/
            contexts:
                - Epfremme\SwaggerBundle\Behat\SwaggerContext: ~
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
          sessions:
            default:
              symfony2: ~
    testers:
        rerun_cache: .behat_rerun_cache

```

Context Details
---------------

[](#context-details)

### @Given I have the request payload:

[](#given-i-have-the-request-payload)

Takes in a TableNode for key value pairs to be used as request payload

Format: | key | value |

### @When I request :path

[](#when-i-request-path)

### @When I request :path with method :method

[](#when-i-request-path-with-method-method)

Make a request to the API with or without a request method (defaults to GET)

### @When I use the :schema schema

[](#when-i-use-the-schema-schema)

### @When I am using the :schema schema

[](#when-i-am-using-the-schema-schema)

Store a swagger definition schema from your swagger doc to be used to validate API json response data

Note: The swagger documentation used is the file defined in the `swagger_bundle.swagger_file` parameter

### @When I test swagger path :path

[](#when-i-test-swagger-path-path)

### @When I test swagger path :path with operation :operation

[](#when-i-test-swagger-path-path-with-operation-operation)

### @When I test swagger path :path with operation :operation and response :response

[](#when-i-test-swagger-path-path-with-operation-operation-and-response-response)

Store a swagger response schema from your swagger doc to be used to validate API json response data

Note: The swagger documentation used is the file defined in the `swagger_bundle.swagger_file` parameter

### @Then the response should be json

[](#then-the-response-should-be-json)

Assert the the response is json

### @Then the response json should contain key :key

[](#then-the-response-json-should-contain-key-key)

Assert that the response json contains "key"

### @Then the response json key :key should equal :value

[](#then-the-response-json-key-key-should-equal-value)

Assert the response json key equals "value"

### @Then The json response data should be valid

[](#then-the-json-response-data-should-be-valid)

### @Then The json response key :key should be valid

[](#then-the-json-response-key-key-should-be-valid)

Validates the response data agains the previously specified swagger definition or response schema

Mock API Usage
==============

[](#mock-api-usage)

The mock API can be disabled by setting `swagger_bundle.mock_api` to false. Also note the listener will not run in prod mode if you forget to move it to require-dev or added it to the wrong are of your kernel

1. Install `app/console swagger:install:mock-api`
2. Add the `x-mock-api` header to the request to trigger the listener to trigger the mock response

### Resources

[](#resources)

A useful chrome extension used to mock request headers [Modheader](https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj)

Additional chance methods &amp; options that can be defined in the swagger.json doc [chance](http://chancejs.com/)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~34 days

Recently: every ~75 days

Total

10

Last Release

3668d ago

Major Versions

v0.1.6 → v1.0.02016-02-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/676986caba2c215a2d21d09ec73a55fccbe180f9d9c511fc0d1753f2bfd05461?d=identicon)[epfremmer](/maintainers/epfremmer)

---

Top Contributors

[![epfremmer](https://avatars.githubusercontent.com/u/1810965?v=4)](https://github.com/epfremmer "epfremmer (6 commits)")[![natebrunette](https://avatars.githubusercontent.com/u/1831497?v=4)](https://github.com/natebrunette "natebrunette (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/epfremme-swagger-bundle/health.svg)

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

###  Alternatives

[drupal/drupal-extension

Drupal extension for Behat

22215.1M147](/packages/drupal-drupal-extension)[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2021.0M277](/packages/drupal-core-dev)[tomaj/nette-api

Nette api

36261.8k4](/packages/tomaj-nette-api)[polishsymfonycommunity/symfony2-mocker-extension

Behat extension for mocking services defined in the Symfony2 dependency injection container.

26253.1k4](/packages/polishsymfonycommunity-symfony2-mocker-extension)

PHPackages © 2026

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