2017-12-03 20:30:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the NelmioApiDocBundle package.
|
|
|
|
*
|
|
|
|
* (c) Nelmio
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Nelmio\ApiDocBundle\ModelDescriber;
|
|
|
|
|
2017-12-17 10:44:07 +01:00
|
|
|
use Doctrine\Common\Annotations\Reader;
|
2017-12-03 20:30:44 +02:00
|
|
|
use EXSyst\Component\Swagger\Items;
|
2017-12-17 10:44:07 +01:00
|
|
|
use EXSyst\Component\Swagger\Schema;
|
2017-12-03 20:30:44 +02:00
|
|
|
use Swagger\Annotations\Property as SwgProperty;
|
2017-12-17 17:58:41 +02:00
|
|
|
use const Swagger\Annotations\UNDEFINED;
|
2017-12-03 20:30:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
class SwaggerPropertyAnnotationReader
|
|
|
|
{
|
|
|
|
private $annotationsReader;
|
|
|
|
|
|
|
|
public function __construct(Reader $annotationsReader)
|
|
|
|
{
|
|
|
|
$this->annotationsReader = $annotationsReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \ReflectionProperty $reflectionProperty
|
|
|
|
* @param Items|Schema $property
|
|
|
|
*/
|
|
|
|
public function updateWithSwaggerPropertyAnnotation(\ReflectionProperty $reflectionProperty, $property)
|
|
|
|
{
|
|
|
|
$swgProperty = $this->annotationsReader->getPropertyAnnotation($reflectionProperty, SwgProperty::class);
|
|
|
|
if ($swgProperty instanceof SwgProperty) {
|
2017-12-17 17:58:41 +02:00
|
|
|
if ($swgProperty->type !== null) {
|
2017-12-03 20:30:44 +02:00
|
|
|
$property->setType($swgProperty->type);
|
|
|
|
}
|
2017-12-17 17:58:41 +02:00
|
|
|
if ($swgProperty->default !== UNDEFINED) {
|
|
|
|
$property->setDefault($swgProperty->default);
|
|
|
|
}
|
|
|
|
if ($swgProperty->enum !== null) {
|
|
|
|
$property->setEnum($swgProperty->enum);
|
2017-12-03 20:30:44 +02:00
|
|
|
}
|
2017-12-15 17:39:18 +01:00
|
|
|
if ($property instanceof Schema) {
|
2017-12-17 17:58:41 +02:00
|
|
|
if ($swgProperty->description !== null) {
|
2017-12-15 17:39:18 +01:00
|
|
|
$property->setDescription($swgProperty->description);
|
|
|
|
}
|
2017-12-17 17:58:41 +02:00
|
|
|
if ($swgProperty->title !== null) {
|
2017-12-15 17:39:18 +01:00
|
|
|
$property->setTitle($swgProperty->title);
|
|
|
|
}
|
2017-12-17 17:58:41 +02:00
|
|
|
if ($swgProperty->example !== null) {
|
|
|
|
$property->setExample($swgProperty->example);
|
|
|
|
}
|
|
|
|
if ($swgProperty->readOnly !== null) {
|
|
|
|
$property->setReadOnly($swgProperty->readOnly);
|
2017-12-15 17:39:18 +01:00
|
|
|
}
|
2017-12-03 20:30:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|