A swagger OpenApi Documentation generator for laravel. This package requires no phpDoc comments
All other swagger packages require you to write phpDoc comments. This package is different. It will generate swagger documentation from your routes and controllers.
SWAGGER_VERSION=2.0
In your projects composer.json
file,add the following "repositories" section:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/niamulhasan/laravel-api-doctor-swagger"
}
]
Example:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
//Here is the section
"repositories": [
{
"type": "vcs",
"url": "https://github.com/niamulhasan/laravel-api-doctor-swagger"
}
],
"require": {
"php": "^7.2.5",
"fideloper/proxy": "^4.0"
},
...
...
}
Set the "minimum-stability": "dev"
in composer.json
Then run the following command to install the package:
composer require niamulhasan/api-doctor-swagger
Add the following line to the providers
array:
NiamulHasan\ApiDoctorSwagger\Providers\ApiDoctorProvider::class,
This will register the package's service provider for your project.
Run the following command to publish the package's config file:
`protected $except = [
'api/*'
];`
add this in your app/Http/Middleware/VerifyCsrfToken.php
For now this package can generate doc only for URL parameters and Request body. It will not generate doc for Query parameters.
To be able to generate doc for Body parameters you must have to use Form Request in your controller method.
In your controller method:
public function filter(CircularFilterRequest $request): array
{
return CircularResource::collection(CircularsService::filter($request->job_type, $request->order_by, $request->order, $request->tags))->toArray($request);
}
In your Form Request:
class CircularFilterRequest extends FormRequest
{
public function rules()
{
return [
'order_by' => 'string|nullable|in:created_at,starting_date,deadline',
'order' => 'string|nullable|in:asc,desc',
'job_type' => 'string|nullable|in:gov,non-gov',
'tags' => 'array|nullable',
];
}
}
A new route will be added to your project. You can access the swagger documentation by visiting the following url:
http://your-project-url/api-docs
And the swagger yaml file will be available at:
http://your-project-url/swagger-yaml-file-generated
This package is being developed for my own projects. I will be adding more features to it as I need them. If you have any suggestions or find any bug please feel free to open an issue or a pull request.