Skip to content

Commit 3570df9

Browse files
committed
Fix swagger
1 parent f6b8e0d commit 3570df9

14 files changed

+179
-225
lines changed

src/Identity/Controller/AdminAttributeDefinitionController.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
use PhpList\RestBundle\Common\Controller\BaseController;
1313
use PhpList\RestBundle\Common\Service\Provider\PaginatedDataProvider;
1414
use PhpList\RestBundle\Common\Validator\RequestValidator;
15-
use PhpList\RestBundle\Identity\Request\CreateAttributeDefinitionRequest;
16-
use PhpList\RestBundle\Identity\Request\UpdateAttributeDefinitionRequest;
15+
use PhpList\RestBundle\Identity\Request\AdminAttributeDefinitionRequest;
1716
use PhpList\RestBundle\Identity\Serializer\AdminAttributeDefinitionNormalizer;
1817
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
1918
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -51,7 +50,7 @@ public function __construct(
5150
requestBody: new OA\RequestBody(
5251
description: 'Pass parameters to create admin attribute.',
5352
required: true,
54-
content: new OA\JsonContent(ref: '#/components/schemas/CreateAdminAttributeDefinitionRequest')
53+
content: new OA\JsonContent(ref: '#/components/schemas/AdminAttributeDefinitionRequest')
5554
),
5655
tags: ['admin-attributes'],
5756
parameters: [
@@ -87,8 +86,8 @@ public function create(Request $request): JsonResponse
8786
{
8887
$this->requireAuthentication($request);
8988

90-
/** @var CreateAttributeDefinitionRequest $definitionRequest */
91-
$definitionRequest = $this->validator->validate($request, CreateAttributeDefinitionRequest::class);
89+
/** @var AdminAttributeDefinitionRequest $definitionRequest */
90+
$definitionRequest = $this->validator->validate($request, AdminAttributeDefinitionRequest::class);
9291

9392
$attributeDefinition = $this->definitionManager->create($definitionRequest->getDto());
9493
$this->entityManager->flush();
@@ -107,7 +106,7 @@ public function create(Request $request): JsonResponse
107106
requestBody: new OA\RequestBody(
108107
description: 'Pass parameters to update admin attribute.',
109108
required: true,
110-
content: new OA\JsonContent(ref: '#/components/schemas/CreateAdminAttributeDefinitionRequest')
109+
content: new OA\JsonContent(ref: '#/components/schemas/AdminAttributeDefinitionRequest')
111110
),
112111
tags: ['admin-attributes'],
113112
parameters: [
@@ -153,8 +152,8 @@ public function update(
153152
throw $this->createNotFoundException('Attribute definition not found.');
154153
}
155154

156-
/** @var UpdateAttributeDefinitionRequest $definitionRequest */
157-
$definitionRequest = $this->validator->validate($request, UpdateAttributeDefinitionRequest::class);
155+
/** @var AdminAttributeDefinitionRequest $definitionRequest */
156+
$definitionRequest = $this->validator->validate($request, AdminAttributeDefinitionRequest::class);
158157

159158
$attributeDefinition = $this->definitionManager->update(
160159
attributeDefinition: $attributeDefinition,

src/Identity/OpenApi/SwaggerSchemasRequest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpList\RestBundle\Identity\OpenApi;
66

77
use OpenApi\Attributes as OA;
8+
use PhpList\Core\Domain\Common\Model\AttributeTypeEnum;
89

910
#[OA\Schema(
1011
schema: 'CreateAdministratorRequest',
@@ -96,15 +97,23 @@
9697
type: 'object'
9798
)]
9899
#[OA\Schema(
99-
schema: 'CreateAdminAttributeDefinitionRequest',
100+
schema: 'AdminAttributeDefinitionRequest',
100101
required: ['name'],
101102
properties: [
102103
new OA\Property(property: 'name', type: 'string', format: 'string', example: 'Country'),
103-
new OA\Property(property: 'type', type: 'string', example: 'checkbox'),
104+
new OA\Property(
105+
property: 'type',
106+
type: 'string',
107+
enum: [
108+
AttributeTypeEnum::TextLine,
109+
AttributeTypeEnum::Hidden,
110+
],
111+
example: 'hidden',
112+
nullable: true
113+
),
104114
new OA\Property(property: 'order', type: 'number', example: 12),
105115
new OA\Property(property: 'default_value', type: 'string', example: 'United States'),
106116
new OA\Property(property: 'required', type: 'boolean', example: true),
107-
new OA\Property(property: 'table_name', type: 'string', example: 'list_attributes'),
108117
],
109118
type: 'object'
110119
)]

src/Identity/OpenApi/SwaggerSchemasResponse.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
properties: [
2828
new OA\Property(property: 'id', type: 'integer', example: 1),
2929
new OA\Property(property: 'name', type: 'string', example: 'Country'),
30-
new OA\Property(property: 'type', type: 'string', example: 'select'),
30+
new OA\Property(property: 'type', type: 'string', example: 'hidden'),
3131
new OA\Property(property: 'list_order', type: 'integer', example: 12),
3232
new OA\Property(property: 'default_value', type: 'string', example: 'United States'),
3333
new OA\Property(property: 'required', type: 'boolean', example: true),
34-
new OA\Property(property: 'table_name', type: 'string', example: 'ukcounties'),
3534
],
3635
type: 'object'
3736
)]

