125 words
1 minutes
Add Documentation to Your Symfony API

Today, we will see how to set up documentation for our API (which you can find in the previous article).

This will be extremely simple thanks to the package NelmioApiDocBundle.

Installation#

To install it:

composer require nelmio/api-doc-bundle

And that’s it! You can now navigate to /api/doc to view your API documentation.

If it doesn’t work, it might be because Twig is not installed. In that case, add it:

composer require twig asset

If it still doesn’t work, you need to declare the route in Symfony:

# config/routes/nelmio_api_doc.yaml
app.swagger_ui:
    path: /api/doc
    methods: GET
    defaults: { _controller: nelmio_api_doc.controller.swagger_ui }

Result#

This should give you:

Swagger UI Documentation

Customizing the Documentation#

If you want to learn more about customizing your API documentation to the fullest, you can check out the format specifications: https://swagger.io/specification/.

Source Code#

You can find the complete source code on GitHub:
https://github.com/gponty/custom-api