Skip to content

Commit 567ea90

Browse files
committed
update v4.1.2
- 新增auto_url.handle_key配置项,用于自定义处理自动生成url的每个key。 - 新增前端显示版本号。 - 新增自定义事件name属性,用于自定义事件名称的显示。 - 新增ResponseSuccessMd注解,用于使用md编写成功响应体。 - 新增ResponseErrorMd注解,用于使用md编写失败响应体。 - 优化markdown的json显示效果。
1 parent 9588c1b commit 567ea90

File tree

9 files changed

+85
-28
lines changed

9 files changed

+85
-28
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
## 🤷‍♀️ Apidoc是什么?
2424

25-
Apidoc是一个通过解析注解生成Api接口文档的PHP composer扩展;
26-
全面的注解引用、数据表字段引用,简单的注解即可生成Api文档,而Apidoc不仅于接口文档,在线接口调试、Mock调试数据、调试事件处理、Json/TypeScript生成、批量测试、接口分享、代码生成器、Api市场等诸多实用功能,致力于提高Api接口开发效率。
25+
Apidoc是一个通过解析注解生成Api接口文档的PHP composer扩展,兼容Laravel、ThinkPHP、Hyperf、Webman等框架
26+
全面的注解引用、数据表字段引用,简单的注解即可生成Api文档,而Apidoc不仅于接口文档,在线接口调试、Mock调试数据、调试事件处理、Json/TypeScript生成、接口生成器、代码生成器等诸多实用功能,致力于提高Api接口开发效率。
2727

2828

2929
## ✨特性

