Search code examples
symfonyswaggersymfony-3.3nelmioapidocbundle

NelmioApiDoc v3 / Swagger - multiple API docs


NelmioApiDoc v2 allowed to use multiple views parameter so I can hide some endpoints and present them on different URL

https://symfony.com/doc/current/bundles/NelmioApiDocBundle/multiple-api-doc.html

Is it possible to do it in NelmioApiDoc v3 which is using Swagger?

I am using Symfony 3.3


Solution

  • What you are looking for seems to be called "Areas" now in NelmioApiDoc v3. Thanks to this feature, you can define areas which will each generates a different documentation :

    You just have to define those areas in your config.yml:

    nelmio_api_doc:
        areas:
            default:
                path_patterns: [ ^/api ]
            custom:
                path_patterns: [ ^/custom ]
            another_custom:
                path_patterns: [ ^/anothercustom ]
    

    Then you need to update your routing.yml file:

    app.swagger_ui:
        path: /api/doc/{area}
        methods: GET
        defaults: { _controller: nelmio_api_doc.controller.swagger_ui, area: default }
    

    You can read about it on this doc.