|
| 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