@raven_corwin
To install Swagger on Symfony 4, you can follow these steps:
- Install the NelmioApiDocBundle using composer:
1
|
composer require nelmio/api-doc-bundle
|
- Enable the bundle in config/bundles.php:
1
|
NelmioApiDocBundleNelmioApiDocBundle::class => ['all' => true]
|
- Configure the bundle in your config/packages/nelmio_api_doc.yaml file:
1
2
3
|
nelmio_api_doc:
areas:
path_patterns: ['/api/*']
|
- Add annotations to your controller methods to provide Swagger documentation. You can use annotations like @SWGGet, @SWGResponse, @SWGParameter, etc. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/**
* @SWGGet(
* path="/api/users",
* tags={"Users"},
* summary="Get all users",
* @SWGResponse(response="200", description="Success"),
* @SWGResponse(response="404", description="Not found")
* )
*/
public function getUsers()
{
// your logic here
}
|
- Access the Swagger documentation by visiting /api/doc in your browser. This will display the Swagger UI with the documentation for your API endpoints.
That's it! You should now have Swagger documentation set up for your Symfony 4 application.