Merge pull request #585 from dunglas/dunglasjsonldapibundle

DunglasJsonLdApiBundle support
This commit is contained in:
William Durand 2015-03-20 10:51:03 +01:00
commit 26fe302a5a
25 changed files with 6091 additions and 2108 deletions

View File

@ -12,13 +12,17 @@ matrix:
env: SYMFONY_VERSION='2.3.*'
- php: 5.5
env: SYMFONY_VERSION='2.4.*'
- php: 5.5
env: SYMFONY_VERSION='2.6.*'
- php: 5.5
env: SYMFONY_VERSION='dev-master'
allow_failures:
- env: SYMFONY_VERSION=dev-master
- php: 5.5
env: SYMFONY_VERSION='dev-master'
before_script:
- composer self-update
- sh -c 'if [ "$SYMFONY_VERSION" != "dev-master" ] && [ "$SYMFONY_VERSION" != "2.6.*" ]; then sed -i "/dunglas\/json-ld-api-bundle/d;/symfony\/serializer/d" composer.json; fi;'
- sh -c 'if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/symfony=$SYMFONY_VERSION; fi;'
- composer install

View File

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* AnnotationsProvider compiler pass.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class AnnotationsProviderCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$annotationsProviders = array();
foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.annotations_provider') as $id => $attributes) {
$annotationsProviders[] = new Reference($id);
}
$container
->getDefinition('nelmio_api_doc.extractor.api_doc_extractor')
->replaceArgument(6, $annotationsProviders)
;
}
}

View File

@ -29,6 +29,6 @@ class ExtractorHandlerCompilerPass implements CompilerPassInterface
$container
->getDefinition('nelmio_api_doc.extractor.api_doc_extractor')
->replaceArgument(4, $handlers);
->replaceArgument(5, $handlers);
}
}

View File

@ -32,5 +32,10 @@ class LoadExtractorParsersPass implements CompilerPassInterface
if ($container->hasDefinition('jms_serializer.serializer')) {
$loader->load('services.jms.xml');
}
// DunglasJsonLdApiBundle may or may not be installed, if it is, load that config as well
if ($container->hasDefinition('dunglas_json_ld_api.resources')) {
$loader->load('services.dunglas_json_ld_api.xml');
}
}
}

View File

@ -0,0 +1,95 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Extractor\AnnotationsProvider;
use Doctrine\Common\Annotations\Reader;
use Dunglas\JsonLdApiBundle\JsonLd\Resource;
use Dunglas\JsonLdApiBundle\JsonLd\Resources;
use Dunglas\JsonLdApiBundle\Mapping\ClassMetadataFactory;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\Extractor\AnnotationsProviderInterface;
/**
* Creates ApiDoc annotations for DunglasJsonLdApiBundle.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DunglasJsonLdApiProvider implements AnnotationsProviderInterface
{
/**
* @var Resources
*/
private $resources;
/**
* @var ClassMetadataFactory
*/
private $classMetadataFactory;
public function __construct(Resources $resources, ClassMetadataFactory $classMetadataFactory)
{
$this->resources = $resources;
$this->classMetadataFactory = $classMetadataFactory;
}
/**
* {@inheritdoc}
*/
public function getAnnotations()
{
$annotations = [];
foreach ($this->resources as $resource) {
$resource->getRouteCollection(); // Populate !route
foreach ($resource->getCollectionOperations() as $operation) {
$annotations[] = $this->getApiDoc($resource, $operation);
}
foreach ($resource->getItemOperations() as $operation) {
$annotations[] = $this->getApiDoc($resource, $operation);
}
}
return $annotations;
}
/**
* Builds ApiDoc annotation from DunglasJsonLdApiBundle data.
*
* @param Resource $resource
* @param array $operation
*
* @return ApiDoc
*/
private function getApiDoc(Resource $resource, array $operation)
{
$data = [
'resource' => $operation['!route_path'],
'description' => $operation['rdfs:label'],
'resourceDescription' => $this->classMetadataFactory->getMetadataFor($resource->getEntityClass())->getDescription(),
];
if (isset($operation['expects']) && $operation['expects'] !== 'owl:Nothing') {
$data['input'] = $resource->getEntityClass();
}
if (isset($operation['returns']) && $operation['returns'] !== 'owl:Nothing') {
$data['output'] = $resource->getEntityClass();
}
$data['filters'] = $resource->getFilters();
$apiDoc = new ApiDoc($data);
$apiDoc->setRoute($operation['!route']);
return $apiDoc;
}
}

