Skip to content

Commit c263e0d

Browse files
committed
Swagger schemas in request/normalizer
1 parent d4d0aeb commit c263e0d

36 files changed

+654
-703
lines changed

src/Identity/OpenApi/SwaggerSchemasRequest.php

Lines changed: 0 additions & 122 deletions
This file was deleted.

src/Identity/OpenApi/SwaggerSchemasResponse.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/Identity/Request/AdminAttributeDefinitionRequest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace PhpList\RestBundle\Identity\Request;
66

7+
use OpenApi\Attributes as OA;
8+
use PhpList\Core\Domain\Common\Model\AttributeTypeEnum;
79
use PhpList\Core\Domain\Identity\Model\Dto\AdminAttributeDefinitionDto;
810
use PhpList\Core\Domain\Subscription\Validator\AttributeTypeValidator;
911
use PhpList\RestBundle\Common\Request\RequestInterface;
@@ -12,6 +14,27 @@
1214
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1315
use Symfony\Component\Validator\Exception\ValidatorException;
1416

17+
#[OA\Schema(
18+
schema: 'AdminAttributeDefinitionRequest',
19+
required: ['name'],
20+
properties: [
21+
new OA\Property(property: 'name', type: 'string', format: 'string', example: 'Country'),
22+
new OA\Property(
23+
property: 'type',
24+
type: 'string',
25+
enum: [
26+
AttributeTypeEnum::TextLine,
27+
AttributeTypeEnum::Hidden,
28+
],
29+
example: 'hidden',
30+
nullable: true
31+
),
32+
new OA\Property(property: 'order', type: 'number', example: 12),
33+
new OA\Property(property: 'default_value', type: 'string', example: 'United States'),
34+
new OA\Property(property: 'required', type: 'boolean', example: true),
35+
],
36+
type: 'object'
37+
)]
1538
#[Assert\Callback('validateType')]
1639
class AdminAttributeDefinitionRequest implements RequestInterface
1740
{

src/Identity/Request/CreateAdministratorRequest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,59 @@
44

55
namespace PhpList\RestBundle\Identity\Request;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Identity\Model\Administrator;
89
use PhpList\Core\Domain\Identity\Model\Dto\CreateAdministratorDto;
910
use PhpList\RestBundle\Common\Request\RequestInterface;
1011
use PhpList\RestBundle\Identity\Validator\Constraint\UniqueEmail;
1112
use PhpList\RestBundle\Identity\Validator\Constraint\UniqueLoginName;
1213
use Symfony\Component\Validator\Constraints as Assert;
1314

15+
#[OA\Schema(
16+
schema: 'CreateAdministratorRequest',
17+
required: ['login_name', 'password', 'email', 'super_user'],
18+
properties: [
19+
new OA\Property(
20+
property: 'login_name',
21+
type: 'string',
22+
maxLength: 255,
23+
minLength: 3,
24+
example: 'admin'
25+
),
26+
new OA\Property(
27+
property: 'password',
28+
type: 'string',
29+
format: 'password',
30+
maxLength: 255,
31+
minLength: 6,
32+
example: 'StrongP@ssw0rd'
33+
),
34+
new OA\Property(
35+
property: 'email',
36+
type: 'string',
37+
format: 'email',
38+
example: 'admin@example.com'
39+
),
40+
new OA\Property(
41+
property: 'super_user',
42+
type: 'boolean',
43+
example: false
44+
),
45+
new OA\Property(
46+
property: 'privileges',
47+
description: 'Array of privileges where keys are privilege names and values are booleans',
48+
properties: [
49+
new OA\Property(property: 'subscribers', type: 'boolean', example: true),
50+
new OA\Property(property: 'campaigns', type: 'boolean', example: false),
51+
new OA\Property(property: 'statistics', type: 'boolean', example: true),
52+
new OA\Property(property: 'settings', type: 'boolean', example: false),
53+
],
54+
type: 'object',
55+
example: ['subscribers' => true, 'campaigns' => false, 'statistics' => true, 'settings' => false]
56+
),
57+
],
58+
type: 'object'
59+
)]
1460
class CreateAdministratorRequest implements RequestInterface
1561
{
1662
#[Assert\NotBlank]

src/Identity/Request/UpdateAdministratorRequest.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,58 @@
44

55
namespace PhpList\RestBundle\Identity\Request;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Identity\Model\Administrator;
89
use PhpList\Core\Domain\Identity\Model\Dto\UpdateAdministratorDto;
9-
use PhpList\Core\Domain\Identity\Model\PrivilegeFlag;
1010
use PhpList\RestBundle\Common\Request\RequestInterface;
1111
use PhpList\RestBundle\Identity\Validator\Constraint\UniqueEmail;
1212
use PhpList\RestBundle\Identity\Validator\Constraint\UniqueLoginName;
1313
use Symfony\Component\Validator\Constraints as Assert;
1414

15+
#[OA\Schema(
16+
schema: 'UpdateAdministratorRequest',
17+
properties: [
18+
new OA\Property(
19+
property: 'login_name',
20+
type: 'string',
21+
maxLength: 255,
22+
minLength: 3,
23+
example: 'admin'
24+
),
25+
new OA\Property(
26+
property: 'password',
27+
type: 'string',
28+
format: 'password',
29+
maxLength: 255,
30+
minLength: 6,
31+
example: 'StrongP@ssw0rd'
32+
),
33+
new OA\Property(
34+
property: 'email',
35+
type: 'string',
36+
format: 'email',
37+
example: 'admin@example.com'
38+
),
39+
new OA\Property(
40+
property: 'super_user',
41+
type: 'boolean',
42+
example: false
43+
),
44+
new OA\Property(
45+
property: 'privileges',
46+
description: 'Array of privileges where keys are privilege names and values are booleans',
47+
properties: [
48+
new OA\Property(property: 'subscribers', type: 'boolean', example: true),
49+
new OA\Property(property: 'campaigns', type: 'boolean', example: false),
50+
new OA\Property(property: 'statistics', type: 'boolean', example: true),
51+
new OA\Property(property: 'settings', type: 'boolean', example: false),
52+
],
53+
type: 'object',
54+
example: ['subscribers' => true, 'campaigns' => false, 'statistics' => true, 'settings' => false]
55+
),
56+
],
57+
type: 'object'
58+
)]
1559
class UpdateAdministratorRequest implements RequestInterface
1660
{
1761
public int $administratorId;

src/Identity/Serializer/AdminAttributeDefinitionNormalizer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@
44

55
namespace PhpList\RestBundle\Identity\Serializer;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Identity\Model\AdminAttributeDefinition;
89
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
910

11+
#[OA\Schema(
12+
schema: 'AdminAttributeDefinition',
13+
properties: [
14+
new OA\Property(property: 'id', type: 'integer', example: 1),
15+
new OA\Property(property: 'name', type: 'string', example: 'Country'),
16+
new OA\Property(property: 'type', type: 'string', example: 'hidden'),
17+
new OA\Property(property: 'list_order', type: 'integer', example: 12),
18+
new OA\Property(property: 'default_value', type: 'string', example: 'United States'),
19+
new OA\Property(property: 'required', type: 'boolean', example: true),
20+
],
21+
type: 'object'
22+
)]
1023
class AdminAttributeDefinitionNormalizer implements NormalizerInterface
1124
{
1225
/**

src/Identity/Serializer/AdminAttributeValueNormalizer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
namespace PhpList\RestBundle\Identity\Serializer;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Identity\Model\AdminAttributeValue;
89
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
910

11+
#[OA\Schema(
12+
schema: 'AdminAttributeValue',
13+
properties: [
14+
new OA\Property(property: 'administrator', ref: '#/components/schemas/Administrator'),
15+
new OA\Property(property: 'definition', ref: '#/components/schemas/AttributeDefinition'),
16+
new OA\Property(property: 'value', type: 'string', example: 'United States'),
17+
],
18+
type: 'object'
19+
)]
1020
class AdminAttributeValueNormalizer implements NormalizerInterface
1121
{
1222
public function __construct(

0 commit comments

Comments
 (0)