From 79c1c4e4f4b21d20e7043eaf1fd6cf3eaf22e57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 28 Apr 2015 23:29:18 +0200 Subject: [PATCH] Enhanced DunglasApiBundle support --- .travis.yml | 2 +- .../LoadExtractorParsersPass.php | 4 +- .../DunglasApiProvider.php | 193 ++++++++++++++++++ .../DunglasJsonLdApiProvider.php | 98 --------- Parser/DunglasApiParser.php | 190 +++++++++++++++++ Parser/DunglasJsonLdApiParser.php | 96 --------- Parser/ParserInterface.php | 2 +- Resources/config/services.dunglas_api.xml | 23 +++ .../config/services.dunglas_json_ld_api.xml | 22 -- Resources/doc/index.md | 42 +++- Tests/Fixtures/app/AppKernel.php | 8 +- ...unglas_json_ld_api.yml => dunglas_api.yml} | 8 +- .../app/config/dunglas_api_routing.yml | 6 + .../config/dunglas_json_ld_api_routing.yml | 9 - ...arserTest.php => DunglasApiParserTest.php} | 15 +- composer.json | 4 +- 16 files changed, 465 insertions(+), 257 deletions(-) create mode 100644 Extractor/AnnotationsProvider/DunglasApiProvider.php delete mode 100644 Extractor/AnnotationsProvider/DunglasJsonLdApiProvider.php create mode 100644 Parser/DunglasApiParser.php delete mode 100644 Parser/DunglasJsonLdApiParser.php create mode 100644 Resources/config/services.dunglas_api.xml delete mode 100644 Resources/config/services.dunglas_json_ld_api.xml rename Tests/Fixtures/app/config/{dunglas_json_ld_api.yml => dunglas_api.yml} (76%) create mode 100644 Tests/Fixtures/app/config/dunglas_api_routing.yml delete mode 100644 Tests/Fixtures/app/config/dunglas_json_ld_api_routing.yml rename Tests/Parser/{DunglasJsonLdApiParserTest.php => DunglasApiParserTest.php} (69%) diff --git a/.travis.yml b/.travis.yml index 80b160a7b..9ad51caed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ matrix: 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" != "dev-master" ] && [ "$SYMFONY_VERSION" != "2.6.*" ]; then sed -i "/dunglas\/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 diff --git a/DependencyInjection/LoadExtractorParsersPass.php b/DependencyInjection/LoadExtractorParsersPass.php index 1139f01aa..3a83f8f3b 100644 --- a/DependencyInjection/LoadExtractorParsersPass.php +++ b/DependencyInjection/LoadExtractorParsersPass.php @@ -34,8 +34,8 @@ public function process(ContainerBuilder $container) } // DunglasJsonLdApiBundle may or may not be installed, if it is, load that config as well - if ($container->hasDefinition('dunglas_json_ld_api.resource_collection')) { - $loader->load('services.dunglas_json_ld_api.xml'); + if ($container->hasDefinition('api.resource_collection')) { + $loader->load('services.dunglas_api.xml'); } } } diff --git a/Extractor/AnnotationsProvider/DunglasApiProvider.php b/Extractor/AnnotationsProvider/DunglasApiProvider.php new file mode 100644 index 000000000..c5d2d87c1 --- /dev/null +++ b/Extractor/AnnotationsProvider/DunglasApiProvider.php @@ -0,0 +1,193 @@ + + * + * 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 Dunglas\ApiBundle\Api\Operation\OperationInterface; +use Dunglas\ApiBundle\Api\ResourceCollectionInterface; +use Dunglas\ApiBundle\Api\ResourceInterface; +use Dunglas\ApiBundle\Hydra\ApiDocumentationBuilderInterface; +use Dunglas\ApiBundle\Mapping\ClassMetadataFactoryInterface; +use Nelmio\ApiDocBundle\Annotation\ApiDoc; +use Nelmio\ApiDocBundle\Extractor\AnnotationsProviderInterface; +use Nelmio\ApiDocBundle\Parser\DunglasApiParser; + +/** + * Creates ApiDoc annotations for DunglasApiBundle. + * + * @author Kévin Dunglas + */ +class DunglasApiProvider implements AnnotationsProviderInterface +{ + /** + * @var ResourceCollectionInterface + */ + private $resourceCollection; + /** + * @var ApiDocumentationBuilderInterface + */ + private $apiDocumentationBuilder; + /** + * @var ClassMetadataFactoryInterface + */ + private $classMetadataFactory; + + public function __construct( + ResourceCollectionInterface $resourceCollection, + ApiDocumentationBuilderInterface $apiDocumentationBuilder, + ClassMetadataFactoryInterface $classMetadataFactory + ) { + $this->resourceCollection = $resourceCollection; + $this->apiDocumentationBuilder = $apiDocumentationBuilder; + $this->classMetadataFactory = $classMetadataFactory; + } + + /** + * {@inheritdoc} + */ + public function getAnnotations() + { + $annotations = []; + $hydraDoc = $this->apiDocumentationBuilder->getApiDocumentation(); + $entrypointHydraDoc = $this->getResourceHydraDoc($hydraDoc, '#Entrypoint'); + + /** + * @var ResourceInterface + */ + foreach ($this->resourceCollection as $resource) { + $classMetadata = $this->classMetadataFactory->getMetadataFor($resource->getEntityClass()); + $prefixedShortName = ($iri = $classMetadata->getIri()) ? $iri : '#'.$resource->getShortName(); + $resourceHydraDoc = $this->getResourceHydraDoc($hydraDoc, $prefixedShortName); + + if ($hydraDoc) { + foreach ($resource->getCollectionOperations() as $operation) { + $annotations[] = $this->getApiDoc(true, $resource, $operation, $resourceHydraDoc, $entrypointHydraDoc); + } + + foreach ($resource->getItemOperations() as $operation) { + $annotations[] = $this->getApiDoc(false, $resource, $operation, $resourceHydraDoc); + } + } + } + + return $annotations; + } + + /** + * Builds ApiDoc annotation from DunglasApiBundle data. + * + * @param bool $collection + * @param ResourceInterface $resource + * @param OperationInterface $operation + * @param array $resourceHydraDoc + * @param array $entrypointHydraDoc + * + * @return ApiDoc + */ + private function getApiDoc( + $collection, + ResourceInterface $resource, + OperationInterface $operation, + array $resourceHydraDoc, + array $entrypointHydraDoc = [] + ) { + $method = $operation->getRoute()->getMethods()[0]; + + if ($collection) { + $operationHydraDoc = $this->getCollectionOperationHydraDoc($resource->getShortName(), $method, $entrypointHydraDoc); + } else { + $operationHydraDoc = $this->getOperationHydraDoc($operation->getRoute()->getMethods()[0], $resourceHydraDoc); + } + + $route = $operation->getRoute(); + + $data = [ + 'resource' => $route->getPath(), + 'description' => $operationHydraDoc['hydra:title'], + 'resourceDescription' => $resourceHydraDoc['hydra:title'], + ]; + + $entityClass = $resource->getEntityClass(); + + if (isset($operationHydraDoc['expects']) && 'owl:Nothing' !== $operationHydraDoc['expects']) { + $data['input'] = sprintf('%s:%s', DunglasApiParser::IN_PREFIX, $entityClass); + } + + if (isset($operationHydraDoc['returns']) && 'owl:Nothing' !== $operationHydraDoc['returns']) { + $data['output'] = sprintf('%s:%s', DunglasApiParser::OUT_PREFIX, $entityClass); + } + + $data['filters'] = []; + foreach ($resource->getFilters() as $filter) { + $data['filters'][] = ['name' => $filter->getName()]; + } + + $apiDoc = new ApiDoc($data); + $apiDoc->setRoute($route); + + return $apiDoc; + } + + /** + * Gets Hydra documentation for the given resource. + * + * @param array $hydraApiDoc + * @param string $prefixedShortName + * + * @return array|null + */ + private function getResourceHydraDoc(array $hydraApiDoc, $prefixedShortName) + { + foreach ($hydraApiDoc['hydra:supportedClass'] as $supportedClass) { + if ($supportedClass['@id'] === $prefixedShortName) { + return $supportedClass; + } + } + } + + /** + * Gets the Hydra documentation of a given operation. + * + * @param string $method + * @param array $hydraDoc + * + * @return array|null + */ + private function getOperationHydraDoc($method, array $hydraDoc) + { + foreach ($hydraDoc['hydra:supportedOperation'] as $supportedOperation) { + if ($supportedOperation['hydra:method'] === $method) { + return $supportedOperation; + } + } + } + + /** + * Gets the Hydra documentation for the collection operation. + * + * @param string $shortName + * @param string $method + * @param array $hydraEntrypointDoc + * + * @return array|null + */ + private function getCollectionOperationHydraDoc($shortName, $method, array $hydraEntrypointDoc) + { + $propertyName = '#Entrypoint/'.lcfirst($shortName); + + foreach ($hydraEntrypointDoc['hydra:supportedProperty'] as $supportedProperty) { + $hydraProperty = $supportedProperty['hydra:property']; + if ($hydraProperty['@id'] === $propertyName) { + return $this->getOperationHydraDoc($method, $hydraProperty); + } + } + } +} diff --git a/Extractor/AnnotationsProvider/DunglasJsonLdApiProvider.php b/Extractor/AnnotationsProvider/DunglasJsonLdApiProvider.php deleted file mode 100644 index bf36d376a..000000000 --- a/Extractor/AnnotationsProvider/DunglasJsonLdApiProvider.php +++ /dev/null @@ -1,98 +0,0 @@ - - * - * 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\ResourceCollectionInterface; -use Dunglas\JsonLdApiBundle\JsonLd\ResourceInterface; -use Dunglas\JsonLdApiBundle\Mapping\ClassMetadataFactory; -use Nelmio\ApiDocBundle\Annotation\ApiDoc; -use Nelmio\ApiDocBundle\Extractor\AnnotationsProviderInterface; - -/** - * Creates ApiDoc annotations for DunglasJsonLdApiBundle. - * - * @author Kévin Dunglas - */ -class DunglasJsonLdApiProvider implements AnnotationsProviderInterface -{ - /** - * @var ResourceCollectionInterface - */ - private $resourceCollection; - /** - * @var ClassMetadataFactory - */ - private $classMetadataFactory; - - public function __construct(ResourceCollectionInterface $resourceCollection, ClassMetadataFactory $classMetadataFactory) - { - $this->resourceCollection = $resourceCollection; - $this->classMetadataFactory = $classMetadataFactory; - } - - /** - * {@inheritdoc} - */ - public function getAnnotations() - { - $annotations = []; - /** - * @var ResourceInterface $resource - */ - foreach ($this->resourceCollection 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 ResourceInterface $resource - * @param array $operation - * - * @return ApiDoc - */ - private function getApiDoc(ResourceInterface $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; - } -} diff --git a/Parser/DunglasApiParser.php b/Parser/DunglasApiParser.php new file mode 100644 index 000000000..640fbddd6 --- /dev/null +++ b/Parser/DunglasApiParser.php @@ -0,0 +1,190 @@ + + * + * 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\ApiBundle\Api\ResourceCollectionInterface; +use Dunglas\ApiBundle\Api\ResourceInterface; +use Dunglas\ApiBundle\Mapping\AttributeMetadataInterface; +use Dunglas\ApiBundle\Mapping\ClassMetadataFactoryInterface; +use Nelmio\ApiDocBundle\DataTypes; +use PropertyInfo\Type; + +/** + * Use DunglasApiBundle to extract input and output information. + * + * @author Kévin Dunglas + */ +class DunglasApiParser implements ParserInterface +{ + const IN_PREFIX = 'dunglas_api_in'; + const OUT_PREFIX = 'dunglas_api_out'; + const IRI = 'IRI'; + + private static $typeMap = array( + 'int' => DataTypes::INTEGER, + 'bool' => DataTypes::BOOLEAN, + 'string' => DataTypes::STRING, + 'float' => DataTypes::FLOAT, + ); + + /** + * @var ResourceCollectionInterface + */ + private $resourceCollection; + /** + * @var ClassMetadataFactory + */ + private $classMetadataFactory; + + public function __construct( + ResourceCollectionInterface $resourceCollection, + ClassMetadataFactoryInterface $classMetadataFactory + ) { + $this->resourceCollection = $resourceCollection; + $this->classMetadataFactory = $classMetadataFactory; + } + + /** + * {@inheritdoc} + */ + public function supports(array $item) + { + list(, $class) = explode(':', $item['class'], 2); + + return null !== $this->resourceCollection->getResourceForEntity($class); + } + + /** + * {@inheritdoc} + */ + public function parse(array $item) + { + list($io, $entityClass) = explode(':', $item['class'], 2); + $resource = $this->resourceCollection->getResourceForEntity($entityClass); + + return $this->parseClass($resource, $entityClass, $io); + } + + /** + * Parses a class. + * + * @param ResourceInterface $resource + * @param string $entityClass + * @param string $io + * + * @return array + */ + private function parseClass(ResourceInterface $resource, $entityClass, $io) + { + $classMetadata = $this->classMetadataFactory->getMetadataFor( + $entityClass, + $resource->getNormalizationGroups(), + $resource->getDenormalizationGroups(), + $resource->getValidationGroups() + ); + + $data = array(); + foreach ($classMetadata->getAttributes() as $attributeMetadata) { + if ( + ($attributeMetadata->isReadable() && self::OUT_PREFIX === $io) || + ($attributeMetadata->isWritable() && self::IN_PREFIX === $io) + ) { + $data[$attributeMetadata->getName()] = $this->parseAttribute($resource, $attributeMetadata, $io); + } + } + + return $data; + } + + /** + * Parses an attribute. + * + * @param ResourceInterface $resource + * @param AttributeMetadataInterface $attributeMetadata + * @param string $io + * @param Type|null $type + * + * @return array + */ + private function parseAttribute(ResourceInterface $resource, AttributeMetadataInterface $attributeMetadata, $io, Type $type = null) + { + $data = array( + 'dataType' => null, + 'required' => $attributeMetadata->isRequired(), + 'description' => $attributeMetadata->getDescription(), + 'readonly' => !$attributeMetadata->isWritable(), + ); + + if (null == $type) { + if (!isset($attributeMetadata->getTypes()[0])) { + // Default to string + $data['dataType'] = DataTypes::STRING; + + return $data; + } + + // Use the first type found as primary + $type = $attributeMetadata->getTypes()[0]; + } + + if ($type->isCollection()) { + $data['actualType'] = DataTypes::COLLECTION; + + if ($collectionType = $type->getCollectionType()) { + $subAttribute = $this->parseAttribute($resource, $attributeMetadata, $io, $collectionType); + if (self::IRI === $subAttribute['dataType']) { + $data['dataType'] = 'array of IRIs'; + $data['subType'] = DataTypes::STRING; + + return $data; + } + + $data['subType'] = $subAttribute['subType']; + $data['children'] = $subAttribute['children']; + } + + return $data; + } + + $phpType = $type->getType(); + if ('object' === $phpType) { + $class = $type->getClass(); + + if ('DateTime' === $class) { + $data['dataType'] = DataTypes::DATETIME; + $data['format'] = sprintf('{DateTime %s}', \DateTime::ATOM); + + return $data; + } + + if ( + (self::OUT_PREFIX === $io && $attributeMetadata->isNormalizationLink()) || + (self::IN_PREFIX === $io && $attributeMetadata->isDenormalizationLink()) + ) { + $data['dataType'] = self::IRI; + $data['actualType'] = DataTypes::STRING; + + return $data; + } + + $data['actualType'] = DataTypes::MODEL; + $data['subType'] = $class; + $data['children'] = $this->parseClass($resource, $class, $io); + + return $data; + } + + $data['dataType'] = isset(self::$typeMap[$type->getType()]) ? self::$typeMap[$type->getType()] : DataTypes::STRING; + + return $data; + } +} diff --git a/Parser/DunglasJsonLdApiParser.php b/Parser/DunglasJsonLdApiParser.php deleted file mode 100644 index 7ddfe3b18..000000000 --- a/Parser/DunglasJsonLdApiParser.php +++ /dev/null @@ -1,96 +0,0 @@ - - * - * 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\ResourceCollectionInterface; -use Dunglas\JsonLdApiBundle\JsonLd\ResourceInterface; -use Dunglas\JsonLdApiBundle\Mapping\ClassMetadataFactory; -use Nelmio\ApiDocBundle\DataTypes; - -/** - * Use DunglasJsonLdApi to extract input and output information. - * - * @author Kévin Dunglas - */ -class DunglasJsonLdApiParser implements ParserInterface -{ - /** - * @var ResourceCollectionInterface - */ - private $resourceCollection; - /** - * @var ClassMetadataFactory - */ - private $classMetadataFactory; - - public function __construct(ResourceCollectionInterface $resourceCollection, ClassMetadataFactory $classMetadataFactory) - { - $this->resourceCollection = $resourceCollection; - $this->classMetadataFactory = $classMetadataFactory; - } - - /** - * {@inheritdoc} - */ - public function supports(array $item) - { - return null !== $this->resourceCollection->getResourceForEntity($item['class']); - } - - /** - * {@inheritdoc} - */ - public function parse(array $item) - { - /** - * @var $resource ResourceInterface - */ - $resource = $this->resourceCollection->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; - } else { - $data[$attribute->getName()]['dataType'] = DataTypes::STRING; - } - } - - return $data; - } -} diff --git a/Parser/ParserInterface.php b/Parser/ParserInterface.php index 33455508c..68cdc83f9 100644 --- a/Parser/ParserInterface.php +++ b/Parser/ParserInterface.php @@ -36,7 +36,7 @@ public function supports(array $item); * - class (optional) the fully-qualified class name of the item, if * it is represented by an object * - * @param string $item The string type of input to parse. + * @param array $item The string type of input to parse. * @return array */ public function parse(array $item); diff --git a/Resources/config/services.dunglas_api.xml b/Resources/config/services.dunglas_api.xml new file mode 100644 index 000000000..67f668d45 --- /dev/null +++ b/Resources/config/services.dunglas_api.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/config/services.dunglas_json_ld_api.xml b/Resources/config/services.dunglas_json_ld_api.xml deleted file mode 100644 index 49f886b23..000000000 --- a/Resources/config/services.dunglas_json_ld_api.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 3228a4675..945823543 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -14,7 +14,7 @@ Require the `nelmio/api-doc-bundle` package in your composer.json and update you Register the bundle in `app/AppKernel.php`: -``` php +```php // app/AppKernel.php public function registerBundles() { @@ -33,7 +33,7 @@ NelmioApiDocBundle: prefix: /api/doc ``` Enable the bundle's configuration in `app/config/config.yml`: -``` yaml +```yaml # app/config/config.yml nelmio_api_doc: ~ ``` @@ -48,7 +48,7 @@ uses introspection a lot. Thanks to an annotation, it's really easy to document The bundle provides an `ApiDoc()` annotation for your controllers: -``` php +```php load(__DIR__.'/config/'.$this->environment.'.yml'); - if (class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) { - $loader->load(__DIR__.'/config/dunglas_json_ld_api.yml'); + if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) { + $loader->load(__DIR__.'/config/dunglas_api.yml'); } } diff --git a/Tests/Fixtures/app/config/dunglas_json_ld_api.yml b/Tests/Fixtures/app/config/dunglas_api.yml similarity index 76% rename from Tests/Fixtures/app/config/dunglas_json_ld_api.yml rename to Tests/Fixtures/app/config/dunglas_api.yml index 0eba27782..f490b7555 100644 --- a/Tests/Fixtures/app/config/dunglas_json_ld_api.yml +++ b/Tests/Fixtures/app/config/dunglas_api.yml @@ -9,14 +9,14 @@ doctrine: auto_mapping: true framework: - router: { resource: "%kernel.root_dir%/config/dunglas_json_ld_api_routing.yml" } + router: { resource: "%kernel.root_dir%/config/dunglas_api_routing.yml" } -dunglas_json_ld_api: +dunglas_api: title: API description: Test API services: dunglas_json_ld_api.popo: - class: "Dunglas\JsonLdApiBundle\JsonLd\Resource" + parent: "api.resource" arguments: [ "Nelmio\\ApiDocBundle\\Tests\\Fixtures\\Model\\Popo" ] - tags: [ { name: "json-ld.resource" } ] + tags: [ { name: "api.resource" } ] diff --git a/Tests/Fixtures/app/config/dunglas_api_routing.yml b/Tests/Fixtures/app/config/dunglas_api_routing.yml new file mode 100644 index 000000000..d46992603 --- /dev/null +++ b/Tests/Fixtures/app/config/dunglas_api_routing.yml @@ -0,0 +1,6 @@ +main: + resource: "routing.yml" + +dunglas_api: + resource: "." + type: "api" diff --git a/Tests/Fixtures/app/config/dunglas_json_ld_api_routing.yml b/Tests/Fixtures/app/config/dunglas_json_ld_api_routing.yml deleted file mode 100644 index 3b0ca75e9..000000000 --- a/Tests/Fixtures/app/config/dunglas_json_ld_api_routing.yml +++ /dev/null @@ -1,9 +0,0 @@ -main: - resource: "routing.yml" - -dunglas_json_ld_api_doc: - resource: "@DunglasJsonLdApiBundle/Resources/config/routing.xml" - -dunglas_json_ld_api: - resource: "." - type: "json-ld" diff --git a/Tests/Parser/DunglasJsonLdApiParserTest.php b/Tests/Parser/DunglasApiParserTest.php similarity index 69% rename from Tests/Parser/DunglasJsonLdApiParserTest.php rename to Tests/Parser/DunglasApiParserTest.php index 5385ab7e4..16b63d0bb 100644 --- a/Tests/Parser/DunglasJsonLdApiParserTest.php +++ b/Tests/Parser/DunglasApiParserTest.php @@ -11,18 +11,20 @@ namespace NelmioApiDocBundle\Tests\Parser; +use Nelmio\ApiDocBundle\DataTypes; +use Nelmio\ApiDocBundle\Parser\DunglasApiParser; use Nelmio\ApiDocBundle\Tests\WebTestCase; /** * @author Kévin Dunglas */ -class DunglasJsonLdApiParserTest extends WebTestCase +class DunglasApiParserTest extends WebTestCase { protected function setUp() { - if (!class_exists('Dunglas\JsonLdApiBundle\DunglasJsonLdApiBundle')) { + if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) { $this->markTestSkipped( - 'DunglasJsonLdApiBundle is not available.' + 'DunglasApiBundle is not available.' ); } } @@ -30,9 +32,9 @@ protected function setUp() public function testParser() { $container = $this->getContainer(); - $parser = $container->get('nelmio_api_doc.parser.dunglas_json_ld_api_parser'); + $parser = $container->get('nelmio_api_doc.parser.dunglas_api_parser'); - $item = array('class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo'); + $item = array('class' => DunglasApiParser::OUT_PREFIX.':Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo'); $expected = array ( 'foo' => @@ -40,8 +42,7 @@ public function testParser() 'required' => false, 'description' => '', 'readonly' => false, - 'class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo', - 'dataType' => 'string', + 'dataType' => DataTypes::STRING, ), ); diff --git a/composer.json b/composer.json index f2abd7470..f4988f507 100644 --- a/composer.json +++ b/composer.json @@ -33,14 +33,14 @@ "symfony/serializer": "~2.7@dev", "friendsofsymfony/rest-bundle": "~1.0", "jms/serializer-bundle": ">=0.11", - "dunglas/json-ld-api-bundle": "dev-master", + "dunglas/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.", + "dunglas/api-bundle": "For making use of resources definitions of DunglasApiBundle.", "jms/serializer": "For making use of serializer information in the doc." }, "autoload": {