View File

@ -0,0 +1,29 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Extractor;
use Symfony\Component\Routing\Route;
/**
* Interface for annotations providers.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
interface AnnotationsProviderInterface
{
/**
* Returns an array ApiDoc annotations.
*
* @return \Nelmio\ApiDocBundle\Annotation\ApiDoc[]
*/
public function getAnnotations();
}

View File

@ -18,6 +18,7 @@ use Nelmio\ApiDocBundle\DataTypes;
use Nelmio\ApiDocBundle\Parser\ParserInterface;
use Nelmio\ApiDocBundle\Parser\PostParserInterface;
use Nelmio\ApiDocBundle\Util\DocCommentExtractor;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
@ -47,6 +48,11 @@ class ApiDocExtractor
*/
private $commentExtractor;
/**
* @var ControllerNameParser
*/
protected $controllerNameParser;
/**
* @var ParserInterface[]
*/
@ -57,13 +63,20 @@ class ApiDocExtractor
*/
protected $handlers;
public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, array $handlers)
/**
* @var AnnotationsProviderInterface[]
*/
protected $annotationsProviders;
public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, ControllerNameParser $controllerNameParser, array $handlers, array $annotationsProviders)
{
$this->container = $container;
$this->router = $router;
$this->reader = $reader;
$this->commentExtractor = $commentExtractor;
$this->handlers = $handlers;
$this->container = $container;
$this->router = $router;
$this->reader = $reader;
$this->commentExtractor = $commentExtractor;
$this->controllerNameParser = $controllerNameParser;
$this->handlers = $handlers;
$this->annotationsProviders = $annotationsProviders;
}
/**
@ -125,6 +138,13 @@ class ApiDocExtractor
}
}
foreach ($this->annotationsProviders as $annotationProvider) {
foreach ($annotationProvider->getAnnotations() as $annotation) {
$route = $annotation->getRoute();
$array[] = array('annotation' => $this->extractData($annotation, $route, $this->getReflectionMethod($route->getDefault('_controller'))));
}
}
rsort($resources);
foreach ($array as $index => $element) {
$hasResource = false;
@ -181,6 +201,10 @@ class ApiDocExtractor
*/
public function getReflectionMethod($controller)
{
if (false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
$controller = $this->controllerNameParser->parse($controller);
}
if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) {
$class = $matches[1];
$method = $matches[2];

View File

@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Extractor;
use Doctrine\Common\Annotations\Reader;
use Nelmio\ApiDocBundle\Util\DocCommentExtractor;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -37,11 +38,13 @@ class CachingApiDocExtractor extends ApiDocExtractor
RouterInterface $router,
Reader $reader,
DocCommentExtractor $commentExtractor,
ControllerNameParser $controllerNameParser,
array $handlers,
array $annotationsProviders,
$cacheFile,
$debug = false
) {
parent::__construct($container, $router, $reader, $commentExtractor, $handlers);
parent::__construct($container, $router, $reader, $commentExtractor, $controllerNameParser, $handlers, $annotationsProviders);
$this->cacheFile = $cacheFile;
$this->cache = new ConfigCache($this->cacheFile, $debug);
}

View File

@ -2,6 +2,7 @@
namespace Nelmio\ApiDocBundle;
use Nelmio\ApiDocBundle\DependencyInjection\AnnotationsProviderCompilerPass;
use Nelmio\ApiDocBundle\DependencyInjection\SwaggerConfigCompilerPass;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -18,6 +19,7 @@ class NelmioApiDocBundle extends Bundle
$container->addCompilerPass(new LoadExtractorParsersPass());
$container->addCompilerPass(new RegisterExtractorParsersPass());
$container->addCompilerPass(new ExtractorHandlerCompilerPass());
$container->addCompilerPass(new AnnotationsProviderCompilerPass());
$container->addCompilerPass(new SwaggerConfigCompilerPass());
}
}

View File

