-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapi_docs.php
140 lines (127 loc) · 4.58 KB
/
api_docs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
declare(strict_types=1);
use Hyperf\ApiDocs\DTO\GlobalResponse;
use function Hyperf\Support\env;
return [
/*
|--------------------------------------------------------------------------
| 启动 swagger 服务
|--------------------------------------------------------------------------
|
| false 将不会启动 swagger 服务
|
*/
'enable' => env('APP_ENV') !== 'prod',
/*
|--------------------------------------------------------------------------
| 生成swagger文件格式
|--------------------------------------------------------------------------
|
| 支持json和yaml
|
*/
'format' => 'json',
/*
|--------------------------------------------------------------------------
| 生成swagger文件路径
|--------------------------------------------------------------------------
*/
'output_dir' => BASE_PATH . '/runtime/container',
/*
|--------------------------------------------------------------------------
| 生成代理类路径
|--------------------------------------------------------------------------
*/
'proxy_dir' => BASE_PATH . '/runtime/container/proxy',
/*
|--------------------------------------------------------------------------
| 设置路由前缀
|--------------------------------------------------------------------------
*/
'prefix_url' => env('API_DOCS_PREFIX_URL', '/swagger'),
/*
|--------------------------------------------------------------------------
| 设置swagger资源路径,cdn资源
|--------------------------------------------------------------------------
*/
'prefix_swagger_resources' => 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.5.0',
/*
|--------------------------------------------------------------------------
| 设置全局返回的代理类
|--------------------------------------------------------------------------
|
| 全局返回 如:[code=>200,data=>null] 格式,设置会后会全局生成对应文档
| 配合ApiVariable注解使用,示例参考GlobalResponse类
| 返回数据格式可以利用AOP统一返回
|
*/
// 'global_return_responses_class' => GlobalResponse::class,
/*
|--------------------------------------------------------------------------
| 替换验证属性
|--------------------------------------------------------------------------
|
| 通过获取注解ApiModelProperty的值,来提供数据验证的提示信息
|
*/
'validation_custom_attributes' => true,
/*
|--------------------------------------------------------------------------
| 设置DTO类默认值等级
|--------------------------------------------------------------------------
|
| 设置:0 默认(不设置默认值)
| 设置:1 简单类型会为设置默认值,复杂类型(带?)会设置null
| - 简单类型默认值: int:0 float:0 string:'' bool:false array:[] mixed:null
| 设置:2 (慎用)包含等级1且复杂类型(联合类型除外)会设置null
|
*/
'dto_default_value_level' => 0,
/*
|--------------------------------------------------------------------------
| 全局responses,映射到ApiResponse注解对象
|--------------------------------------------------------------------------
*/
'responses' => [
['response' => 401, 'description' => 'Unauthorized'],
['response' => 500, 'description' => 'System error'],
],
/*
|--------------------------------------------------------------------------
| swagger 的基础配置
|--------------------------------------------------------------------------
|
| 该属性会映射到OpenAPI对象
|
*/
'swagger' => [
'info' => [
'title' => 'API DOC',
'version' => '0.1',
'description' => 'swagger api desc',
],
'servers' => [
[
'url' => 'http://127.0.0.1:9501',
'description' => 'OpenApi host',
],
],
'components' => [
'securitySchemes' => [
[
'securityScheme' => 'Authorization',
'type' => 'apiKey',
'in' => 'header',
'name' => 'Authorization',
],
],
],
'security' => [
['Authorization' => []],
],
'externalDocs' => [
'description' => 'Find out more about Swagger',
'url' => 'https://github.com/tw2066/api-docs',
],
],
];