zquintana / lara-swag
Generates documentation for your REST API from annotations
Installs: 2 401
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Language:JavaScript
Type:laravel-package
Requires
- php: ~7.0|~7.1
- exsyst/swagger: ~0.2.3
- indigophp/doctrine-annotation-autoload: ^0.1
- symfony/property-info: ^3.1|^4.0
- zircote/swagger-php: ^2.0.9
Requires (Dev)
- api-platform/core: ^2.0.3
- doctrine/annotations: ^1.2
- friendsofsymfony/rest-bundle: ^2.0
- illuminate/container: >=5.5
- illuminate/routing: >=5.5
- orchestra/testbench: ^3.4
- phpdocumentor/reflection-docblock: ^3.1
- symfony/asset: ^2.8|^3.0|^4.0
- symfony/browser-kit: ^2.8|^3.0|^4.0
- symfony/cache: ^3.1|^4.0
- symfony/config: ^2.8|^3.0|^4.0
- symfony/console: ^2.8|^3.0|^4.0
- symfony/dom-crawler: ^2.8|^3.0|^4.0
- symfony/form: ^3.0.8|^4.0
- symfony/phpunit-bridge: ^3.3
- symfony/property-access: ^2.8|^3.0|^4.0
- symfony/templating: ^2.8|^3.0|^4.0
- symfony/twig-bundle: ^3.0|^4.0
- symfony/validator: ^2.8|^3.0|^4.0
Suggests
- api-platform/core: For using an API oriented framework.
- phpdocumentor/reflection-docblock: For parsing php docs.
This package is auto-updated.
Last update: 2024-11-29 04:20:01 UTC
README
The LaraSwag package allows you to generate a decent documentation for your APIs.
Installation
First, open a command console, enter your project directory and execute the following command to download the latest version of this bundle (still in beta, for a stable version look here):
composer require zquintana/lara-swag dev-master
Then add the service provider to your app config:
ZQuintana\LaraSwag\Provider\LaraSwagProvider::class
To install the vendor assets like configurations and templates run:
$ php artisan vendor:publish --provider="ZQuintana\LaraSwag\Provider\LaraSwagProvider::class"
To browse your documentation with Swagger UI, register the routes in config/routing/lara_swag.php
.
To make this easier after you run the vendor:publish
command you can add
the following to your routes config file:
<?php ... Route::group(['prefix' => 'api'], function () { require_once('lara_swag.php'); // use routes/lara_swag.php if you're using Laravel pre 5.3 });
What does this bundle?
It generates you a swagger documentation from your Laravel app thanks to Describers. Each of these Describers extract infos from various sources. For instance, one extract data from SwaggerPHP annotations, one from your routes, etc.
If you configured the routes above, you can browse your documentation at
http://example.org/api/docs
.
Use the bundle
You can configure globally your documentation in the config (take a look at the Swagger specification to know the fields available):
<?php return [ 'documentation' => [ 'info' => [ 'title' => 'My App', 'description' => 'This is an awesome app!', 'version' => '1.0.0', ] ], ];
To document your routes, you can use annotations in your controllers:
namespace App\Controllers; use App\Models\User; use App\Models\Reward; use ZQuintana\LaraSwag\Annotation\Model; use Swagger\Annotations as SWG; class UserController { /* * @SWG\Response( * response=200, * description="Returns the rewards of an user", * @SWG\Schema( * type="array", * @Model(type=Reward::class, groups={"full"}) * ) * ) * @SWG\Parameter( * name="order", * in="query", * type="string", * description="The field used to order rewards" * ) * @SWG\Tag(name="rewards") */ public function fetchUserRewardsAction(User $user) { // ... } }
What's supported?
This package supports Laravel route requirements, PHP annotations, Swagger-Php annotations.
It supports models through the @Model
annotation.
Contributing
See CONTRIBUTING file.
Running the Tests
Install the Composer dependencies:
git clone https://github.com/zquintana/LaraSwag.git
cd LaraSwag
composer install
Then run the test suite:
./phpunit
License
This bundle is released under the MIT license.