Skip to content

Commit 9a16382

Browse files
committed
修正响应体的ref不解析问题
1 parent 52b4138 commit 9a16382

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/parses/ParseApiDetail.php

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected function getMethodAnnotation($refMethod,$refField=""){
176176
if (!empty($refField)){
177177
$handleFields = [$refField];
178178
}else{
179-
$handleFields = ["header","query","param","routeParam","returned","before","after"];
179+
$handleFields = ["header","query","param","routeParam","returned","before","after","responseSuccess","responseError"];
180180
}
181181
foreach ($handleFields as $field) {
182182
if (!empty($annotations[$field])){
@@ -290,36 +290,41 @@ protected function handleApiResponseError($methodAnnotations,$textAnnotations){
290290
$config = $this->config;
291291
$currentApp = $this->currentApp;
292292
$responseErrors = [];
293+
$paramType = "error";
294+
$mergeParams = [];
293295
if (
294296
in_array("NotResponses", $textAnnotations) ||
295297
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'];
319312
}
320-
$data[]=$item;
313+
$mergeParams = Helper::arrayMergeAndUnique("name", $mergeParams,$methodResponseError);
321314
}
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 [];
323328
}
324329

325330

0 commit comments

Comments
 (0)