Download the PHP package wangzd/laravel-apidoc-generator without Composer
On this page you can find all versions of the php package wangzd/laravel-apidoc-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wangzd/laravel-apidoc-generator
More information about wangzd/laravel-apidoc-generator
Files in wangzd/laravel-apidoc-generator
Package laravel-apidoc-generator
Short Description Generate beautiful API documentation from your Laravel application
License MIT
Homepage https://github.com/MissZhou12345/laravel-apidoc-generator
Informations about the package laravel-apidoc-generator
注意注意注意!!!
https://github.com/mpociot/laravel-apidoc-generator
本项目是在以上项目基础之上修改
tips:继续采用request文件的验证规则作为bodyParameters mpociot/laravel-apidoc-generator已经放弃该做法
修改的清单
- 生成
collection_swagger.json
需要加--swaggerCollection
参数
可以供yapi自动导入
-
request相关的参数都在request验证类中体现,需要继承
Mpociot\ApiDoc\Request\BaseRequest
- 规则校验新增
describe
规则
describe
只对生成文档有效,不作为laravel校验规则
- 如果字段中文名能作为描述:上述规则也可以使用laravel验证类的
attributes()
方法
describe
优先级大于attributes()
方法
- 使用
@responseTransformer
标签 写 response
建议
-
为自己添加一些 Live Templates
- 修改
PHP Class Doc Comment
Laravel API Documentation Generator
Automatically generate your API documentation from your existing Laravel routes. Take a look at the example documentation.
php artisan api:gen --routePrefix="settings/api/*"
Installation
你可以通过vcs的方式安装: 在composer.json
中添加 repositories
属性
然后添加:require-dev
你就可以拉取本项目了
Require this package with composer using the following command:
Using Laravel < 5.5? Go to your config/app.php
and add the service provider:
Using Laravel < 5.4? Use version 1.0! For Laravel 5.4 and up, use 2.0 instead.
Usage
To generate your API documentation, use the api:generate
artisan command.
This command will scan your applications routes for the URIs matching api/v1/*
and will parse these controller methods and form requests. For example:
Available command options:
Option | Description |
---|---|
output |
The output path used for the generated documentation. Default: public/docs |
routePrefix |
The route prefix to use for generation - * can be used as a wildcard |
routes |
The route names to use for generation - Required if no routePrefix is provided |
middleware |
The middlewares to use for generation |
noResponseCalls |
Disable API response calls |
noPostmanCollection |
Disable Postman collection creation |
useMiddlewares |
Use all configured route middlewares (Needed for Laravel 5.3 SubstituteBindings middleware) |
actAsUserId |
The user ID to use for authenticated API response calls |
router |
The router to use, when processing the route files (can be Laravel or Dingo - defaults to Laravel) |
bindings |
List of route bindings that should be replaced when trying to retrieve route results. Syntax format: binding_one,id|binding_two,id |
force |
Force the re-generation of existing/modified API routes |
header |
Custom HTTP headers to add to the example requests. Separate the header name and value with ":". For example: --header="Authorization: CustomToken" |
Publish rule descriptions for customisation or translation.
By default, this package returns the descriptions in english. You can publish the packages language files, to customise and translate the documentation output.
After the files are published you can customise or translate the descriptions in the language you want by renaming the en
folder and editing the files in public/vendor/apidoc/resources/lang
.
How does it work?
This package uses these resources to generate the API documentation:
Controller doc block
This package uses the HTTP controller doc blocks to create a table of contents and show descriptions for your API methods.
Using @resource
in a doc block prior to each controller is useful as it creates a Group within the API documentation for all methods defined in that controller (rather than listing every method in a single list for all your controllers), but using @resource
is not required. The short description after the @resource
should be unique to allow anchor tags to navigate to this section. A longer description can be included below.
Above each method within the controller you wish to include in your API documentation you should have a doc block. This should include a unique short description as the first entry. An optional second entry can be added with further information. Both descriptions will appear in the API documentation in a different format as shown below.
Result:
Form request validation rules
To display a list of valid parameters, your API methods accepts, this package uses Laravels Form Requests Validation.
Result:
Controller method doc block
It is possible to override the results for the response. This will also show the responses for other request methods then GET.
@transformer
With the transformer you can define the transformer that is used for the result of the method. It will try the next parts to get a result if it can find the transformer. The first successfull will be used.
- Check if there is a transformermodel tag to define the model
- Get a model from the modelfactory
- If the parameter is a Eloquent model it will load the first from the database.
- A new instance from the class
@transformercollection
This is the same idea as the @tranformer tag with one different, instead of the return of an item, it will generate the return of a set with two items
@transformermodel
The @transformermodel tag is needed for PHP 5.* to get the model. For PHP 7 is it optional to specify the model that is used for the transformer.
@response
If you expliciet want to specify the result of a function you can set it in the docblock
API responses
If your API route accepts a GET
method, this package tries to call the API route with all middleware disabled to fetch an example API response.
If your API needs an authenticated user, you can use the actAsUserId
option to specify a user ID that will be used for making these API calls:
If you don't want to automatically perform API response calls, use the noResponseCalls
option.
Note: The example API responses work best with seeded data.
Postman collections
The generator automatically creates a Postman collection file, which you can import to use within your Postman App for even simpler API testing and usage.
If you don't want to create a Postman collection, use the --noPostmanCollection
option, when generating the API documentation.
As of Laravel 5.3, the default base URL added to the Postman collection will be that found in your Laravel config/app.php
file. This will likely be http://localhost
. If you wish to change this setting you can directly update the url or link this config value to your environment file to make it more flexible (as shown below):
If you are referring to the environment setting as shown above, then you should ensure that you have updated your .env
file to set the APP_URL value as appropriate. Otherwise the default value (http://yourappdefault.app
) will be used in your Postman collection. Example environment value:
Modify the generated documentation
If you want to modify the content of your generated documentation, go ahead and edit the generated index.md
file.
The default location of this file is: public/docs/source/index.md
.
After editing the markdown file, use the api:update
command to rebuild your documentation as a static HTML file.
As an optional parameter, you can use --location
to tell the update command where your documentation can be found.
Skip single routes
If you want to skip a single route from a list of routes that match a given prefix, you can use the @hideFromAPIDocumentation
tag on the Controller method you do not want to document.
Further modification
This package uses Documentarian to generate the API documentation. If you want to modify the CSS files of your documentation, or simply want to learn more about what is possible, take a look at the Documentarian guide.
License
The Laravel API Documentation Generator is free software licensed under the MIT license.
All versions of laravel-apidoc-generator with dependencies
league/fractal Version ~0.19.2
fzaninotto/faker Version ~1.4
laravel/framework Version ~7.24
mpociot/documentarian Version ~0.4.0
mpociot/reflection-docblock Version ~1.0
ramsey/uuid Version ^3.0