@ -0,0 +1,93 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Parser;
use Dunglas\JsonLdApiBundle\JsonLd\Resources;
use Dunglas\JsonLdApiBundle\Mapping\ClassMetadataFactory;
use Nelmio\ApiDocBundle\DataTypes;
/**
* Use DunglasJsonLdApi to extract input and output information.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DunglasJsonLdApiParser implements ParserInterface
{
/**
* @var Resources
*/
private $resources;
/**
* @var ClassMetadataFactory
*/
private $classMetadataFactory;
public function __construct(Resources $resources, ClassMetadataFactory $classMetadataFactory)
{
$this->resources = $resources;
$this->classMetadataFactory = $classMetadataFactory;
}
/**
* {@inheritdoc}
*/
public function supports(array $item)
{
return null !== $this->resources->getResourceForEntity($item['class']);
}
/**
* {@inheritdoc}
*/
public function parse(array $item)
{
/**
* @var $resource \Dunglas\JsonLdApiBundle\JsonLd\Resource
*/
$resource = $this->resources->getResourceForEntity($item['class']);
$classMetadata = $this->classMetadataFactory->getMetadataFor(
$resource->getEntityClass(),
$resource->getNormalizationGroups(),
$resource->getDenormalizationGroups(),
$resource->getValidationGroups()
);
$data = array();
foreach ($classMetadata->getAttributes() as $attribute) {
$data[$attribute->getName()] = [
'required' => $attribute->isRequired(),
'description' => $attribute->getDescription(),
'readonly' => $attribute->isReadable() && !$attribute->isWritable(),
'class' => $resource->getEntityClass(),
];
if (isset($attribute->getTypes()[0])) {
$type = $attribute->getTypes()[0];
if ($type->isCollection()) {
$dataType = DataTypes::COLLECTION;
} elseif ('object' === $type->getType()) {
if ('DateTime' === $type->getClass()) {
$dataType = DataTypes::DATETIME;
} else {
$dataType = DataTypes::STRING;
}
} else {
$dataType = $type->getType();
}
$data[$attribute->getName()]['dataType'] = $dataType;
}
}
return $data;
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="nelmio_api_doc.annotations_provider.dunglas_json_ld_api_annotation_provider" class="Nelmio\ApiDocBundle\Extractor\AnnotationsProvider\DunglasJsonLdApiProvider">
<argument type="service" id="dunglas_json_ld_api.resources" />
<argument type="service" id="dunglas_json_ld_api.mapping.class_metadata_factory" />
<tag name="nelmio_api_doc.extractor.annotations_provider" />
</service>
<service id="nelmio_api_doc.parser.dunglas_json_ld_api_parser" class="Nelmio\ApiDocBundle\Parser\DunglasJsonLdApiParser">
<argument type="service" id="dunglas_json_ld_api.resources" />
<argument type="service" id="dunglas_json_ld_api.mapping.class_metadata_factory" />
<tag name="nelmio_api_doc.extractor.parser" />
</service>
</services>
</container>

View File

@ -19,14 +19,20 @@
</parameters>
<services>
<service id='nelmio_api_doc.doc_comment_extractor' class="%nelmio_api_doc.doc_comment_extractor.class%" />
<service id="nelmio_api_doc.doc_comment_extractor" class="%nelmio_api_doc.doc_comment_extractor.class%" />
<service id="nelmio_api_doc.controller_name_parser" class="Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser" public="false">
<argument type="service" id="kernel" />
</service>
<service id="nelmio_api_doc.extractor.api_doc_extractor" class="%nelmio_api_doc.extractor.api_doc_extractor.class%">
<argument type="service" id="service_container"/>
<argument type="service" id="service_container" />
<argument type="service" id="router" />
<argument type="service" id="annotation_reader" />
<argument type="service" id="nelmio_api_doc.doc_comment_extractor" />
<argument type="collection"/>
<argument type="service" id="nelmio_api_doc.controller_name_parser" />
<argument type="collection" />
<argument type="collection" />
</service>
<service id="nelmio_api_doc.form.extension.description_form_type_extension" class="%nelmio_api_doc.form.extension.description_form_type_extension.class%">

View File

@ -0,0 +1,44 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Tests\Extractor\AnnotationsProvider;
use Nelmio\ApiDocBundle\Tests\WebTestCase;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DunglasJsonLdApiProviderTest extends WebTestCase
{
protected function setUp()
{
if (!class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) {
$this->markTestSkipped(
'DunglasJsonLdApiBundle is not available.'
);
}
}
public function testGetAnnotations()
{
$container = $this->getContainer();
$provider = $container->get('nelmio_api_doc.annotations_provider.dunglas_json_ld_api_annotation_provider');
$annotations = $provider->getAnnotations();
$this->assertCount(5, $annotations);
foreach ($annotations as $annotation) {
$this->assertInstanceOf('Nelmio\ApiDocBundle\Annotation\ApiDoc', $annotation);
$this->assertInstanceOf('Symfony\Component\Routing\Route', $annotation->getRoute());
$this->assertTrue('' != $annotation->getDescription());
}
}
}

View File

@ -17,8 +17,6 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
class ApiDocExtractorTest extends WebTestCase
{
const ROUTES_QUANTITY = 33;
public function testAll()
{
$container = $this->getContainer();
@ -27,14 +25,22 @@ class ApiDocExtractorTest extends WebTestCase
$data = $extractor->all();
restore_error_handler();
if(class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) {
$routesQuantity = 38;
$httpsKey = 25;
} else {
$routesQuantity = 33;
$httpsKey = 20;
}
$this->assertTrue(is_array($data));
$this->assertCount(self::ROUTES_QUANTITY, $data);
$this->assertCount($routesQuantity, $data);
$cacheFile = $container->getParameter('kernel.cache_dir') . '/api-doc.cache';
$this->assertFileExists($cacheFile);
$this->assertEquals(file_get_contents($cacheFile), serialize($data));
foreach ($data as $d) {
foreach ($data as $key => $d) {
$this->assertTrue(is_array($d));
$this->assertArrayHasKey('annotation', $d);
$this->assertArrayHasKey('resource', $d);
@ -76,9 +82,8 @@ class ApiDocExtractorTest extends WebTestCase
$this->assertTrue($a4->isResource());
$this->assertEquals('TestResource', $a4->getResource());
$a3 = $data[20]['annotation'];
$a3 = $data[$httpsKey]['annotation'];
$this->assertTrue($a3->getHttps());
}
public function testGet()

View File

@ -0,0 +1,28 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Model;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class Popo
{
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $foo;
}

View File

@ -26,17 +26,20 @@ class AppKernel extends Kernel
public function registerBundles()
{
return array(
$bundles = array(
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \JMS\SerializerBundle\JMSSerializerBundle($this),
new \Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new \Nelmio\ApiDocBundle\Tests\Fixtures\NelmioApiDocTestBundle(),
);
}
public function init()
{
if (class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) {
$bundles[] = new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle();
$bundles[] = new \Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle();
}
return $bundles;
}
public function getRootDir()
@ -57,6 +60,10 @@ class AppKernel extends Kernel
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/'.$this->environment.'.yml');
if (class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) {
$loader->load(__DIR__.'/config/dunglas_json_ld_api.yml');
}
}
public function serialize()

View File

@ -0,0 +1,22 @@
doctrine:
dbal:
driver: "pdo_sqlite"
path: "%kernel.cache_dir%/db.sqlite"
charset: "UTF8"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
framework:
router: { resource: "%kernel.root_dir%/config/dunglas_json_ld_api_routing.yml" }
dunglas_json_ld_api:
title: API
description: Test API
services:
dunglas_json_ld_api.popo:
class: "Dunglas\JsonLdApiBundle\JsonLd\Resource"
arguments: [ "Nelmio\\ApiDocBundle\\Tests\\Fixtures\\Model\\Popo" ]
tags: [ { name: "json-ld.resource" } ]

View File

@ -0,0 +1,9 @@
main:
resource: "routing.yml"
dunglas_json_ld_api_doc:
resource: "@DunglasJsonLdApiBundle/Resources/config/routing.xml"
dunglas_json_ld_api:
resource: "."
type: "json-ld"

View File

@ -239,3 +239,4 @@ test_route_25:
defaults: { _controller: NelmioApiDocTestBundle:Test:withLinkAction }
requirements:
_method: GET

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -45,54 +45,137 @@ class SwaggerFormatterTest extends WebTestCase
$actual = $this->formatter->format($data, null);
$expected = array(
'swaggerVersion' => '1.2',
'apiVersion' => '3.14',
'info' =>
array(
'title' => 'Nelmio Swagger',
'description' => 'Testing Swagger integration.',
'TermsOfServiceUrl' => 'https://github.com',
'contact' => 'user@domain.tld',
'license' => 'MIT',
'licenseUrl' => 'http://opensource.org/licenses/MIT',
),
'authorizations' =>
array(
'apiKey' => array(
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
)
),
'apis' =>
array(
array(
'path' => '/other-resources',
'description' => 'Operations on another resource.',
if (class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) {
$expected = array (
'swaggerVersion' => '1.2',
'apis' =>
array (
0 =>
array (
'path' => '/other-resources',
'description' => 'Operations on another resource.',
),
1 =>
array (
'path' => '/resources',
'description' => 'Operations on resource.',
),
2 =>
array (
'path' => '/tests',
'description' => NULL,
),
3 =>
array (
'path' => '/tests',
'description' => NULL,
),
4 =>
array (
'path' => '/tests2',
'description' => NULL,
),
5 =>
array (
'path' => '/TestResource',
'description' => NULL,
),
6 =>
array (
'path' => '/others',
'description' => '',
),
7 =>
array (
'path' => '/others',
'description' => '',
),
8 =>
array (
'path' => '/others',
'description' => '',
),
9 =>
array (
'path' => '/others',
'description' => '',
),
10 =>
array (
'path' => '/others',
'description' => '',
),
),
array(
'path' => '/resources',
'description' => 'Operations on resource.',
'apiVersion' => '3.14',
'info' =>
array (
'title' => 'Nelmio Swagger',
'description' => 'Testing Swagger integration.',
'TermsOfServiceUrl' => 'https://github.com',
'contact' => 'user@domain.tld',
'license' => 'MIT',
'licenseUrl' => 'http://opensource.org/licenses/MIT',
),
array(
'path' => '/tests',
'description' => null,
'authorizations' =>
array (
'apiKey' =>
array (
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
),
),
);
} else {
$expected = array(
'swaggerVersion' => '1.2',
'apiVersion' => '3.14',
'info' =>
array(
'path' => '/tests',
'description' => null,
'title' => 'Nelmio Swagger',
'description' => 'Testing Swagger integration.',
'TermsOfServiceUrl' => 'https://github.com',
'contact' => 'user@domain.tld',
'license' => 'MIT',
'licenseUrl' => 'http://opensource.org/licenses/MIT',
),
'authorizations' =>
array(
'path' => '/tests2',
'description' => null,
'apiKey' => array(
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
)
),
'apis' =>
array(
'path' => '/TestResource',
'description' => null,
array(
'path' => '/other-resources',
'description' => 'Operations on another resource.',
),
array(
'path' => '/resources',
'description' => 'Operations on resource.',
),
array(
'path' => '/tests',
'description' => null,
),
array(
'path' => '/tests',
'description' => null,
),
array(
'path' => '/tests2',
'description' => null,
),
array(
'path' => '/TestResource',
'description' => null,
),
),
),
);
);
}
$this->assertEquals($expected, $actual);

View File

@ -0,0 +1,51 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NelmioApiDocBundle\Tests\Parser;
use Nelmio\ApiDocBundle\Tests\WebTestCase;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DunglasJsonLdApiParserTest extends WebTestCase
{
protected function setUp()
{
if (!class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) {
$this->markTestSkipped(
'DunglasJsonLdApiBundle is not available.'
);
}
}
public function testParser()
{
$container = $this->getContainer();
$parser = $container->get('nelmio_api_doc.parser.dunglas_json_ld_api_parser');
$item = array('class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo');
$expected = array (
'foo' =>
array (
'required' => false,
'description' => '',
'readonly' => false,
'class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo',
'dataType' => 'string',
),
);
$this->assertTrue($parser->supports($item));
$this->assertEquals($expected, $parser->parse($item));
}
}

View File

@ -25,7 +25,11 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
$formFactoryBuilder->addTypeExtension(new DescriptionFormTypeExtension());
$formFactory = $formFactoryBuilder->getFormFactory();
$formTypeParser = new FormTypeParser($formFactory);
set_error_handler(array('Nelmio\ApiDocBundle\Tests\WebTestCase', 'handleDeprecation'));
trigger_error('test', E_USER_DEPRECATED);
$output = $formTypeParser->parse($typeName);
restore_error_handler();
$this->assertEquals($expected, $output);
}

View File

@ -30,14 +30,17 @@
"symfony/validator": "~2.1",
"symfony/yaml": "~2.1",
"symfony/form": "~2.1",
"symfony/serializer": "~2.7@dev",
"friendsofsymfony/rest-bundle": "~1.0",
"jms/serializer-bundle": ">=0.11",
"dunglas/json-ld-api-bundle": "dev-master",
"sensio/framework-extra-bundle": "~3.0"
},
"suggest": {
"symfony/form": "For using form definitions as input.",
"symfony/validator": "For making use of validator information in the doc.",
"friendsofsymfony/rest-bundle": "For making use of REST information in the doc.",
"dunglas/json-ld-api-bundle": "For making use of resources definitions of DunglasJsonLdApiBundle.",
"jms/serializer": "For making use of serializer information in the doc."
},
"autoload": {