|
| 1 | +Swagger UI Bundle |
| 2 | +================= |
| 3 | + |
| 4 | +## Installation & Usage |
| 5 | + |
| 6 | +Install via Composer: |
| 7 | + |
| 8 | +`$ composer require activelamp/swagger-ui-bundle:0.1.*` |
| 9 | + |
| 10 | +Enable in `app/AppKernel.php`: |
| 11 | + |
| 12 | +```php |
| 13 | +<?php |
| 14 | + |
| 15 | +use Symfony\Component\HttpKernel\Kernel; |
| 16 | +use Symfony\Component\Config\Loader\LoaderInterface; |
| 17 | + |
| 18 | +class AppKernel extends Kernel |
| 19 | +{ |
| 20 | + public function registerBundles() |
| 21 | + { |
| 22 | + $bundles = array( |
| 23 | + ... |
| 24 | + new ActiveLAMP\Bundle\SwaggerUIBundle\ALSwaggerUIBundle(), |
| 25 | + |
| 26 | +``` |
| 27 | +Let it know where to find your API's resource-list JSON: |
| 28 | + |
| 29 | +``` |
| 30 | +# app/config/config.yml |
| 31 | +
|
| 32 | +al_swagger_ui: |
| 33 | + resource_list: http://petstore.swagger.wordnik.com/api/api-docs |
| 34 | +``` |
| 35 | + |
| 36 | +And finally, add the route to `app/config/routing.yml`: |
| 37 | + |
| 38 | +``` |
| 39 | +al_swagger_ui: |
| 40 | + resource: @ALSwaggerUIBundle/Resources/config/routing.yml |
| 41 | + prefix: /docs |
| 42 | +``` |
| 43 | +Done! |
| 44 | + |
| 45 | +The swagger-ui page for your REST API should now be served at |
| 46 | +`http://yourapp.com/docs`. |
| 47 | + |
| 48 | +### `al_swagger_ui -> resource_list` configuration |
| 49 | + |
| 50 | +The `resource_list` option can receive 2 types of values: |
| 51 | + |
| 52 | +1. An absolute URL to an external Swagger resource-list (demoed above). |
| 53 | +2. A route name. |
| 54 | + |
| 55 | +### Serving static JSON files |
| 56 | + |
| 57 | +If you already have a set of Swagger-compliant JSON files, you can configure this bundle to serve them for you in such a way that `swagger-ui` can consume it properly: |
| 58 | + |
| 59 | +1. Place all JSON files inside a directory (doesn't have to be public) |
| 60 | +2. Register the routes: |
| 61 | + |
| 62 | +```yaml |
| 63 | + # app/config/routing.yml |
| 64 | +al_swagger_ui_static_resources: |
| 65 | + resource: @ALSwaggerUI/Resources/config/static_resources_routing.yml |
| 66 | + prefix: /swagger-docs |
| 67 | +``` |
| 68 | +3. Configure the `static_resources` config: |
| 69 | + |
| 70 | +```yaml |
| 71 | +al_swagger_ui: |
| 72 | + static_resources: |
| 73 | + resource_dir: app/Resources/swagger-docs |
| 74 | + resource_list_filename: api-docs.json |
| 75 | + resource_list: al_swagger_ui_static_resource_list |
| 76 | +``` |
| 77 | + |
| 78 | +This will result in a `/swagger-docs` route to return the resource-list, and `/swagger-docs/<resource_name>` to serve API declarations. |
| 79 | + |
| 80 | +Setting `resource_list` to `al_swagger_ui_static_resource_list` will then point `swagger-ui` to the right direction. |
0 commit comments