This commit is contained in:
Evan Villemez 2012-08-07 21:57:36 -04:00
parent 149f282481
commit 68767f6c72
7 changed files with 25 additions and 30 deletions

View File

@ -35,6 +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');
} }
} }

View File

@ -4,9 +4,7 @@ namespace Nelmio\ApiDocBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
class RegisterJmsParserPass implements CompilerPassInterface class RegisterJmsParserPass implements CompilerPassInterface
@ -14,7 +12,7 @@ class RegisterJmsParserPass implements CompilerPassInterface
public function process(ContainerBuilder $container) public function process(ContainerBuilder $container)
{ {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
//JMS may or may not be installed, if it is, load that config as well //JMS may or may not be installed, if it is, load that config as well
try { try {
if ($serializer = $container->findDefinition('serializer')) { if ($serializer = $container->findDefinition('serializer')) {

View File

@ -18,7 +18,7 @@ use Metadata\MetadataFactoryInterface;
*/ */
class JmsMetadataParser implements ParserInterface class JmsMetadataParser implements ParserInterface
{ {
/** /**
* Constructor, requires JMS Metadata factory * Constructor, requires JMS Metadata factory
*/ */
@ -26,19 +26,19 @@ class JmsMetadataParser implements ParserInterface
{ {
$this->factory = $factory; $this->factory = $factory;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function supports($input) public function supports($input)
{ {
if($meta = $this->factory->getMetadataForClass($input)) { if ($meta = $this->factory->getMetadataForClass($input)) {
return true; return true;
} }
return false; return false;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -46,20 +46,20 @@ class JmsMetadataParser implements ParserInterface
{ {
$meta = $this->factory->getMetadataForClass($input); $meta = $this->factory->getMetadataForClass($input);
if(is_null($meta)) { if (is_null($meta)) {
throw new \InvalidArgumentException(sprintf("No metadata found for class %s", $input)); throw new \InvalidArgumentException(sprintf("No metadata found for class %s", $input));
} }
$params = array(); $params = array();
//iterate over property metadata //iterate over property metadata
foreach ($meta->propertyMetadata as $item) { foreach ($meta->propertyMetadata as $item) {
if (!is_null($item->type)) { if (!is_null($item->type)) {
$name = isset($item->serializedName) ? $item->serializedName : $item->name; $name = isset($item->serializedName) ? $item->serializedName : $item->name;
//TODO: check for nested type //TODO: check for nested type
$params[$name] = array( $params[$name] = array(
'dataType' => $item->type, '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 'required' => false, //TODO: can't think of a good way to specify this one, JMS doesn't have a setting for this
@ -68,17 +68,16 @@ class JmsMetadataParser implements ParserInterface
); );
} }
} }
return $params; return $params;
} }
protected function getDescription($className, $propertyName) protected function getDescription($className, $propertyName)
{ {
$description = "No description."; $description = "No 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;
} }

View File

@ -90,7 +90,7 @@ class TestController
public function zActionWithQueryParamAction() public function zActionWithQueryParamAction()
{ {
} }
/** /**
* @ApiDoc( * @ApiDoc(
* description="Testing JMS", * description="Testing JMS",

View File

@ -7,27 +7,27 @@ use JMS\SerializerBundle\Annotation as JMS;
class JmsTest class JmsTest
{ {
public $nothing; public $nothing;
/** /**
* @JMS\Type("string"); * @JMS\Type("string");
*/ */
public $foo; public $foo;
/** /**
* @JMS\Type("DateTime"); * @JMS\Type("DateTime");
* @JMS\ReadOnly * @JMS\ReadOnly
*/ */
public $bar; public $bar;
/** /**
* @JMS\Type("double"); * @JMS\Type("double");
* @JMS\SerializedName("number"); * @JMS\SerializedName("number");
*/ */
public $baz; public $baz;
/** /**
* @JMS\Type("array"); * @JMS\Type("array");
*/ */
public $arr; public $arr;
} }

View File

@ -55,4 +55,3 @@ jms_serializer:
# class: My\FooBundle\Entity\User # class: My\FooBundle\Entity\User
# expected path: @MyFooBundle/Resources/config/serializer/Entity.User.(yml|xml|php) # expected path: @MyFooBundle/Resources/config/serializer/Entity.User.(yml|xml|php)
auto_detection: true auto_detection: true

View File

@ -69,4 +69,3 @@ test_service_route_4:
NelmioApiDocBundle: NelmioApiDocBundle:
resource: "@NelmioApiDocBundle/Resources/config/routing.yml" resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
prefix: / prefix: /