@@ -61,17 +61,25 @@ public function parseApiMethod($refClass,$refMethod,$currentAppData = null){
6161
6262 }
6363 if (empty ($ refMethod ->name )) {
64- return [];
64+ return false ;
65+ }
66+ if (!empty ($ config ['ignored_methods ' ]) && in_array ($ refMethod ->name , $ config ['ignored_methods ' ])){
67+ return false ;
6568 }
6669 $ classTextAnnotations = ParseAnnotation::parseTextAnnotation ($ refClass );
6770 $ classAnnotations = (new ParseAnnotation ($ config ))->getClassAnnotation ($ refClass );
6871
6972 $ textAnnotations = ParseAnnotation::parseTextAnnotation ($ refMethod );
7073 // 标注不解析的方法
7174 if (in_array ("NotParse " , $ textAnnotations )) {
72- return [] ;
75+ return false ;
7376 }
7477 $ methodAnnotations = $ this ->getMethodAnnotation ($ refMethod );
78+
79+ // 标注不解析的方法
80+ if (isset ($ methodAnnotations ['notParse ' ]) || empty ($ methodAnnotations )) {
81+ return false ;
82+ }
7583 $ methodAnnotations = self ::handleApiBaseInfo ($ methodAnnotations ,$ refClass ->name ,$ refMethod ->name ,$ textAnnotations ,$ config );
7684 // 是否开启debug
7785 if (
@@ -137,6 +145,25 @@ public function parseApiMethod($refClass,$refMethod,$currentAppData = null){
137145 $ methodAnnotations ['param ' ] = $ this ->mergeGlobalOrAppParams ($ params ,'body ' );
138146 }
139147
148+ // 合并全局响应状态码
149+ if (
150+ !in_array ("NotResponsesStatus " , $ textAnnotations ) &&
151+ !isset ($ methodAnnotations ['notResponsesStatus ' ])
152+ )
153+ {
154+ $ globalResponseStatus = [];
155+ if (!empty ($ config ['responses_status ' ])){
156+ $ globalResponseStatus = $ config ['responses_status ' ];
157+ }else if (!empty ($ this ->currentApp ['responses_status ' ])){
158+ $ globalResponseStatus = $ this ->currentApp ['responses_status ' ];
159+ }
160+ if (count ($ globalResponseStatus )>0 ){
161+ $ responseStatus = !empty ($ methodAnnotations ['responseStatus ' ])?$ methodAnnotations ['responseStatus ' ]:[];
162+ $ methodAnnotations ['responseStatus ' ] = Helper::arrayMergeAndUnique ("name " , $ globalResponseStatus ,$ responseStatus );
163+ }
164+
165+ }
166+
140167 //添加成功响应体
141168 $ methodAnnotations ['responseSuccess ' ] = $ this ->handleApiResponseSuccess ($ methodAnnotations ,$ textAnnotations );
142169 //添加异常响应体
@@ -195,7 +222,7 @@ protected function getMethodAnnotation($refMethod,$refField=""){
195222 if (!empty ($ refField )){
196223 $ handleFields = [$ refField ];
197224 }else {
198- $ handleFields = ["header " ,"query " ,"param " ,"routeParam " ,"returned " ,"before " ,"after " ,"responseSuccess " ,"responseError " ];
225+ $ handleFields = ["header " ,"query " ,"param " ,"routeParam " ,"returned " ,"before " ,"after " ,"responseSuccess " ,"responseError " , " responseStatus " ];
199226 }
200227 foreach ($ handleFields as $ field ) {
201228 if (!empty ($ annotations [$ field ])){
@@ -262,8 +289,8 @@ protected function handleApiResponseSuccess($methodAnnotations,$textAnnotations)
262289 $ paramType ='success ' ;
263290 if (
264291 in_array ("NotResponses " , $ textAnnotations ) ||
265- in_array ("NotResponseSuccess " , $ textAnnotations ) ||
266- isset ($ methodAnnotations ['notResponses ' ]) ||
292+ in_array ("NotResponseSuccess " , $ textAnnotations ) ||
293+ isset ($ methodAnnotations ['notResponses ' ]) ||
267294 isset ($ methodAnnotations ['notResponseSuccess ' ])
268295 ) {
269296 // 注解了不使用全局响应
@@ -325,8 +352,8 @@ protected function handleApiResponseError($methodAnnotations,$textAnnotations){
325352 $ mergeParams = [];
326353 if (
327354 in_array ("NotResponses " , $ textAnnotations ) ||
328- in_array ("NotResponseError " , $ textAnnotations ) ||
329- isset ($ methodAnnotations ['notResponses ' ]) ||
355+ in_array ("NotResponseError " , $ textAnnotations ) ||
356+ isset ($ methodAnnotations ['notResponses ' ]) ||
330357 isset ($ methodAnnotations ['notResponseError ' ])
331358 ) {
332359 // 注解了不使用全局响应
@@ -363,6 +390,10 @@ protected function handleApiResponseError($methodAnnotations,$textAnnotations){
363390
364391
365392 public static function handleApiBaseInfo ($ methodInfo ,$ className ,$ methodName ,$ textAnnotations ,$ config ){
393+ // 是否存在apidoc的注解
394+ if (empty ($ methodInfo )) {
395+ return false ;
396+ }
366397 // 无标题,且有文本注释
367398 if (empty ($ methodInfo ['title ' ]) && !empty ($ textAnnotations ) && count ($ textAnnotations ) > 0 ) {
368399 $ methodInfo ['title ' ] = Lang::getLang ($ textAnnotations [0 ]);
@@ -380,8 +411,8 @@ public static function handleApiBaseInfo($methodInfo,$className,$methodName,$tex
380411
381412 // 默认default_author
382413 if (
383- empty ($ methodInfo ['author ' ]) &&
384- !empty ($ config ['default_author ' ]) &&
414+ empty ($ methodInfo ['author ' ]) &&
415+ !empty ($ config ['default_author ' ]) &&
385416 !in_array ("NotDefaultAuthor " , $ textAnnotations ) &&
386417 !isset ($ methodInfo ['notDefaultAuthor ' ])
387418 ) {
@@ -668,8 +699,8 @@ public function handleRefData($annotation,$refParams, string $field): array
668699// }
669700 return $ refParams ;
670701 }
671-
672-
702+
703+
673704
674705
675706
@@ -754,4 +785,4 @@ public static function filterParamsField(array $data, $fields, string $type = "f
754785
755786
756787
757- }
788+ }
0 commit comments