mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-10 18:51:02 +00:00
add attributes to define OpenAPI schema more conveniently
This commit is contained in:
parent
c3f8d07c92
commit
a245434d74
4 changed files with 129 additions and 0 deletions
23
src/OpenApi/Attribute/OrderParameter.php
Normal file
23
src/OpenApi/Attribute/OrderParameter.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wallabag\OpenApi\Attribute;
|
||||||
|
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_METHOD)]
|
||||||
|
class OrderParameter extends OA\Parameter
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly string $defaultName = 'order',
|
||||||
|
public readonly string $default = 'desc',
|
||||||
|
) {
|
||||||
|
parent::__construct(
|
||||||
|
name: $defaultName,
|
||||||
|
in: 'query',
|
||||||
|
description: 'Order of results (asc or desc).',
|
||||||
|
required: false,
|
||||||
|
schema: new OA\Schema(type: 'string', enum: ['asc', 'desc'], default: $default)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
60
src/OpenApi/Attribute/PagerFanta/JsonContent.php
Normal file
60
src/OpenApi/Attribute/PagerFanta/JsonContent.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wallabag\OpenApi\Attribute\PagerFanta;
|
||||||
|
|
||||||
|
use Nelmio\ApiDocBundle\Attribute\Model;
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_CLASS)]
|
||||||
|
class JsonContent extends OA\JsonContent
|
||||||
|
{
|
||||||
|
public function __construct(string|array|null $modelClass = null)
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
properties: [
|
||||||
|
new OA\Property(
|
||||||
|
property: '_embedded',
|
||||||
|
type: 'object',
|
||||||
|
properties: [
|
||||||
|
new OA\Property(
|
||||||
|
property: 'items',
|
||||||
|
type: 'array',
|
||||||
|
items: new OA\Items(ref: new Model(type: $modelClass))
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
new OA\Property(property: 'page', type: 'integer'),
|
||||||
|
new OA\Property(property: 'limit', type: 'integer'),
|
||||||
|
new OA\Property(property: 'pages', type: 'integer'),
|
||||||
|
new OA\Property(property: 'total', type: 'integer'),
|
||||||
|
new OA\Property(
|
||||||
|
property: '_links',
|
||||||
|
type: 'object',
|
||||||
|
properties: [
|
||||||
|
new OA\Property(
|
||||||
|
property: 'self',
|
||||||
|
type: 'object',
|
||||||
|
properties: [new OA\Property(property: 'href', type: 'string')]
|
||||||
|
),
|
||||||
|
new OA\Property(
|
||||||
|
property: 'first',
|
||||||
|
type: 'object',
|
||||||
|
properties: [new OA\Property(property: 'href', type: 'string')]
|
||||||
|
),
|
||||||
|
new OA\Property(
|
||||||
|
property: 'last',
|
||||||
|
type: 'object',
|
||||||
|
properties: [new OA\Property(property: 'href', type: 'string')]
|
||||||
|
),
|
||||||
|
new OA\Property(
|
||||||
|
property: 'next',
|
||||||
|
type: 'object',
|
||||||
|
properties: [new OA\Property(property: 'href', type: 'string')]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
23
src/OpenApi/Attribute/PagerFanta/PageParameter.php
Normal file
23
src/OpenApi/Attribute/PagerFanta/PageParameter.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wallabag\OpenApi\Attribute\PagerFanta;
|
||||||
|
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_METHOD)]
|
||||||
|
class PageParameter extends OA\Parameter
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly string $defaultName = 'page',
|
||||||
|
public readonly int $default = 1,
|
||||||
|
) {
|
||||||
|
parent::__construct(
|
||||||
|
name: $defaultName,
|
||||||
|
in: 'query',
|
||||||
|
description: 'Requested page number.',
|
||||||
|
required: false,
|
||||||
|
schema: new OA\Schema(type: 'integer', default: $default)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
23
src/OpenApi/Attribute/PagerFanta/PerPageParameter.php
Normal file
23
src/OpenApi/Attribute/PagerFanta/PerPageParameter.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wallabag\OpenApi\Attribute\PagerFanta;
|
||||||
|
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute(Attribute::TARGET_METHOD)]
|
||||||
|
class PerPageParameter extends OA\Parameter
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly string $defaultName = 'perPage',
|
||||||
|
public readonly int $default = 30,
|
||||||
|
) {
|
||||||
|
parent::__construct(
|
||||||
|
name: $defaultName,
|
||||||
|
in: 'query',
|
||||||
|
description: 'Number of items per page.',
|
||||||
|
required: false,
|
||||||
|
schema: new OA\Schema(type: 'integer', default: $default)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue