在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mtrajano/laravel-swagger开源软件地址(OpenSource Url):https://github.com/mtrajano/laravel-swagger开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel SwaggerPlease 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. AboutLaravel 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. InstallationThe package can easily be installed by running If you are running a version of Laravel < 5.5 also make sure you add 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 UsageGenerating the swagger documentation is easy, simply run If you wish to generate docs for a subset of your routes, you can pass a filter using 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 options are: ExampleSay you have a route 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 {
"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": ""
}
]
},
...
}
}
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论