mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
tests passing with JmsMetadataParser, but work still to do on required and description properties
This commit is contained in:
parent
b71bc8bf3f
commit
149f282481
@ -35,16 +35,6 @@ class NelmioApiDocExtension extends Extension
|
|||||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
$loader->load('formatters.xml');
|
$loader->load('formatters.xml');
|
||||||
$loader->load('request_listener.xml');
|
$loader->load('request_listener.xml');
|
||||||
$loader->load('services.xml');
|
$loader->load('services.xml');
|
||||||
|
|
||||||
//JMS may or may not be installed, if it is, load that config as well
|
|
||||||
try {
|
|
||||||
if ($serializer = $container->findDefinition('serializer')) {
|
|
||||||
die(__METHOD__);
|
|
||||||
$loader->load('services.jms.xml');
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
DependencyInjection/RegisterJmsParserPass.php
Normal file
27
DependencyInjection/RegisterJmsParserPass.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||||
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
|
use Symfony\Component\Config\FileLocator;
|
||||||
|
|
||||||
|
class RegisterJmsParserPass implements CompilerPassInterface
|
||||||
|
{
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
|
|
||||||
|
//JMS may or may not be installed, if it is, load that config as well
|
||||||
|
try {
|
||||||
|
if ($serializer = $container->findDefinition('serializer')) {
|
||||||
|
$loader->load('services.jms.xml');
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace Nelmio\ApiDocBundle;
|
|||||||
|
|
||||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Nelmio\ApiDocBundle\DependencyInjection\RegisterJmsParserPass;
|
||||||
use Nelmio\ApiDocBundle\DependencyInjection\RegisterExtractorParsersPass;
|
use Nelmio\ApiDocBundle\DependencyInjection\RegisterExtractorParsersPass;
|
||||||
|
|
||||||
class NelmioApiDocBundle extends Bundle
|
class NelmioApiDocBundle extends Bundle
|
||||||
@ -12,6 +13,7 @@ class NelmioApiDocBundle extends Bundle
|
|||||||
{
|
{
|
||||||
parent::build($container);
|
parent::build($container);
|
||||||
|
|
||||||
|
$container->addCompilerPass(new RegisterJmsParserPass());
|
||||||
$container->addCompilerPass(new RegisterExtractorParsersPass());
|
$container->addCompilerPass(new RegisterExtractorParsersPass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,6 @@ class JmsMetadataParser implements ParserInterface
|
|||||||
*/
|
*/
|
||||||
public function parse($input)
|
public function parse($input)
|
||||||
{
|
{
|
||||||
die(__METHOD__);
|
|
||||||
|
|
||||||
$meta = $this->factory->getMetadataForClass($input);
|
$meta = $this->factory->getMetadataForClass($input);
|
||||||
|
|
||||||
if(is_null($meta)) {
|
if(is_null($meta)) {
|
||||||
@ -53,41 +51,35 @@ class JmsMetadataParser implements ParserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$params = array();
|
$params = array();
|
||||||
$refClass = new \ReflectionClass($input);
|
|
||||||
|
|
||||||
//iterate over property metadata
|
//iterate over property metadata
|
||||||
foreach ($meta->propertyMetadata as $item) {
|
foreach ($meta->propertyMetadata as $item) {
|
||||||
$name = isset($item->serializedName) ? $item->serializedName : $item->name;
|
|
||||||
|
|
||||||
$type = $this->getType($item->type);
|
if (!is_null($item->type)) {
|
||||||
|
$name = isset($item->serializedName) ? $item->serializedName : $item->name;
|
||||||
if (true) {
|
|
||||||
//TODO: check for nested type
|
//TODO: check for nested type
|
||||||
}
|
|
||||||
|
|
||||||
$params[$name] = array(
|
$params[$name] = array(
|
||||||
'dataType' => $item->type,
|
'dataType' => $item->type,
|
||||||
'required' => false, //can't think of a good way to specify this one, JMS doesn't have a setting for this
|
'required' => false, //TODO: can't think of a good way to specify this one, JMS doesn't have a setting for this
|
||||||
'description' => $this->getDescription($refClass, $item->name),
|
'description' => $this->getDescription($input, $item->name),
|
||||||
'readonly' => $item->readonly
|
'readonly' => $item->readOnly
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDescription($ref, $nativePropertyName)
|
protected function getDescription($className, $propertyName)
|
||||||
{
|
{
|
||||||
$description = "No description.";
|
$description = "No description.";
|
||||||
|
|
||||||
if (!$doc = $ref->getProperty($nativePropertyName)->getDocComment()) {
|
|
||||||
return $description;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: regex comment to get description - or move doc comment parsing functionality from `ApiDocExtractor` to a new location
|
//TODO: regex comment to get description - or move doc comment parsing functionality from `ApiDocExtractor` to a new location
|
||||||
//in order to reuse it here
|
//in order to reuse it here
|
||||||
|
|
||||||
return $description;
|
return $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
5
TODO.md
5
TODO.md
@ -1,5 +0,0 @@
|
|||||||
# TODO #
|
|
||||||
|
|
||||||
* Fix JMS registration by moving logic into a CompilerPass
|
|
||||||
* Finish `JmsMetadataParser`
|
|
||||||
* Implement new tests
|
|
@ -139,6 +139,32 @@ _Action without HTTP verb_
|
|||||||
|
|
||||||
_Testing JMS_
|
_Testing JMS_
|
||||||
|
|
||||||
|
#### Parameters ####
|
||||||
|
|
||||||
|
foo:
|
||||||
|
|
||||||
|
* type: string
|
||||||
|
* required: false
|
||||||
|
* description: No description.
|
||||||
|
|
||||||
|
bar:
|
||||||
|
|
||||||
|
* type: DateTime
|
||||||
|
* required: false
|
||||||
|
* description: No description.
|
||||||
|
|
||||||
|
number:
|
||||||
|
|
||||||
|
* type: double
|
||||||
|
* required: false
|
||||||
|
* description: No description.
|
||||||
|
|
||||||
|
arr:
|
||||||
|
|
||||||
|
* type: array
|
||||||
|
* required: false
|
||||||
|
* description: No description.
|
||||||
|
|
||||||
|
|
||||||
### `ANY` /my-commented/{id}/{page} ###
|
### `ANY` /my-commented/{id}/{page} ###
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user