Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 64 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
JwtDecorator | |
0.00% |
0 / 64 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__invoke | |
0.00% |
0 / 63 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace App\Application\Symfony\OpenApi; |
6 | |
7 | use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface; |
8 | use ApiPlatform\Core\OpenApi\Model; |
9 | use ApiPlatform\Core\OpenApi\OpenApi; |
10 | |
11 | final class JwtDecorator implements OpenApiFactoryInterface |
12 | { |
13 | private OpenApiFactoryInterface $decorated; |
14 | |
15 | public function __construct(OpenApiFactoryInterface $decorated) |
16 | { |
17 | $this->decorated = $decorated; |
18 | } |
19 | |
20 | public function __invoke(array $context = []): OpenApi |
21 | { |
22 | $openApi = ($this->decorated)($context); |
23 | $schemas = $openApi->getComponents()->getSchemas(); |
24 | |
25 | $schemas['Token'] = new \ArrayObject([ |
26 | 'type' => 'object', |
27 | 'properties' => [ |
28 | 'token' => [ |
29 | 'type' => 'string', |
30 | 'readOnly' => true, |
31 | ], |
32 | ], |
33 | ]); |
34 | $schemas['Credentials'] = new \ArrayObject([ |
35 | 'type' => 'object', |
36 | 'properties' => [ |
37 | 'username' => [ |
38 | 'type' => 'string', |
39 | 'example' => 'johndoe@example.com', |
40 | ], |
41 | 'password' => [ |
42 | 'type' => 'string', |
43 | 'example' => 'apassword', |
44 | ], |
45 | ], |
46 | ]); |
47 | |
48 | $pathItem = new Model\PathItem( |
49 | 'JWT Token', |
50 | null, |
51 | null, |
52 | null, |
53 | null, |
54 | new Model\Operation( |
55 | 'postCredentialsItem', |
56 | ['Token'], |
57 | [ |
58 | '200' => [ |
59 | 'description' => 'Get JWT token', |
60 | 'content' => [ |
61 | 'application/json' => [ |
62 | 'schema' => [ |
63 | '$ref' => '#/components/schemas/Token', |
64 | ], |
65 | ], |
66 | ], |
67 | ], |
68 | ], |
69 | 'Get JWT token to login.', |
70 | '', |
71 | null, |
72 | [], |
73 | new Model\RequestBody( |
74 | 'Generate new JWT Token', |
75 | new \ArrayObject([ |
76 | 'application/json' => [ |
77 | 'schema' => [ |
78 | '$ref' => '#/components/schemas/Credentials', |
79 | ], |
80 | ], |
81 | ]), |
82 | ), |
83 | ), |
84 | ); |
85 | $openApi->getPaths()->addPath('/api/login', $pathItem); |
86 | |
87 | return $openApi; |
88 | } |
89 | } |