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
|
|
|
public function __construct(NormalizerInterface $decorated) |
12
|
|
|
{ |
13
|
|
|
$this->decorated = $decorated; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function normalize($object, $format = null, array $context = []) |
17
|
|
|
{ |
18
|
|
|
$docs = $this->decorated->normalize($object, $format, $context); |
19
|
|
|
|
20
|
|
|
$patchOpPath = '/forms/{id}/submit'; |
21
|
|
|
$patchOp = $docs['paths'][$patchOpPath]['patch']; |
22
|
|
|
$patchOp['summary'] = 'Submit a single input for validation'; |
23
|
|
|
$patchOp['parameters'] = $docs['paths']['/forms/{id}']['get']['parameters']; |
24
|
|
|
$patchOp['parameters'][] = [ |
25
|
|
|
'name' => 'form', |
26
|
|
|
'in' => 'body', |
27
|
|
|
'required' => false, |
28
|
|
|
'schema' => [ |
29
|
|
|
'type' => 'object', |
30
|
|
|
'properties' => [ |
31
|
|
|
'form_name' => [ |
32
|
|
|
'type' => 'object', |
33
|
|
|
'properties' => [ |
34
|
|
|
'input_name' => [ |
35
|
|
|
'type' => 'string' |
36
|
|
|
] |
37
|
|
|
] |
38
|
|
|
] |
39
|
|
|
] |
40
|
|
|
] |
41
|
|
|
]; |
42
|
|
|
$patchOp['responses'] = $docs['paths']['/forms/{id}']['get']['responses']; |
43
|
|
|
$patchOp['responses']['200']['description'] = "Validation passed successfully"; |
44
|
|
|
$patchOp['responses']['400'] = [ |
45
|
|
|
'description' => "Validation failed", |
46
|
|
|
'schema' => [ |
47
|
|
|
'$ref' => '#/definitions/Form-page' |
48
|
|
|
] |
49
|
|
|
]; |
50
|
|
|
// $patchOp['responses']['406']['description'] = "Invalid field name for the form ID"; |
51
|
|
|
$patchOp['consumes'] = $docs['paths']['/forms/{id}']['put']['consumes']; |
52
|
|
|
$patchOp['produces'] = $docs['paths']['/forms/{id}']['put']['produces']; |
53
|
|
|
|
54
|
|
|
$docs['paths'][$patchOpPath]['patch'] = $patchOp; |
55
|
|
|
$docs['paths'][$patchOpPath]['post']['parameters'] = $docs['paths'][$patchOpPath]['patch']['parameters']; |
56
|
|
|
$docs['paths'][$patchOpPath]['post']['summary'] = 'Submit and validate the entire form'; |
57
|
|
|
// $docs['paths'][$patchOpPath]['post']['parameters'] = $patchOp['parameters']; |
58
|
|
|
// $docs['paths'][$patchOpPath]['post']['responses']['201']['description'] = "Form successfully submitted and valid"; |
59
|
|
|
|
60
|
|
|
return $docs; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function supportsNormalization($data, $format = null) |
64
|
|
|
{ |
65
|
|
|
return $this->decorated->supportsNormalization($data, $format); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|