PHPackages                             php-solution/swagger-ui-gen - 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. php-solution/swagger-ui-gen

ActiveComponent[API Development](/categories/api)

php-solution/swagger-ui-gen
===========================

Extra functionality for generate Swagger specification

v4.3.3(6y ago)479.3k↓50%9[3 issues](https://github.com/php-solution/swagger-ui-gen/issues)[2 PRs](https://github.com/php-solution/swagger-ui-gen/pulls)MITPHPPHP ~7.1CI failing

Since Sep 8Pushed 4y ago10 watchersCompare

[ Source](https://github.com/php-solution/swagger-ui-gen)[ Packagist](https://packagist.org/packages/php-solution/swagger-ui-gen)[ RSS](/packages/php-solution-swagger-ui-gen/feed)WikiDiscussions v4 Synced 1mo ago

READMEChangelog (4)Dependencies (14)Versions (55)Used By (0)

Disclaimer
----------

[](#disclaimer)

At now this lib is under development.

SwaggerUIGenerator
==================

[](#swaggeruigenerator)

This lib includes components and Symfony bundle for generate OpenApi specification.

Install
-------

[](#install)

Via Composer

```
$ composer require php-solution/swagger-ui-gen
```

Integration to Project
----------------------

[](#integration-to-project)

1. Copy to web document root [swagger-ui dist files](https://github.com/swagger-api/swagger-ui/tree/master/dist)
2. Copy to /web/assets/swagger

    - index.html
    - swagger-ui.css
    - swagger-ui.js
    - swagger-ui-bundle.js
    - swagger-ui-standalone-preset.js
3. Change on index.html url to swagger openapi specification

```
const ui = SwaggerUIBundle({
    url: "http://localhost/assets/swagger-spec.json",
})

```

Add Symfony Configuration
-------------------------

[](#add-symfony-configuration)

```
swagger_ui_gen:
    options_provider:
        defaults:
            - '%kernel.root_dir%/Resources/swagger-doc/defaults.yml'
        files:
            - '%kernel.root_dir%/Resources/swagger-doc/general.yml'
            - '%kernel.root_dir%/Resources/swagger-doc/tags.yml'
            - '%kernel.root_dir%/Resources/swagger-doc/paths.yml'
            - '%kernel.root_dir%/Resources/swagger-doc/security_def.yml'
            - '%kernel.root_dir%/Resources/swagger-doc/definitions.yml'
        folders:
            - '@ProjectAdminBundle/Resources/config/swagger-doc'
    handlers:
        validator: false
        form: false
        form_validator: false
        serializer: false
        doctrine_orm: false
    naming_strategy_service: 'PhpSolution\SwaggerUIGen\Bundle\ModelHandler\PropertyNaming\UnderscoreNamingStrategy'

```

Generate file with Swagger Specification
----------------------------------------

[](#generate-file-with-swagger-specification)

```
php bin\console swagger-gen:generate-spec --path=./web/assets/swagger-spec.json

```

Examples
--------

[](#examples)

#### Symfony project

[](#symfony-project)

See example of Symfony app files on /examples/project.

#### Debug mode for Symfony

[](#debug-mode-for-symfony)

1. Add route to your general route.yml

```
_swagger_ui_gen:
    resource: '@SwaggerUIGenBundle/Resources/config/routing.yml'
```

2. Add to swagger ui bootstrap html file(index.html):

```

window.onload = function() {
function getUrlParameter(name) {
      name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
      var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
      var results = regex.exec(location.search);
      return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
  }
  const debugDataUrl = getUrlParameter('url');
  const ui = SwaggerUIBundle({
    url: debugDataUrl ? debugDataUrl : "./data.json",

    ...

```

3. Use on browser:

```
http://localhost/path-to-swagger-ui-bootstrap-html.html?url=/swagger-ui-gen/data.json

```

4. See dumped data

```
http://localhost/swagger-ui-gen/dump

```

Example of symfony route specification
--------------------------------------

[](#example-of-symfony-route-specification)

```
sf_route_paths:
  -
    route: 'get_list_of_entity' # symfony route name, required
    tags: ['admin'] # openapi tags, not required, default value: []
    schemes: [] # openapi schemes, not required, default value: []
    response: # use for openapi operation response, not required, default value: []
      status_code: 200 # not required, default value: "default"
      type: 'object' # not required, default value: "object", complex values: ['array', 'object', 'collection']
      mapping:
        type: ['doctrine', 'serializer'] # not required, use all if builders empty
        class: 'Project\AdminBundle\Lib\PaginatedCollection' # required
        serializer_groups: ['list'] # use only for serializer
      properties:
        items: # property name, require
          type: 'collection'
          mapping: {class: 'Project\AdminBundle\Entity\Admin'}
    openapi_params: # not required, default value: []
      get:
        summary: 'Get admin list'
        responses:
