tests passing with JmsMetadataParser, but work still to do on required and description properties

This commit is contained in:
Evan Villemez 2012-08-07 21:47:33 -04:00
parent b71bc8bf3f
commit 149f282481
6 changed files with 68 additions and 36 deletions

View File

@ -36,15 +36,5 @@ class NelmioApiDocExtension extends Extension
$loader->load('formatters.xml');
$loader->load('request_listener.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) {
}
}
}

View 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) {
}
}
}

View File

@ -4,6 +4,7 @@ namespace Nelmio\ApiDocBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Nelmio\ApiDocBundle\DependencyInjection\RegisterJmsParserPass;
use Nelmio\ApiDocBundle\DependencyInjection\RegisterExtractorParsersPass;
class NelmioApiDocBundle extends Bundle
@ -12,6 +13,7 @@ class NelmioApiDocBundle extends Bundle
{
parent::build($container);
$container->addCompilerPass(new RegisterJmsParserPass());
$container->addCompilerPass(new RegisterExtractorParsersPass());
}
}

View File

@ -44,8 +44,6 @@ class JmsMetadataParser implements ParserInterface
*/
public function parse($input)
{
die(__METHOD__);
$meta = $this->factory->getMetadataForClass($input);
if(is_null($meta)) {
@ -53,37 +51,31 @@ class JmsMetadataParser implements ParserInterface
}
$params = array();
$refClass = new \ReflectionClass($input);
//iterate over property metadata
foreach ($meta->propertyMetadata as $item) {
if (!is_null($item->type)) {
$name = isset($item->serializedName) ? $item->serializedName : $item->name;
$type = $this->getType($item->type);
if (true) {
//TODO: check for nested type
}
$params[$name] = array(
'dataType' => $item->type,
'required' => false, //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),
'readonly' => $item->readonly
'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($input, $item->name),
'readonly' => $item->readOnly
);
}
}
return $params;
}
protected function getDescription($ref, $nativePropertyName)
protected function getDescription($className, $propertyName)
{
$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
//in order to reuse it here

View File

@ -1,5 +0,0 @@
# TODO #
* Fix JMS registration by moving logic into a CompilerPass
* Finish `JmsMetadataParser`
* Implement new tests

View File

@ -139,6 +139,32 @@ _Action without HTTP verb_
_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} ###