Skip to content

Commit 93c7545

Browse files
authored
Merge pull request #41 from BitBagCommerce/UC-27-api-v1
[UC-27 v1] Add customer-agreements endpoint swagger
2 parents 1dd1b1e + c6b7ea4 commit 93c7545

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

config/services/api.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@
2121
<argument type="service" id="monolog.logger.user_com"/>
2222
<argument type="service" id="bit_bag.sylius_user_com_plugin.manager.user_com_api_token_manager"/>
2323
</service>
24+
25+
<service id="bit_bag.sylius_user_com_plugin.openapi.factory" class="BitBag\SyliusUserComPlugin\OpenApi\OpenApiFactory" decorates="api_platform.openapi.factory">
26+
<argument type="service" id="bit_bag.sylius_user_com_plugin.openapi.factory.inner" />
27+
</service>
2428
</services>
2529
</container>

src/OpenApi/OpenApiFactory.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/*
4+
* This file has been created by developers from BitBag.
5+
* Feel free to contact us once you face any issues or want to start
6+
* You can find more information about us on https://bitbag.io and write us
7+
* an email on hello@bitbag.io.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace BitBag\SyliusUserComPlugin\OpenApi;
13+
14+
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
15+
use ApiPlatform\OpenApi\Model;
16+
use ApiPlatform\OpenApi\OpenApi;
17+
18+
final class OpenApiFactory implements OpenApiFactoryInterface
19+
{
20+
public function __construct(
21+
private OpenApiFactoryInterface $decorated,
22+
) {
23+
}
24+
25+
public function __invoke(array $context = []): OpenApi
26+
{
27+
$openApi = ($this->decorated)($context);
28+
$paths = $openApi->getPaths();
29+
30+
$pathItem = new Model\PathItem(
31+
summary: 'Synchronize user agreements coming from User.com',
32+
post: new Model\Operation(
33+
operationId: 'bitbag_usercom_customer_agreements_post',
34+
tags: ['UserComAgreements'],
35+
responses: [
36+
'200' => [
37+
'description' => 'OK',
38+
'content' => [
39+
'text/plain' => [
40+
'schema' => [
41+
'type' => 'string',
42+
'example' => 'OK',
43+
],
44+
],
45+
],
46+
],
47+
'400' => ['description' => 'Invalid JSON payload'],
48+
'401' => ['description' => 'Unauthorized'],
49+
'404' => ['description' => 'Not found'],
50+
'500' => ['description' => 'Internal server error'],
51+
],
52+
parameters: [
53+
new Model\Parameter(
54+
name: 'X-User-Com-Signature',
55+
in: 'header',
56+
description: 'Request signature',
57+
required: false,
58+
schema: ['type' => 'string'],
59+
),
60+
],
61+
requestBody: new Model\RequestBody(
62+
description: 'User.com agreements payload',
63+
content: new \ArrayObject([
64+
'application/json' => [
65+
'schema' => [
66+
'type' => 'object',
67+
'required' => ['extra'],
68+
'properties' => [
69+
'extra' => [
70+
'type' => 'object',
71+
'required' => ['email', 'agreements'],
72+
'properties' => [
73+
'email' => [
74+
'type' => 'string',
75+
'format' => 'email',
76+
'example' => 'john.doe@example.com',
77+
],
78+
'agreements' => [
79+
'type' => 'object',
80+
'additionalProperties' => [
81+
'type' => 'boolean',
82+
],
83+
'example' => [
84+
'email_agreement' => true,
85+
],
86+
],
87+
],
88+
],
89+
],
90+
],
91+
],
92+
]),
93+
),
94+
),
95+
);
96+
97+
$paths->addPath('/user-com/customer-agreements', $pathItem);
98+
99+
return $openApi;
100+
}
101+
}

0 commit comments

Comments
 (0)