PHP code example of bobitluo / php-swagger
1. Go to this page and download the library: Download bobitluo/php-swagger library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bobitluo / php-swagger example snippets
$options = [
'title' => 'API title', // API系统标题
'description' => 'API description', // API系统描述
'version' => '1.0.0', // API版本号
'host' => '{yourhost.com}', // API系统域名
'schemes' => [ // API支持的SCHEME列表
'https',
],
'securityDefinitions' => [ // API支持的认证列表。无需验证时设置为[]。详情见:https://swagger.io/docs/specification/2-0/authentication/
'ApiKeyAuth' => [
'type' => 'apiKey',
'in' => 'header',
'name' => 'Authorization',
],
],
'security' => [ // API默认全局使用的认证定义。无需验证时设置为[]。详情见:https://swagger.io/docs/specification/2-0/authentication/
[
'ApiKeyAuth' => [],
],
],
'controller_prefix' => '', // 控制器类名前缀。默认值为''
'controller_postfix' => '', // 控制器类名后缀。默认值为''
'action_prefix' => '', // Action方法名前缀。默认值为空''
'action_postfix' => '', // Action方法名后缀。默认值为空''
];
\bobitluo\Php\Swagger\Options::getInstance( $options );
$directory = new \bobitluo\Php\Swagger\Directory('{your_controller_dir}', function($uriPath){
return preg_replace('/(\/controllers)$/', '', $uriPath);
});
echo $directory->build();
/**
* @package 用户
*/
class UserController {
/**
* 登录
*
* 支持密码和验证码两种方式登录
*
* @package 用户
* @http-method post
*
* @param string $login_type* 登录类型(password,sms_code) password
* @param int $cellphone* 手机号 13800138000
* @param string $password* 密码 123456
* @param array $options[] 选项数组 10
* @param array $ext[id][] 扩展ID数组
* @param array $ext[name][] 扩展名称数组
*
* @return json 200 成功
*
* 字段解释:
*
* 名称 | 类型 | 示例 | 描述
* ------- | ---- | ---- | ----
* expires | int | 1565796956 | 凭证过期时间戳
* type | string | Bearer | 凭证类型
* token | string | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 登录凭证
*
* 返回样例:
*
*
bash
composer
* @return json 401 认证失败
*/
public function loginAction() {
...