File tree Expand file tree Collapse file tree 6 files changed +70
-8
lines changed Expand file tree Collapse file tree 6 files changed +70
-8
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ return [
4
+ 'title ' => 'API Docs ' ,
5
+ 'description ' => 'API Docs description. ' ,
6
+ 'headers ' => [
7
+
8
+ ],
9
+ 'service ' => [
10
+
11
+ ],
12
+ ];
Original file line number Diff line number Diff line change 2
2
3
3
declare (strict_types=1 );
4
4
5
- namespace Astral \Serialize \ OpenApi ;
5
+ namespace Astral \Serialize ;
6
6
7
7
use Astral \Serialize \OpenApi \Annotations \Headers ;
8
8
use Astral \Serialize \OpenApi \Annotations \RequestBody ;
@@ -53,13 +53,17 @@ public function buildByClass(string $className): void
53
53
Headers::class => null ,
54
54
];
55
55
56
+
56
57
foreach ($ methodAttributes as $ methodAttribute ) {
57
- $ name = $ methodAttribute ->getName ();
58
- if (array_key_exists ($ name ,$ instances )) {
59
- $ instances [$ name ] = $ methodAttribute ->newInstance ();
58
+ $ inst = $ methodAttribute ->newInstance ();
59
+ foreach (array_keys ($ instances ) as $ anchorClass ) {
60
+ if ($ inst instanceof $ anchorClass ) {
61
+ $ instances [$ anchorClass ] = $ inst ;
62
+ }
60
63
}
61
64
}
62
65
66
+
63
67
if ($ instances [Route::class] === null || $ instances [Summary::class] === null ) {
64
68
continue ;
65
69
}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ abstract class Handler implements HandleInterface
21
21
public function __construct (
22
22
protected readonly ParameterStorage $ headerParameterStorages = new ParameterStorage ()
23
23
) {
24
- self ::$ OpenAPI ??= (new OpenAPI ())->withApiInfo (new ApiInfo ('API 接口 ' ,'' ));
24
+ self ::$ OpenAPI ??= (new OpenAPI ())->withApiInfo (new ApiInfo ('API Doc ' ,'' ));
25
25
}
26
26
27
27
/**
Original file line number Diff line number Diff line change 6
6
7
7
use Astral \Serialize \OpenApi \Enum \ContentTypeEnum ;
8
8
use Astral \Serialize \OpenApi \Storage \StorageInterface ;
9
+ use stdClass ;
9
10
10
11
/**
11
12
* 参数配置
12
13
*/
13
14
class RequestBodyStorage implements StorageInterface
14
15
{
15
- public array $ parameters ;
16
+ public array | stdClass $ parameters = [] ;
16
17
17
18
public function __construct (
18
19
public ContentTypeEnum $ contentType = ContentTypeEnum::JSON ,
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- use Astral \Serialize \OpenApi \ OpenApi ;
3
+ use Astral \Serialize \OpenApi ;
4
4
use Astral \Serialize \Serialize ;
5
5
6
6
beforeAll (static function () {
@@ -59,7 +59,6 @@ public function one(TestOpenApiRequest $request): TestOpenApiResponse
59
59
60
60
// 顶层结构断言
61
61
expect ($ openApi ->openapi )->toBe ('3.1.1 ' )
62
- ->and ($ openApi ->info ->title )->toBe ('API 接口 ' )
63
62
->and ($ openApi ->info ->version )->toBe ('1.0.0 ' )
64
63
->and ($ openApi ->tags [0 ]->name )->toBe ('接口测试 ' );
65
64
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Astral \Serialize \OpenApi ;
4
+ use Astral \Serialize \Serialize ;
5
+
6
+ beforeAll (static function () {
7
+
8
+
9
+ #[Attribute(Attribute::TARGET_METHOD )]
10
+ class CustomerRoute extends OpenApi \Annotations \Route
11
+ {
12
+
13
+ }
14
+
15
+ class TestCustomerRouteRequest extends Serialize
16
+ {
17
+ public string $ name ;
18
+
19
+ public int $ id ;
20
+ }
21
+
22
+ #[\Astral \Serialize \OpenApi \Annotations \Tag('接口测试 ' )]
23
+ class TestCustomerRouteController{
24
+
25
+ #[\Astral \Serialize \OpenApi \Annotations \Summary('测试方法一 ' )]
26
+ #[CustomerRoute('/test/customer-route ' )]
27
+ public function one (TestCustomerRouteRequest $ request ): void
28
+ {
29
+ }
30
+
31
+ }
32
+
33
+ });
34
+
35
+ test ('OpenAPI structure is correct ' , function () {
36
+
37
+ $ api = new OpenApi ();
38
+ $ api ->buildByClass (TestCustomerRouteController::class);
39
+
40
+ $ openApi = $ api ::$ OpenAPI ;
41
+
42
+ // 路径是否存在
43
+ $ paths = $ openApi ->paths ;
44
+ expect ($ paths )->toHaveKey ('/test/customer-route ' );
45
+
46
+ });
You can’t perform that action at this time.
0 commit comments