|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SchemaAdditionalPropertiesHandler class file |
|
4
|
|
|
* adds the flexibility of render 'additionalProperties' in schema/swagger.json |
|
5
|
|
|
* in a proper way depending of the consumer |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Graviton\SchemaBundle\Serializer\Handler; |
|
9
|
|
|
|
|
10
|
|
|
use Graviton\SchemaBundle\Document\Schema; |
|
11
|
|
|
use Graviton\SchemaBundle\Document\SchemaAdditionalProperties; |
|
12
|
|
|
use JMS\Serializer\Context; |
|
13
|
|
|
use JMS\Serializer\JsonSerializationVisitor; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
17
|
|
|
* @license http://opensource.org/licenses/GPL GPL |
|
18
|
|
|
* @link http://swisscom.ch |
|
19
|
|
|
*/ |
|
20
|
|
|
class SchemaAdditionalPropertiesHandler |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Serialize additionalProperties to JSON |
|
25
|
|
|
* |
|
26
|
|
|
* @param JsonSerializationVisitor $visitor Visitor |
|
27
|
|
|
* @param SchemaAdditionalProperties $additionalProperties properties |
|
28
|
|
|
* @param array $type Type |
|
29
|
|
|
* @param Context $context Context |
|
30
|
|
|
* |
|
31
|
|
|
* @return string|null |
|
32
|
|
|
*/ |
|
33
|
|
|
public function serializeSchemaAdditionalPropertiesToJson( |
|
34
|
|
|
JsonSerializationVisitor $visitor, |
|
35
|
|
|
SchemaAdditionalProperties $additionalProperties, |
|
36
|
|
|
array $type, |
|
|
|
|
|
|
37
|
|
|
Context $context |
|
38
|
|
|
) { |
|
39
|
|
|
|
|
40
|
|
|
$properties = $additionalProperties->getProperties(); |
|
41
|
|
|
|
|
42
|
|
|
// case for v4 schema |
|
43
|
|
|
if (is_bool($properties)) { |
|
44
|
|
|
return $visitor->visitBoolean($properties, [], $context); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// case for schema inside additionalProperties, swagger exclusive |
|
48
|
|
|
if ($properties instanceof Schema) { |
|
49
|
|
|
return $visitor->getNavigator()->accept( |
|
50
|
|
|
$properties, |
|
51
|
|
|
['name' => 'Graviton\SchemaBundle\Document\Schema'], |
|
52
|
|
|
$context |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.