dev-master
9999999-dev
The Requires
- php >=5.4.0
- symfony/yaml 2.5.*
- illuminate/support >=4.0
by Raphael Owino
Edit composer.json
and to require, (*1)
"ralphowino/swagger" : "dev-master"
Edit config/app.php
and "Ralphowino/Swagger/SwaggerServiceProvider"
in providers array, (*2)
To create a new documentation for your api, run:, (*3)
php artisan swagger:init
There are 4 doc types: api, resource, model, operation, (*4)
This doc type allows you to create a standard swagger resource doc type., (*5)
To generate one, use command:, (*6)
php artisan swagger:generate api apiname
This doc type is a summarised version of the standard swagger resource and includes 2 variables: models and operations., (*7)
To generate one, use command:, (*8)
php artisan swagger:generate resource resourcename
You will be requested to specify a list of operations to include, (*9)
This doc type represents a single action/route in your api. To generate one, use command:, (*10)
php artisan swagger:generate operation operationName
You will be requested to specify different details about the action such as Verb, Route, etc, (*11)
This doc type represents a model/custom datatype used in your api. To generate one use command:, (*12)
php artisan swagger:generate model Modelname
You will be asked properties of the model and the required ones, (*13)
We can create a quick documentation for a to-do list api with simple Crud function for todo items., (*14)
php artisan swagger:init
Make sure you have updated your api domain name in config/app.php, (*15)
php artisan swagger:generate model Todo --properties="id:integer, title:string, notes:text, completed:boolean, created_at:datetime, updated_at:datetime, completed_at:datetime, deleted_at:datetime" --required="id,title" php artisan swagger:generate model Item --properties="title:string, notes:text, completed:boolean" --required="title"
1. Create Todo, (*16)
php artisan swagger:generate operation createTodo
General details, (*17)
verb: POST path: todos model: Todo summary: Create a new todo item notes:
Parameter: body, (*18)
parameter: body parameter.description: create a new todo item parameter.location: body parameter.type: iTodo parameter.required: y parameter.multiple: n
2.Get Todo, (*19)
php artisan swagger:generate operation getTodo
General details, (*20)
verb: GET path: todos/{id} model: Todo summary: Get todo item using its id notes: Get a todo item using its id. Define fields to retrieve or none if not changed
Parameter: id, (*21)
parameter: id parameter.description: id of todo item to retrieve parameter.location: path parameter.type: integer parameter.required: y parameter.multiple: n
Parameter: if-match-none, (*22)
parameter: if-match-none parameter.description: return if etag doesn't match parameter.location: header parameter.type: string parameter.required: n parameter.multiple: n
Parameter: fields, (*23)
parameter: fields parameter.description: fields to return (limited to fields available) parameter.location: query parameter.type: string parameter.required: n parameter.multiple: n
3.Get Todos, (*24)
php artisan swagger:generate operation getTodos
To populate the operation enter the following answers:, (*25)
General details, (*26)
verb: GET path: todo model: array type: Todo summary: Get todo items notes: Get a todo items paginated and filtered based on parameters
Parameter: if-match-none, (*27)
parameter: if-match-none parameter.description: return if etag doesn't match parameter.location: header parameter.type: string parameter.required: n parameter.multiple: n
Parameter: id, (*28)
parameter: id parameter.description: filter by ids. Comma separated list allowed parameter.location: query parameter.type: string parameter.required: n parameter.multiple: n
Parameter: fields, (*29)
parameter: fields parameter.description: fields to return (limited to fields available) parameter.location: query parameter.type: string parameter.required: n parameter.multiple: n
Parameter: page, (*30)
parameter: page parameter.description: page to display parameter.location: query parameter.type: integer parameter.required: n parameter.multiple: n
Parameter: per_page, (*31)
parameter: per_page parameter.description: items to display per page parameter.location: query parameter.type: integer parameter.required: n parameter.multiple: n
4.Update Todos, (*32)
php artisan swagger:generate operation updateTodo
General details, (*33)
verb: PUT path: todos/{id} model: Todo summary: Update a todo item based on ID notes:
Parameter: body, (*34)
parameter: body parameter.description: updated fields parameter.location: body parameter.type: iTodo parameter.required: y parameter.multiple: n
5.Delete Todo, (*35)
php artisan swagger:generate operation deleteTodo
General details, (*36)
verb: DELETE path: todos/{id} model: summary: Delete a todo item based on ID notes:
php artisan swagger:generate resource todos operation: gettodos operation: gettodo operation: createtodo operation: updatetodo operation: deletetodo