Skip to content

Expose swagger-ui inside your symfony project through a route (eg. /docs).

License

Notifications You must be signed in to change notification settings

Pitoune/swagger-ui-bundle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Code Coverage

Swagger UI Bundle

Expose swagger-ui inside your symfony project through a route (eg. /docs), just like nelmio api docs, without the need for node.

Just add a reference to your swagger Yaml or JSON specification, and enjoy swagger-ui in all it's glory.

After installation and configuration, just start your local webserver, and navigate to /docs or /docs/my_swagger_spec.yml.

Installation

Install with composer in dev environment:

$ composer require harmbandstra/swagger-ui-bundle --dev

Enable bundle in app/AppKernel.php:

<?php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        // ...

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            // ...
            $bundles[] = new HarmBandstra\SwaggerUiBundle\HBSwaggerUiBundle();
        }

        // ...
    }
}

Add the route where swagger-ui will be available in routing_dev.yml:

_swagger-ui:
    resource: '@HBSwaggerUiBundle/Resources/config/routing.yml'
    prefix: /docs

Configuration

In your config.yml, link to the swagger spec.

Specify the directory where your swagger files reside. You can access multiple files through the endpoint like /docs/my_swagger_spec.json. Under files you specify which files should be exposed.

The first file in the array is the default one and it will be the file the /docs endpoint will redirect to. For this file you have the option to specify an absolute path to the .json spec file ("/_swagger/swagger.json") or a URL ("https://example.com/swagger.json").

hb_swagger_ui:
  directory: "%kernel.root_dir%/../docs/"
  files:
    - "/_swagger/swagger.json"
    - "my_swagger_spec.yml"
    - "my_other_swagger_spec.json"

About

Expose swagger-ui inside your symfony project through a route (eg. /docs).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 66.2%
  • HTML 33.8%