PHPackages                             jdesrosiers/silex-swagger-provider - 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. jdesrosiers/silex-swagger-provider

AbandonedArchivedLibrary[API Development](/categories/api)

jdesrosiers/silex-swagger-provider
==================================

A silex service provider that integrates swagger-php into silex

v1.2.0(12y ago)2130.2k↓100%10[1 issues](https://github.com/jdesrosiers/silex-swagger-provider/issues)MITPHP

Since Jul 19Pushed 10y ago3 watchersCompare

[ Source](https://github.com/jdesrosiers/silex-swagger-provider)[ Packagist](https://packagist.org/packages/jdesrosiers/silex-swagger-provider)[ RSS](/packages/jdesrosiers-silex-swagger-provider/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (4)Versions (11)Used By (0)

silex-swagger-provider
======================

[](#silex-swagger-provider)

[![Build Status](https://camo.githubusercontent.com/ef5e5fd24e5a66167efc6168324f1059a5d51bfcca1d7fb9e62a67c48236c769/68747470733a2f2f7472617669732d63692e6f72672f6a646573726f73696572732f73696c65782d737761676765722d70726f76696465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jdesrosiers/silex-swagger-provider)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1dc81bc033bd078fe8478ac294371e6960a278fa766e274d505d4fef83bd3859/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a646573726f73696572732f73696c65782d737761676765722d70726f76696465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jdesrosiers/silex-swagger-provider/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/a49ddc32598194cbc0ee7267f393b01275bee870025999fceaff736ebf9b2852/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a646573726f73696572732f73696c65782d737761676765722d70726f76696465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jdesrosiers/silex-swagger-provider/?branch=master)

[silex-swagger-provider](https://github.com/jdesrosiers/silex-swagger-provider) is a silex service provider that integrates [swagger-php](https://github.com/zircote/swagger-php) into [silex](https://github.com/fabpot/Silex). This service provider adds routes for generating and exposing a swagger defintion based on swagger-php annotations. The swagger definition can then be used with [swagger-ui](https://github.com/wordnik/swagger-ui).

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

[](#installation)

Install the silex-swagger-provider using [composer](http://getcomposer.org/). This project uses [sematic versioning](http://semver.org/).

```
{
    "require": {
        "jdesrosiers/silex-swagger-provider": "~1.0"
    }
}
```

Parameters
----------

[](#parameters)

- **swagger.srcDir**: The path to the swagger-php component.
- **swagger.servicePath**: The path to the classes that contain your swagger annotations.
- **swagger.excludePath**: A colon `:` separated list of paths to be excluded when generating annotations.
- **swagger.apiDocPath**: The URI that will be used to access the swagger definition. Defaults to `/api/api-docs`.
- **swagger.prettyPrint**: Determines whether or not the JSON generated will be formatted for human readability.
- **swagger.cache**: An array of caching options that will be passed to Symfony 2's `Response::setCache` method.
- **swagger.basePath**: The url where your API can be found. If your Swagger annotation contains a basePath it will override this value. Eg. "
- **swagger.apiVersion**: The version of your API. If your Swagger annotation contains a version it will override this value.
- **swagger.swaggerVersion**: The Swagger version of your API. If your Swagger annotation contains a swagger version it will override this value.
- **swagger.resourcePrefix**: A prefix string that will be appended for every resource URI. Defaults to "/".
- **swagger.resourceSuffix**: A suffix string that will be appended for every resource URI. Defaults to "".

Services
--------

[](#services)

- **swagger**: An instance of `Swagger\Swagger`. It's used internally to generate the swagger definition. You probably won't need to use it directly.

Registering
-----------

[](#registering)

```
$app->register(new JDesrosiers\Silex\Provider\SwaggerServiceProvider(), array(
    "swagger.srcDir" => __DIR__ . "/vendor/zircote/swagger-php/library",
    "swagger.servicePath" => __DIR__ . "/path/to/your/api",
));
```

Usage
-----

[](#usage)

The following routes are made available by default

- `GET /api/api-docs`: Get the list of resources
- `GET /api/api-docs/{service}`: Get the definition for a specific resource

The results of the swagger definition file is not cached internally. Instead, the routes that are created are designed to work with an HTTP cache such as a browser cache or reverse proxy. You can configure how you want to your service cached using the `swagger.cache` parameter. By default, no caching will be done. Read about [HTTP caching](http://symfony.com/doc/current/book/http_cache.html) in Symfony for more information about how to customize caching behavior. The following example will allow the service definition file to be cached for 5 days.

```
$app["swagger.cache"] = array(
    "max_age": "432000", // 5 days in seconds
    "s_maxage": "432000", // 5 days in seconds
    "public": true,
)
```

Logging
-------

[](#logging)

Swagger uses php notices and warnings to log issues it encounters when trying to generate your API documentation. If your silex application has a `logger` service, it will log those issues as well.

Getting Started
---------------

[](#getting-started)

The following is a minimal example to get you started quickly. It uses the [jdesrosiers/silex-cors-provider](https://github.com/jdesrosiers/silex-cors-provider)to allow us to use the demo installation of swagger-ui so we don't have to stand up our own. See the [swagger-php documentation](http://zircote.com/swagger-php/) for details on how to expand on this example.

- Create a composer.json with at minimum, the following dependecies

```
{
    "require": {
        "jdesrosiers/silex-swagger-provider": "~1.0",
        "jdesrosiers/silex-cors-provider": "~0.1"
    }
}
```

- Run composer install
- Create /web/index.php

```