src/Identity/Request/CreateAttributeDefinitionRequest.php renamed to src/Identity/Request/AdminAttributeDefinitionRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PhpList\RestBundle\Common\Request\RequestInterface;
99
use Symfony\Component\Validator\Constraints as Assert;
1010

11-
class CreateAttributeDefinitionRequest implements RequestInterface
11+
class AdminAttributeDefinitionRequest implements RequestInterface
1212
{
1313
#[Assert\NotBlank]
1414
public string $name;

src/Identity/Request/UpdateAttributeDefinitionRequest.php

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

src/Subscription/OpenApi/SwaggerSchemasRequest.php

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

src/Subscription/OpenApi/SwaggerSchemasResponse.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,24 @@
9494
new OA\Property(property: 'default_value', type: 'string', example: 'United States'),
9595
new OA\Property(property: 'required', type: 'boolean', example: true),
9696
new OA\Property(property: 'table_name', type: 'string', example: 'list_attributes'),
97+
new OA\Property(
98+
property: 'options',
99+
type: 'array',
100+
items: new OA\Items(ref: '#/components/schemas/DynamicListAttrOption'),
101+
nullable: true,
102+
),
97103
],
98104
type: 'object'
99105
)]
106+
#[OA\Schema(
107+
schema: 'DynamicListAttrOption',
108+
properties: [
109+
new OA\Property(property: 'id', type: 'integer', example: 1, nullable: false),
110+
new OA\Property(property: 'name', type: 'string', example: 'United States'),
111+
new OA\Property(property: 'listorder', type: 'integer', example: 1, nullable: false),
112+
],
113+
type: 'object',
114+
)]
100115
#[OA\Schema(
101116
schema: 'SubscriberAttributeValue',
102117
properties: [

src/Subscription/Request/CreateSubscriberListRequest.php

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

55
namespace PhpList\RestBundle\Subscription\Request;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Subscription\Model\Dto\CreateSubscriberListDto;
89
use PhpList\RestBundle\Common\Request\RequestInterface;
910
use Symfony\Component\Validator\Constraints as Assert;
1011

12+
#[OA\Schema(
13+
schema: 'CreateSubscriberListRequest',
14+
required: ['name'],
15+
properties: [
16+
new OA\Property(property: 'name', type: 'string', format: 'string', example: 'News'),
17+
new OA\Property(property: 'description', type: 'string', example: 'News (and some fun stuff)'),
18+
new OA\Property(property: 'list_position', type: 'number', example: 12),
19+
new OA\Property(property: 'public', type: 'boolean', example: true),
20+
],
21+
type: 'object'
22+
)]
1123
class CreateSubscriberListRequest implements RequestInterface
1224
{
1325
#[Assert\NotBlank]

src/Subscription/Request/CreateSubscriberRequest.php

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

55
namespace PhpList\RestBundle\Subscription\Request;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Subscription\Model\Dto\CreateSubscriberDto;
89
use PhpList\Core\Domain\Subscription\Model\Subscriber;
910
use PhpList\RestBundle\Common\Request\RequestInterface;
1011
use PhpList\RestBundle\Subscription\Validator\Constraint\UniqueEmail;
1112
use Symfony\Component\Validator\Constraints as Assert;
1213

14+
#[OA\Schema(
15+
schema: 'CreateSubscriberRequest',
16+
required: ['email'],
17+
properties: [
18+
new OA\Property(property: 'email', type: 'string', format: 'string', example: 'admin@example.com'),
19+
new OA\Property(property: 'request_confirmation', type: 'boolean', example: false),
20+
new OA\Property(property: 'html_email', type: 'boolean', example: false),
21+
],
22+
type: 'object'
23+
)]
1324
class CreateSubscriberRequest implements RequestInterface
1425
{
1526
#[Assert\NotBlank]

src/Subscription/Request/SubscriberAttributeDefinitionRequest.php

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

55
namespace PhpList\RestBundle\Subscription\Request;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Common\Model\AttributeTypeEnum;
89
use PhpList\Core\Domain\Subscription\Model\Dto\AttributeDefinitionDto;
910
use PhpList\Core\Domain\Subscription\Model\Dto\DynamicListAttrDto;
@@ -14,6 +15,50 @@
1415
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1516
use Symfony\Component\Validator\Exception\ValidatorException;
1617

18+
#[OA\Schema(
19+
schema: 'SubscriberAttributeDefinitionRequest',
20+
required: ['name'],
21+
properties: [
22+
new OA\Property(property: 'name', type: 'string', example: 'Country'),
23+
new OA\Property(
24+
property: 'type',
25+
type: 'string',
26+
enum: [
27+
AttributeTypeEnum::TextLine,
28+
AttributeTypeEnum::Hidden,
29+
AttributeTypeEnum::CreditCardNo,
30+
AttributeTypeEnum::Select,
31+
AttributeTypeEnum::Date,
32+
AttributeTypeEnum::Checkbox,
33+
AttributeTypeEnum::TextArea,
34+
AttributeTypeEnum::Radio,
35+
AttributeTypeEnum::CheckboxGroup,
36+
],
37+
example: 'checkbox',
38+
nullable: true
39+
),
40+
new OA\Property(property: 'order', type: 'integer', example: 12, nullable: true),
41+
new OA\Property(property: 'default_value', type: 'string', example: 'United States', nullable: true),
42+
new OA\Property(property: 'required', type: 'boolean', example: true),
43+
new OA\Property(
44+
property: 'options',
45+
type: 'array',
46+
items: new OA\Items(ref: '#/components/schemas/DynamicListAttr'),
47+
nullable: true,
48+
),
49+
],
50+
type: 'object',
51+
)]
52+
#[OA\Schema(
53+
schema: 'DynamicListAttr',
54+
required: ['name'],
55+
properties: [
56+
new OA\Property(property: 'id', type: 'integer', example: 1, nullable: true),
57+
new OA\Property(property: 'name', type: 'string', example: 'United States'),
58+
new OA\Property(property: 'listorder', type: 'integer', example: 10, nullable: true),
59+
],
60+
type: 'object',
61+
)]
1762
#[Assert\Callback('validateType')]
1863
class SubscriberAttributeDefinitionRequest implements RequestInterface
1964
{

0 commit comments

Comments
 (0)