1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-06-27 16:36:00 +00:00

add attributes to define OpenAPI schema more conveniently

This commit is contained in:
Martin Chaine 2025-06-03 09:45:26 +02:00
parent c3f8d07c92
commit a245434d74
No known key found for this signature in database
GPG key ID: 2D04DFDC89D53FDE
4 changed files with 129 additions and 0 deletions

View 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)
);
}
}

View 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')]
)
]
)
]
);
}
}

View 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)
);
}
}

View 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)
);
}
}