mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
WIP parse phpdoc annotations in jms models
This commit is contained in:
parent
f03e33f551
commit
fe3629cdeb
@ -103,6 +103,8 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
|||||||
|
|
||||||
// read property options from Swagger Property annotation if it exists
|
// read property options from Swagger Property annotation if it exists
|
||||||
if (null !== $item->reflection) {
|
if (null !== $item->reflection) {
|
||||||
|
$phpdocReader = new PhpdocAnnotationReader();
|
||||||
|
$phpdocReader->updateWithPhpdoc($item->reflection, $realProp);
|
||||||
$this->swaggerPropertyAnnotationReader->updateWithSwaggerPropertyAnnotation($item->reflection, $realProp);
|
$this->swaggerPropertyAnnotationReader->updateWithSwaggerPropertyAnnotation($item->reflection, $realProp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
61
ModelDescriber/PhpdocAnnotationReader.php
Normal file
61
ModelDescriber/PhpdocAnnotationReader.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use EXSyst\Component\Swagger\Schema;
|
||||||
|
use EXSyst\Component\Swagger\Items;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
|
||||||
|
use phpDocumentor\Reflection\DocBlockFactory;
|
||||||
|
use phpDocumentor\Reflection\DocBlockFactoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class PhpdocAnnotationReader
|
||||||
|
{
|
||||||
|
private $docBlockFactory;
|
||||||
|
|
||||||
|
public function __construct(DocBlockFactoryInterface $docBlockFactory = null)
|
||||||
|
{
|
||||||
|
if (null === $docBlockFactory) {
|
||||||
|
$docBlockFactory = DocBlockFactory::createInstance();
|
||||||
|
}
|
||||||
|
$this->docBlockFactory = $docBlockFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \ReflectionProperty $reflectionProperty
|
||||||
|
* @param Items|Schema $property
|
||||||
|
*/
|
||||||
|
public function updateWithPhpdoc(\ReflectionProperty $reflectionProperty, $property)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$docBlock = $this->docBlockFactory->create($reflectionProperty);
|
||||||
|
if (!$title = $docBlock->getSummary()) {
|
||||||
|
/** @var Var_ $var */
|
||||||
|
foreach ($docBlock->getTagsByName('var') as $var) {
|
||||||
|
if (null === $description = $var->getDescription()) continue;
|
||||||
|
$title = $description->render();
|
||||||
|
if ($title) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($property->getTitle() === null && $title) {
|
||||||
|
$property->setTitle($title);
|
||||||
|
}
|
||||||
|
if ($property->getDescription() === null && $docBlock->getDescription()) {
|
||||||
|
$property->setDescription($docBlock->getDescription()->render());
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -151,7 +151,7 @@ serialization groups when using the Symfony serializer.
|
|||||||
### If you're using the JMS Serializer
|
### If you're using the JMS Serializer
|
||||||
|
|
||||||
The metadata of the JMS serializer are used by default to describe your
|
The metadata of the JMS serializer are used by default to describe your
|
||||||
models. Note that PHP doc blocks aren't supported in this case.
|
models.
|
||||||
|
|
||||||
In case you prefer using the [Symfony PropertyInfo component](https://symfony.com/doc/current/components/property_info.html) (you
|
In case you prefer using the [Symfony PropertyInfo component](https://symfony.com/doc/current/components/property_info.html) (you
|
||||||
won't be able to use JMS serialization groups), you can disable JMS serializer
|
won't be able to use JMS serialization groups), you can disable JMS serializer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user