|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Swagger; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
|
6
|
|
|
|
|
7
|
|
|
final class SwaggerDecorator implements NormalizerInterface |
|
8
|
|
|
{ |
|
9
|
|
|
private $decorated; |
|
10
|
|
|
|
|
11
|
5 |
|
public function __construct(NormalizerInterface $decorated) |
|
12
|
|
|
{ |
|
13
|
5 |
|
$this->decorated = $decorated; |
|
14
|
5 |
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function normalize($object, $format = null, array $context = []) |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var array $docs */ |
|
19
|
|
|
$docs = $this->decorated->normalize($object, $format, $context); |
|
20
|
|
|
|
|
21
|
|
|
$currentPath = '/forms/{id}'; |
|
22
|
|
|
$patchOpPath = $currentPath . '/submit'; |
|
23
|
|
|
|
|
24
|
|
|
$patchOp = $docs['paths'][$patchOpPath]['patch']; |
|
25
|
|
|
$patchOp['summary'] = 'Submit a single input for validation'; |
|
26
|
|
|
$patchOp['parameters'] = $docs['paths'][$currentPath]['get']['parameters']; |
|
27
|
|
|
$patchOp['parameters'][] = [ |
|
28
|
|
|
'name' => 'form', |
|
29
|
|
|
'in' => 'body', |
|
30
|
|
|
'required' => false, |
|
31
|
|
|
'schema' => [ |
|
32
|
|
|
'type' => 'object', |
|
33
|
|
|
'properties' => [ |
|
34
|
|
|
'form_name' => [ |
|
35
|
|
|
'type' => 'object', |
|
36
|
|
|
'properties' => [ |
|
37
|
|
|
'input_name' => [ |
|
38
|
|
|
'type' => 'string' |
|
39
|
|
|
] |
|
40
|
|
|
] |
|
41
|
|
|
] |
|
42
|
|
|
] |
|
43
|
|
|
] |
|
44
|
|
|
]; |
|
45
|
|
|
$patchOp['responses'] = $docs['paths'][$currentPath]['get']['responses']; |
|
46
|
|
|
$patchOp['responses']['200']['description'] = 'Validation passed successfully'; |
|
47
|
|
|
$patchOp['responses']['400'] = [ |
|
48
|
|
|
'description' => 'Validation failed', |
|
49
|
|
|
'schema' => [ |
|
50
|
|
|
'$ref' => '#/definitions/Form' |
|
51
|
|
|
] |
|
52
|
|
|
]; |
|
53
|
|
|
$patchOp['consumes'] = $docs['paths'][$currentPath]['put']['consumes']; |
|
54
|
|
|
$patchOp['produces'] = $docs['paths'][$currentPath]['put']['produces']; |
|
55
|
|
|
|
|
56
|
|
|
$docs['paths'][$patchOpPath]['patch'] = $patchOp; |
|
57
|
|
|
$docs['paths'][$patchOpPath]['post']['parameters'] = $docs['paths'][$patchOpPath]['patch']['parameters']; |
|
58
|
|
|
$docs['paths'][$patchOpPath]['post']['summary'] = 'Submit and validate the entire form'; |
|
59
|
|
|
|
|
60
|
|
|
return $docs; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
public function supportsNormalization($data, $format = null) |
|
64
|
|
|
{ |
|
65
|
2 |
|
return $this->decorated->supportsNormalization($data, $format); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|