@@ -176,7 +176,7 @@ protected function getMethodAnnotation($refMethod,$refField=""){
176
176
if (!empty ($ refField )){
177
177
$ handleFields = [$ refField ];
178
178
}else {
179
- $ handleFields = ["header " ,"query " ,"param " ,"routeParam " ,"returned " ,"before " ,"after " ];
179
+ $ handleFields = ["header " ,"query " ,"param " ,"routeParam " ,"returned " ,"before " ,"after " , " responseSuccess " , " responseError " ];
180
180
}
181
181
foreach ($ handleFields as $ field ) {
182
182
if (!empty ($ annotations [$ field ])){
@@ -290,36 +290,41 @@ protected function handleApiResponseError($methodAnnotations,$textAnnotations){
290
290
$ config = $ this ->config ;
291
291
$ currentApp = $ this ->currentApp ;
292
292
$ responseErrors = [];
293
+ $ paramType = "error " ;
294
+ $ mergeParams = [];
293
295
if (
294
296
in_array ("NotResponses " , $ textAnnotations ) ||
295
297
in_array ("NotResponseError " , $ textAnnotations )
296
- ){
297
- $ responseErrors = [];
298
- }else if (!empty ($ methodAnnotations ['responseError ' ]) && count ($ methodAnnotations ['responseError ' ])){
299
- $ responseErrors = $ methodAnnotations ['responseError ' ];
300
- }else if (
301
- !empty ($ currentApp ['responses ' ]) &&
302
- !empty ($ currentApp ['responses ' ]['error ' ]) &&
303
- count ($ currentApp ['responses ' ]['error ' ])
304
- ){
305
- $ responseErrors = $ currentApp ['responses ' ]['error ' ];
306
- }else if (
307
- !empty ($ config ['responses ' ]) &&
308
- !empty ($ config ['responses ' ]['error ' ]) &&
309
- count ($ config ['responses ' ]['error ' ])
310
- ){
311
- $ responseErrors = $ config ['responses ' ]['error ' ];
312
- }
313
-
314
- $ data = [];
315
- foreach ($ responseErrors as $ item ) {
316
- $ item ['desc ' ] = Lang::getLang ($ item ['desc ' ]);
317
- if (!empty ($ item ['md ' ])){
318
- $ item ['md ' ] = ParseMarkdown::getContent ($ this ->appKey ,$ item ['md ' ]);
298
+ ) {
299
+ // 注解了不使用全局响应
300
+ $ mergeParams = [];
301
+ }else if (!empty ($ currentApp ['responses ' ]) && !empty ($ currentApp ['responses ' ][$ paramType ])){
302
+ $ mergeParams = $ currentApp ['params ' ][$ paramType ];
303
+ }else if (!empty ($ config ['responses ' ]) && !empty ($ config ['responses ' ][$ paramType ])){
304
+ $ mergeParams = $ config ['responses ' ][$ paramType ];
305
+ }
306
+
307
+ if (!empty ($ methodAnnotations ['responseError ' ])){
308
+ if (!is_int (array_key_first ($ methodAnnotations ['responseError ' ]))){
309
+ $ methodResponseError = [$ methodAnnotations ['responseError ' ]];
310
+ }else {
311
+ $ methodResponseError = $ methodAnnotations ['responseError ' ];
319
312
}
320
- $ data []= $ item ;
313
+ $ mergeParams = Helper:: arrayMergeAndUnique ( " name " , $ mergeParams , $ methodResponseError ) ;
321
314
}
322
- return $ data ;
315
+
316
+ if (!empty ($ mergeParams ) && count ($ mergeParams )){
317
+ $ resData = [];
318
+ foreach ($ mergeParams as $ item ) {
319
+ $ item ['desc ' ] = Lang::getLang ($ item ['desc ' ]);
320
+ if (!empty ($ item ['md ' ])){
321
+ $ item ['md ' ] = ParseMarkdown::getContent ($ this ->appKey ,$ item ['md ' ]);
322
+ }
323
+ $ resData []=$ item ;
324
+ }
325
+ return $ resData ;
326
+ }
327
+ return [];
323
328
}
324
329
325
330
0 commit comments