Skip to content

Commit 71c4a93

Browse files
committed
init
1 parent 6b285bd commit 71c4a93

38 files changed

+8313
-11
lines changed

composer.lock

Lines changed: 6812 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/OpenApi/Annotations/Headers.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Annotations;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_METHOD)]
10+
class Headers
11+
{
12+
/**
13+
* @param array $headers
14+
* @param array $withOutHeaders
15+
* @example
16+
* headers: [['company-id'=>'1'],['test-header'=>'test']]
17+
* withOutHeaders: ['test-header','company-id']
18+
*/
19+
public function __construct(
20+
public array $headers = [],
21+
public array $withOutHeaders = []
22+
) {
23+
}
24+
}

src/OpenApi/Annotations/OpenApi.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Annotations;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_METHOD)]
10+
class OpenApi
11+
{
12+
public function __construct(
13+
public string $descriptions,
14+
) {
15+
}
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Annotations;
6+
7+
use Astral\Serialize\OpenApi\Enum\ContentTypeEnum;
8+
use Attribute;
9+
10+
#[Attribute(Attribute::TARGET_METHOD)]
11+
class RequestBody
12+
{
13+
public function __construct(
14+
/** @var class-string $className */
15+
public string $className = '',
16+
public ContentTypeEnum $contentType = ContentTypeEnum::JSON,
17+
public ?string $group = null
18+
){
19+
}
20+
}

src/OpenApi/Annotations/Response.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Annotations;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_METHOD)]
10+
class Response
11+
{
12+
public function __construct(
13+
/** @var class-string $className */
14+
public string $className,
15+
public ?string $group = null,
16+
public ?int $code = 200
17+
){
18+
}
19+
}

src/OpenApi/Annotations/Route.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Annotations;
6+
7+
use Astral\Serialize\OpenApi\Enum\MethodEnum;
8+
use Attribute;
9+
10+
#[Attribute(Attribute::TARGET_METHOD)]
11+
class Route
12+
{
13+
public function __construct(
14+
public string $route,
15+
public MethodEnum $method = MethodEnum::POST,
16+
public array $attributes = [],
17+
) {
18+
}
19+
20+
public function getMethod(): string
21+
{
22+
return 'April\\ApiDoc\\Storage\\OpenAPI\\Method\\' . $this->method->name;
23+
}
24+
}

src/OpenApi/Annotations/Summary.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Annotations;
6+
7+
use Attribute;
8+
9+
/**
10+
* 方法注解类
11+
*/
12+
#[Attribute(Attribute::TARGET_METHOD)]
13+
class Summary
14+
{
15+
public function __construct(
16+
public string $value,
17+
public string $description = ''
18+
) {
19+
20+
}
21+
}

src/OpenApi/Annotations/Tag.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Annotations;
6+
7+
use Astral\Serialize\OpenApi\Storage\OpenAPI\TagStorage;
8+
use Attribute;
9+
10+
/**
11+
* 栏目注解类
12+
*/
13+
#[Attribute(Attribute::TARGET_CLASS)]
14+
class Tag
15+
{
16+
public function __construct(
17+
public string $value,
18+
public string $description = ''
19+
) {
20+
}
21+
22+
public function buildTagStorage(): TagStorage
23+
{
24+
return new TagStorage($this->value, $this->description);
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Astral\Serialize\OpenApi\Collections;
4+
5+
use Astral\Serialize\OpenApi\Annotations\Headers;
6+
use Astral\Serialize\OpenApi\Annotations\Route;
7+
use Astral\Serialize\OpenApi\Annotations\Summary;
8+
9+
class OpenApiCollection
10+
{
11+
public function __construct(
12+
public string $controllerClass,
13+
public string $methodName,
14+
public Summary $summary,
15+
public Route $route,
16+
public Headers $headers,
17+
public array $attributes,
18+
/** @var array<string, ParameterCollection> $parameters, */
19+
public array $parameters = [],
20+
/** @var array<string, ParameterCollection|mixed> $requestBody, */
21+
public array $requestBody = [],
22+
/** @var array<string, ParameterCollection|mixed> $responses, */
23+
public array $response = [],
24+
25+
){
26+
}
27+
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Collections;
6+
7+
use Attribute;
8+
9+
class ParameterCollection
10+
{
11+
public function __construct(
12+
/** @var string 元素变量名 */
13+
public string $name,
14+
/** @var string descriptions */
15+
public string $descriptions = '',
16+
/** @var string 元素类型 */
17+
public string $type = 'string',
18+
/** @var mixed 示例值 */
19+
public mixed $example = '',
20+
/** @var bool 是否必填 */
21+
public bool $required = false,
22+
/** @var bool 是否忽略显示 */
23+
public bool $ignore = false,
24+
/** @var array<string, ParameterCollection> $children */
25+
public array $children = [],
26+
){
27+
}
28+
}

0 commit comments

Comments
 (0)