src/annotation/EventBase.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
abstract class EventBase extends Annotation
88
{
99

10+
/**
11+
* 名称
12+
* @var string
13+
*/
14+
public $name;
15+
1016
/**
1117
* key
1218
* @var string
@@ -39,7 +45,7 @@ abstract class EventBase extends Annotation
3945
public $contentType;
4046

4147
/**
42-
* 描述
48+
* 字段描述
4349
* @var string
4450
*/
4551
public $desc;

src/annotation/Md.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Doctrine\Common\Annotations\Annotation;
66

77
/**
8-
* Url
8+
* Markdown
99
* @package hg\apidoc\annotation
1010
* @Annotation
1111
* @Target({"METHOD"})

src/annotation/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Doctrine\Common\Annotations\Annotation;
66

77
/**
8-
* Url
8+
* 请求类型
99
* @package hg\apidoc\annotation
1010
* @Annotation
1111
* @Target({"METHOD"})

src/annotation/ResponseErrorMd.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace hg\apidoc\annotation;
4+
5+
use Doctrine\Common\Annotations\Annotation;
6+
7+
/**
8+
* 异常响应体的Markdown内容
9+
* @package hg\apidoc\annotation
10+
* @Annotation
11+
* @Target({"METHOD"})
12+
*/
13+
class ResponseErrorMd extends Annotation
14+
{
15+
/**
16+
* 引入md内容
17+
* @var string
18+
*/
19+
public $ref;
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace hg\apidoc\annotation;
4+
5+
use Doctrine\Common\Annotations\Annotation;
6+
7+
/**
8+
* 成功响应体Markdown内容
9+
* @package hg\apidoc\annotation
10+
* @Annotation
11+
* @Target({"METHOD"})
12+
*/
13+
class ResponseSuccessMd extends Annotation
14+
{
15+
/**
16+
* 引入md内容
17+
* @var string
18+
*/
19+
public $ref;
20+
}

src/annotation/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Doctrine\Common\Annotations\Annotation;
66

77
/**
8-
* Url
8+
* 接口Url
99
* @package hg\apidoc\annotation
1010
* @Annotation
1111
* @Target({"METHOD"})

src/parses/ParseApiDetail.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use hg\apidoc\annotation\Param;
1515
use hg\apidoc\annotation\Query;
1616
use hg\apidoc\annotation\ResponseSuccess;
17+
use hg\apidoc\annotation\ResponseSuccessMd;
1718
use hg\apidoc\annotation\ResponseError;
19+
use hg\apidoc\annotation\ResponseErrorMd;
1820
use hg\apidoc\annotation\Title;
1921
use hg\apidoc\annotation\Desc;
2022
use hg\apidoc\annotation\Md;
@@ -387,16 +389,22 @@ public static function autoCreateUrl($classPath,$method,$config): string
387389
$classUrlArr = [];
388390
foreach ($pathArr as $item) {
389391
if (!in_array($item, $filterPathNames)) {
390-
if (!empty($config['auto_url']) && !empty($config['auto_url']['letter_rule'])){
391-
switch ($config['auto_url']['letter_rule']) {
392-
case 'lcfirst':
393-
$classUrlArr[] = lcfirst($item);
394-
break;
395-
case 'ucfirst':
396-
$classUrlArr[] = ucfirst($item);
397-
break;
398-
default:
399-
$classUrlArr[] = $item;
392+
if (!empty($config['auto_url'])){
393+
$key = $item;
394+
if (!empty($config['auto_url']['letter_rule'])){
395+
switch ($config['auto_url']['letter_rule']) {
396+
case 'lcfirst':
397+
$key = lcfirst($item);
398+
break;
399+
case 'ucfirst':
400+
$key = ucfirst($item);
401+
break;
402+
default:
403+
$key = $item;
404+
}
405+
}
406+
if (!empty($config['auto_url']['handle_key'])){
407+
$classUrlArr[] = $config['auto_url']['handle_key']($key);
400408
}
401409
}else{
402410
$classUrlArr[] = $item;
@@ -565,6 +573,7 @@ protected function parseAnnotation($refMethod, bool $enableRefService = true,$so
565573
case $annotation instanceof ResponseSuccess:
566574
$responseSuccess = $this->handleParamAndReturned($responseSuccess,$annotation,'responseSuccess',$enableRefService);
567575
break;
576+
568577
case $annotation instanceof Query:
569578
$querys = $this->handleParamAndReturned($querys,$annotation,'query',$enableRefService);
570579
break;
@@ -615,18 +624,18 @@ protected function parseAnnotation($refMethod, bool $enableRefService = true,$so
615624
$data['md'] = ParseMarkdown::getContent("",$annotation->ref);
616625
}
617626
break;
618-
// case $annotation instanceof ParamMd:
619-
// $data['paramMd'] = $annotation->value;
620-
// if (!empty($annotation->ref)){
621-
// $data['paramMd'] = ParseMarkdown::getContent("",$annotation->ref);
622-
// }
623-
// break;
624-
// case $annotation instanceof ReturnedMd:
625-
// $data['returnMd'] = $annotation->value;
626-
// if (!empty($annotation->ref)){
627-
// $data['returnMd'] = ParseMarkdown::getContent("",$annotation->ref);
628-
// }
629-
// break;
627+
case $annotation instanceof ResponseSuccessMd:
628+
$data['responseSuccessMd'] = $annotation->value;
629+
if (!empty($annotation->ref)){
630+
$data['responseSuccessMd'] = ParseMarkdown::getContent("",$annotation->ref);
631+
}
632+
break;
633+
case $annotation instanceof ResponseErrorMd:
634+
$data['responseErrorMd'] = $annotation->value;
635+
if (!empty($annotation->ref)){
636+
$data['responseErrorMd'] = ParseMarkdown::getContent("",$annotation->ref);
637+
}
638+
break;
630639
case $annotation instanceof ParamType:
631640
$data['paramType'] = $annotation->value;
632641
break;

src/utils/DirAndFile.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function getDirTree($path){
3232

3333
public static function getClassList($dir){
3434
if ($handle = opendir($dir)) {
35+
$file_list=[];
3536
while (false !== ($file = readdir($handle))) {
3637
if($file=='..' || $file=='.') continue;
3738
$filePath = static::formatPath($dir.'/'.$file,"/");
@@ -59,6 +60,7 @@ public static function getClassList($dir){
5960
closedir($handle);
6061
return $file_list;
6162
}
63+
return [];
6264
}
6365

6466
public static function formatPath($path,$type="/"){

0 commit comments

Comments
 (0)