Download the PHP package timeinc/swagger-bundle without Composer
On this page you can find all versions of the php package timeinc/swagger-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download timeinc/swagger-bundle
More information about timeinc/swagger-bundle
Files in timeinc/swagger-bundle
Package swagger-bundle
Short Description Implementation of swagger-php for Symfony
License MIT
Informations about the package swagger-bundle
SwaggerBundle
This bundle provides integration of swagger-php in Symfony.
It should only run in the dev environment, as searching for annotations at runtime is not performant. The bundle comes
with the ability to generate a swagger.json
file that can be statically served.
Installation
Install via Composer:
Enable Bundle
In your app/AppKernel.php
file, add the following to your list of dev bundles:
Configure Bundle
Application Configuration
Open ./app/config/config_dev.yml
and add your configuration like below.
The full configuration reference for a comprehensive list of all values and defaults.
Routing
The bundle comes with routes to view the default swagger.json
schema or schemas with overridden host, schemes and base_path as defined by your presets. To enable the routes, add the following to your
./app/config/routing_dev.yml
:
You can then access your default schema through /_swagger/swagger.json
or your alternative schemas through /_swagger/swagger-{alternative-host-name}.json
. As noted before, this should not be added to the
production routes.
Usage
Once you have registered your bundles under swagger > bundles
in config_dev.yml
, the swagger-bundle will
automatically search for any swagger-php annotations under:
- [bundle_dir]/Controller
- [bundle_dir]/Document
- [bundle_dir]/Entity
- [bundle_dir]/Form
- [bundle_dir]/Model
- [bundle_dir]/Swagger
Please see swagger-php's annotation reference for details about swagger-php's syntax.
Symfony Routes
This bundle comes with an extra \TimeInc\SwaggerBundle\Swagger\Annotation\Route
annotation that allows you to define
a symfony route as a swagger endpoint. using the annotation will set a swagger path for each method and add parameters
for the path variables and any defaults as query strings.
The annotation can be defined on a class or a method with the following properies:
Property | Context | Default | Notes |
---|---|---|---|
method | CLASS | The method name to inspect | |
route | CLASS|METHOD | The Symfony route to inspect | |
returns | CLASS|METHOD | entity | The response data type (collection|entity) |
entity | CLASS|METHOD | The entity that is returned. If omitted, will be guessed based on controller name | |
queryParams | CLASS|METHOD | [] | Any extra query parameters as Key/Value array of queryParameter/dataType |
headers | CLASS|METHOD | [] | Any extra header parameters as Key/Value array of headerName/dataType |
NOTE: If the entity is omitted, the bundle will search for an entity name of the same name as the controller in the same bundle. For Example, the below example controller is
Acme\PetBundle\Controller\PetController
, so the bundle will search for an entity inAcme\PetBundle\Entity\Pet
Command Line
You can dump the json schema to the console with the swagger:dump
command:
HINT: You can use the option
--alternative-host=product
to override host, schemes and base_path with your production preset
API Gateway
The bundle can also generate a swagger schema for an AWS API Gateway using the HTTP Proxy.
The schema can then be imported into the AWS console to generate a 1-1 route mapping over a HTTP proxy for your API. All parameters and headers and imported into AWS and passed through.
API Gateway
Please see the docs on how to integrate your API with API Gateway.