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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 10:44:07 +01:00
|
|
|
if (null !== $swgProperty->type) {
|
2017-12-03 20:30:44 +02:00
|
|
|
$property->setType($swgProperty->type);
|
|
|
|
}
|
2017-12-17 10:44:07 +01:00
|
|
|
if (null !== $swgProperty->readOnly) {
|
2017-12-03 20:30:44 +02:00
|
|
|
$property->setReadOnly($swgProperty->readOnly);
|
|
|
|
}
|
2017-12-15 17:39:18 +01:00
|
|
|
if ($property instanceof Schema) {
|
2017-12-17 10:44:07 +01:00
|
|
|
if (null !== $swgProperty->description) {
|
2017-12-15 17:39:18 +01:00
|
|
|
$property->setDescription($swgProperty->description);
|
|
|
|
}
|
2017-12-17 10:44:07 +01:00
|
|
|
if (null !== $swgProperty->title) {
|
2017-12-15 17:39:18 +01:00
|
|
|
$property->setTitle($swgProperty->title);
|
|
|
|
}
|
2017-12-17 10:44:07 +01:00
|
|
|
if (null !== $swgProperty->example) {
|
2017-12-15 17:39:18 +01:00
|
|
|
$property->setExample((string) $swgProperty->example);
|
|
|
|
}
|
2017-12-03 20:30:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|