From 149f282481997204e8ae760d656d49ee568792f2 Mon Sep 17 00:00:00 2001 From: Evan Villemez Date: Tue, 7 Aug 2012 21:47:33 -0400 Subject: [PATCH] tests passing with JmsMetadataParser, but work still to do on required and description properties --- DependencyInjection/NelmioApiDocExtension.php | 12 +------ DependencyInjection/RegisterJmsParserPass.php | 27 ++++++++++++++++ NelmioApiDocBundle.php | 2 ++ Parser/JmsMetadataParser.php | 32 +++++++------------ TODO.md | 5 --- Tests/Formatter/MarkdownFormatterTest.php | 26 +++++++++++++++ 6 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 DependencyInjection/RegisterJmsParserPass.php delete mode 100644 TODO.md diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 5aedd86..abf129a 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -35,16 +35,6 @@ class NelmioApiDocExtension extends Extension $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $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) { - - } + $loader->load('services.xml'); } } diff --git a/DependencyInjection/RegisterJmsParserPass.php b/DependencyInjection/RegisterJmsParserPass.php new file mode 100644 index 0000000..133610f --- /dev/null +++ b/DependencyInjection/RegisterJmsParserPass.php @@ -0,0 +1,27 @@ +findDefinition('serializer')) { + $loader->load('services.jms.xml'); + } + } catch (\Exception $e) { + } + + } +} diff --git a/NelmioApiDocBundle.php b/NelmioApiDocBundle.php index fbfe504..ad9a5ce 100644 --- a/NelmioApiDocBundle.php +++ b/NelmioApiDocBundle.php @@ -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()); } } diff --git a/Parser/JmsMetadataParser.php b/Parser/JmsMetadataParser.php index 8978de2..d9cb507 100644 --- a/Parser/JmsMetadataParser.php +++ b/Parser/JmsMetadataParser.php @@ -44,8 +44,6 @@ class JmsMetadataParser implements ParserInterface */ public function parse($input) { - die(__METHOD__); - $meta = $this->factory->getMetadataForClass($input); if(is_null($meta)) { @@ -53,41 +51,35 @@ class JmsMetadataParser implements ParserInterface } $params = array(); - $refClass = new \ReflectionClass($input); //iterate over property metadata foreach ($meta->propertyMetadata as $item) { - $name = isset($item->serializedName) ? $item->serializedName : $item->name; - $type = $this->getType($item->type); - - if (true) { + if (!is_null($item->type)) { + $name = isset($item->serializedName) ? $item->serializedName : $item->name; + //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 - ); + $params[$name] = array( + 'dataType' => $item->type, + '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 return $description; } - + } diff --git a/TODO.md b/TODO.md deleted file mode 100644 index f4d3408..0000000 --- a/TODO.md +++ /dev/null @@ -1,5 +0,0 @@ -# TODO # - -* Fix JMS registration by moving logic into a CompilerPass -* Finish `JmsMetadataParser` -* Implement new tests \ No newline at end of file diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php index 3e5653b..be436b5 100644 --- a/Tests/Formatter/MarkdownFormatterTest.php +++ b/Tests/Formatter/MarkdownFormatterTest.php @@ -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} ###