Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Bundles
  4. NelmioApiDocBundle
  5. Areas

Areas

Edit this page

We've already seen that you can configure which routes are documented using nelmio_api_doc.areas:

1
2
3
4
5
nelmio_api_doc:
    areas:
        path_patterns: [ ^/api ]
        host_patterns: [ ^api\. ]
        name_patterns: [ ^api_v1 ]

But in fact, this config option is way more powerful and allows you to split your documentation in several parts.

Configuration

You can define areas which will each generates a different documentation:

1
2
3
4
5
6
7
8
9
10
11
12
nelmio_api_doc:
    areas:
        default:
            path_patterns: [ ^/api ]
            host_patterns: [ ^api\. ]
        internal:
            path_patterns: [ ^/internal ]
        commercial:
            path_patterns: [ ^/commercial ]
        store:
            # Includes routes with names containing 'store'
            name_patterns: [ store ]

Your main documentation is under the default area. It's the one shown when accessing /api/doc.

Then update your routing to be able to access your different documentations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# app/config/routing.yaml
app.swagger_ui:
    path: /api/doc/{area}
    methods: GET
    defaults: { _controller: nelmio_api_doc.controller.swagger_ui, area: default }

# With Redocly UI
# app/config/routing.yaml
#app.redocly:
#    path: /api/doc/{area}
#    methods: GET
#    defaults: { _controller: nelmio_api_doc.controller.redocly, area: default }

# To expose them as JSON
#app.swagger.areas:
#    path: /api/doc/{area}.json
#    methods: GET
#    defaults: { _controller: nelmio_api_doc.controller.swagger }

That's all! You can now access /api/doc/internal, /api/doc/commercial and /api/doc/store.

Use annotations to filter documented routes in each area

You can use the `@Areas` annotation inside your controllers to define your routes' areas.

First, you need to define which areas will use the`@Areas` annotations to filter the routes that should be documented:

1
2
3
4
5
6
nelmio_api_doc:
    areas:
        default:
            path_patterns: [ ^/api ]
        internal:
            with_annotation: true

Then add the annotation before your controller or action:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use Nelmio\Annotations as Nelmio;

/**
 * @Nelmio\Areas({"internal"}) => All actions in this controller are documented under the 'internal' area
 */
class MyController
{
    /**
     * @Nelmio\Areas({"internal"}) => This action is documented under the 'internal' area
     */
    public function index()
    {
       ...
    }
}
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    Online Symfony certification, take it now!

    Online Symfony certification, take it now!

    The life jacket for your team and your project

    The life jacket for your team and your project

    Version:

    Table of Contents

    • Configuration
    • Use annotations to filter documented routes in each area

    Symfony footer

    Avatar of adursun, a Symfony contributor

    Thanks adursun for being a Symfony contributor

    2 commits • 4 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony