All Projects → mtrajano → Laravel Swagger

mtrajano / Laravel Swagger

Auto generates the swagger documentation of a laravel project based on best practices and simple assumptions

Projects that are alternatives of or similar to Laravel Swagger

L5 Swagger
OpenApi or Swagger integration to Laravel
Stars: ✭ 1,781 (+1280.62%)
Mutual labels:  swagger, laravel, laravel-5-package
Laravel Tournaments
Laravel Package that allows you to generate customizable tournaments trees.
Stars: ✭ 196 (+51.94%)
Mutual labels:  laravel, laravel-5-package, generator
Swagger Express Ts
Generate and serve swagger.json
Stars: ✭ 102 (-20.93%)
Mutual labels:  swagger, swagger2
Llum
Llum (light in catalan language) illuminates your Laravel projects speeding up your Github/Laravel development workflow
Stars: ✭ 107 (-17.05%)
Mutual labels:  laravel, laravel-5-package
Vuejs2 Laravel53 Starter
A starter template for VueJs 2.0 with Laravel 5.4
Stars: ✭ 112 (-13.18%)
Mutual labels:  laravel, laravel-5-package
Laravel Single Session
This package prevents a User from being logged in more than once. It destroys the previous session when a User logs in and thereby allowing only one session per user.
Stars: ✭ 95 (-26.36%)
Mutual labels:  laravel, laravel-5-package
Node Typescript Mongodb
node js typescript mongodb express generator yo
Stars: ✭ 96 (-25.58%)
Mutual labels:  swagger, generator
Cray
A Laravel package to help you generate nearly complete CRUD pages like crazy!
Stars: ✭ 108 (-16.28%)
Mutual labels:  laravel, generator
Artify
The Missing Laravel Commands
Stars: ✭ 89 (-31.01%)
Mutual labels:  laravel, laravel-5-package
Pagination
🎁 Laravel 5 Custom Pagination Presenter
Stars: ✭ 119 (-7.75%)
Mutual labels:  laravel, laravel-5-package
Facebook
📨 Facebook Notifications Channel for Laravel
Stars: ✭ 120 (-6.98%)
Mutual labels:  laravel, laravel-5-package
Swagger Merger
🔗 Merge multiple swagger files into a swagger file, support JSON/YAML.
Stars: ✭ 94 (-27.13%)
Mutual labels:  swagger, swagger2
Flysystem Upyun
Laravel 又拍云文件存储,上传,删除。
Stars: ✭ 92 (-28.68%)
Mutual labels:  laravel, laravel-5-package
Laravel Table
Generate tables from Eloquent models.
Stars: ✭ 101 (-21.71%)
Mutual labels:  laravel, generator
Api Client Generator
Angular REST API client generator from Swagger YAML or JSON file with camel case settigs
Stars: ✭ 92 (-28.68%)
Mutual labels:  swagger, generator
Laravel Excel
🚀 Supercharged Excel exports and imports in Laravel
Stars: ✭ 10,417 (+7975.19%)
Mutual labels:  laravel, laravel-5-package
Wizard
Wizard是一款开源的文档管理工具,支持Markdown/Swagger/Table类型的文档。
Stars: ✭ 1,733 (+1243.41%)
Mutual labels:  swagger, laravel
Django Rest Swagger Docs
Beginners approach to Django Rest Swagger
Stars: ✭ 86 (-33.33%)
Mutual labels:  swagger, swagger2
Laravel Enum
Simple, extensible and powerful enumeration implementation for Laravel.
Stars: ✭ 1,278 (+890.7%)
Mutual labels:  laravel, laravel-5-package
Eye
Eyewitness.io package for Laravel 5 applications
Stars: ✭ 114 (-11.63%)
Mutual labels:  laravel, laravel-5-package

Laravel Swagger

Please note this package is deprecated and is no longer being maintained. For the time being I will accept bug fix prs but will try to avoid adding any large features to it. If you are interested in taking over the project please shoot me an email and we can work it out.

Laravel Swagger scans your Laravel project's endpoints and auto generates a Swagger 2.0 documentation for you.

Build Status Latest Stable Version License

About

Laravel Swagger works based on recommended practices by Laravel. It will parse your routes and generate a path object for each one. If you inject Form Request classes in your controller's actions as request validation, it will also generate the parameters for each request that has them. For the parameters, it will take into account wether the request is a GET/HEAD/DELETE or a POST/PUT/PATCH request and make its best guess as to the type of parameter object it should generate. It will also generate the path parameters if your route contains them. Finally, this package will also scan any documentation you have in your action methods and add it as summary and description to that path, along with any appropriate annotations such as @deprecated.

One thing to note is this library leans on being explicit. It will choose to include keys even if they have a default. For example it chooses to say a route has a deprecated value of false rather than leaving it out. I believe this makes reading the documentation easier by not leaving important information out. The file can be easily cleaned up afterwards if the user chooses to leave out the defaults.

Installation

The package can easily be installed by running composer require mtrajano/laravel-swagger in your project's root folder.

If you are running a version of Laravel < 5.5 also make sure you add Mtrajano\LaravelSwagger\SwaggerServiceProvider::class to the providers array in config/app.php.

This will register the artisan command that will be available to you.

You can also override the default config provided by the application by running php artisan vendor:publish --provider "Mtrajano\LaravelSwagger\SwaggerServiceProvider" in your projects root and change the configuration in the new config/laravel-swagger.php file created.

Usage

Generating the swagger documentation is easy, simply run php artisan laravel-swagger:generate in your project root. Keep in mind the command will simply print out the output in your console. If you want the docs saved in a file you can reroute the output like so: php artisan laravel-swagger:generate > swagger.json

If you wish to generate docs for a subset of your routes, you can pass a filter using --filter, for example: php artisan laravel-swagger:generate --filter="/api"

By default, laravel-swagger prints out the documentation in json format, if you want it in YAML format you can override the format using the --format flag. Make sure to have the yaml extension installed if you choose to do so.

Format options are:
json
yaml

Example

Say you have a route /api/users/{id} that maps to [email protected]

Your sample controller might look like this:

/**
 * Return all the details of a user
 *
 * Returns the user's first name, last name and address
 * Please see the documentation [here](https://example.com/users) for more information
 *
 * @deprecated
 */
class UserController extends Controller
{
    public function show(UserShowRequest $request, $id)
    {
        return User::find($id);
    }
}

And the FormRequest class might look like this:

class UserShowRequest extends FormRequest
{
    public function rules()
    {
        return [
            'fields' => 'array'
            'show_relationships' => 'boolean|required'
        ];
    }
}

Running php artisan laravel-swagger:generate > swagger.json will generate the following file:

{
    "swagger": "2.0",
    "info": {
        "title": "Laravel",
        "description": "Test",
        "version": "1.0.1"
    },
    "host": "http:\/\/localhost",
    "basePath": "\/",
    "paths": {
        "\/api\/user\/{id}": {
            "get": {
                "summary": "Return all the details of a user",
                "description": "Returns the user's first name, last name and address
 Please see the documentation [here](https://example.com/users) for more information",
                "deprecated": true
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                },
                "parameters": [
                    {
                        "in": "path",
                        "name": "id",
                        "type": "integer",
                        "required": true,
                        "description": ""
                    },
                    {
                        "in": "query",
                        "name": "fields",
                        "type": "array",
                        "required": false,
                        "description": ""
                    },
                    {
                        "in": "query",
                        "name": "show_relationships",
                        "type": "boolean",
                        "required": true,
                        "description": ""
                    }
                ]
            },
            ...
        }
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].