diff --git a/.gitignore b/.gitignore
index 80ae21a..d924569 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
-/vendor/*
-composer.lock
-.php_cs.cache
+/vendor/
+/composer.lock
+/.php_cs.cache
+/phpunit.xml
+/Tests/Functional/cache
+/Tests/Functional/logs
diff --git a/.travis.yml b/.travis.yml
index fe79f81..deb7558 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,9 @@
language: php
php:
- - 5.5
- 5.6
- 7.0
+ - 7.1
- hhvm
sudo: false
@@ -26,4 +26,4 @@ matrix:
before_install:
- composer self-update
-install: composer update $COMPOSER_FLAGS --prefer-dist
+install: composer update $COMPOSER_FLAGS
diff --git a/DependencyInjection/Compiler/AddExtractorsPass.php b/DependencyInjection/Compiler/AddExtractorsPass.php
new file mode 100644
index 0000000..6725f45
--- /dev/null
+++ b/DependencyInjection/Compiler/AddExtractorsPass.php
@@ -0,0 +1,28 @@
+findAndSortTaggedServices('exsyst_api_doc.extractor', $container);
+
+ $container->getDefinition('exsyst_api_doc.generator')->replaceArgument(0, $extractors);
+ }
+}
diff --git a/DependencyInjection/Compiler/AddRoutingExtractorsPass.php b/DependencyInjection/Compiler/AddRoutingExtractorsPass.php
new file mode 100644
index 0000000..86566a3
--- /dev/null
+++ b/DependencyInjection/Compiler/AddRoutingExtractorsPass.php
@@ -0,0 +1,28 @@
+findAndSortTaggedServices('exsyst_api_doc.routing_extractor', $container);
+
+ $container->getDefinition('exsyst_api_doc.extractors.routing')->replaceArgument(2, $extractors);
+ }
+}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
new file mode 100644
index 0000000..0b5d88e
--- /dev/null
+++ b/DependencyInjection/Configuration.php
@@ -0,0 +1,26 @@
+root('exsyst_api_doc');
+
+ return $treeBuilder;
+ }
+}
diff --git a/DependencyInjection/EXSystApiDocExtension.php b/DependencyInjection/EXSystApiDocExtension.php
new file mode 100644
index 0000000..0c8ffde
--- /dev/null
+++ b/DependencyInjection/EXSystApiDocExtension.php
@@ -0,0 +1,39 @@
+processConfiguration(new Configuration(), $configs);
+ $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+
+ $loader->load('services.xml');
+ }
+}
diff --git a/EXSystApiDocBundle.php b/EXSystApiDocBundle.php
new file mode 100644
index 0000000..5d00656
--- /dev/null
+++ b/EXSystApiDocBundle.php
@@ -0,0 +1,43 @@
+addCompilerPass(new AddExtractorsPass());
+ $container->addCompilerPass(new AddRoutingExtractorsPass());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getContainerExtension()
+ {
+ if (null === $this->extension) {
+ $this->extension = new EXSystApiDocExtension();
+ }
+ if ($this->extension) {
+ return $this->extension;
+ }
+ }
+}
diff --git a/Extractor/Routing/NelmioAnnotationExtractor.php b/Extractor/Routing/NelmioAnnotationExtractor.php
index 896823f..c8368de 100644
--- a/Extractor/Routing/NelmioAnnotationExtractor.php
+++ b/Extractor/Routing/NelmioAnnotationExtractor.php
@@ -37,12 +37,13 @@ class NelmioAnnotationExtractor implements RouteExtractorInterface
}
$annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, ApiDoc::class);
- // some fields aren't available otherwise
- $annotationArray = $annotation->toArray();
if (null === $annotation) {
return;
}
+ // some fields aren't available otherwise
+ $annotationArray = $annotation->toArray();
+
foreach ($this->getOperations($api, $route) as $operation) {
if ($annotation->getDescription()) {
$operation->setDescription($annotation->getDescription());
diff --git a/Extractor/Routing/RouteExtractorTrait.php b/Extractor/Routing/RouteExtractorTrait.php
index 7767921..391ee0c 100644
--- a/Extractor/Routing/RouteExtractorTrait.php
+++ b/Extractor/Routing/RouteExtractorTrait.php
@@ -27,7 +27,7 @@ trait RouteExtractorTrait
*/
private function getOperations(Swagger $api, Route $route)
{
- $path = $swagger->getPaths()->get($route->getPath());
+ $path = $api->getPaths()->get($route->getPath());
$methods = $route->getMethods() ?: Swagger::$METHODS;
foreach ($methods as $method) {
$method = strtolower($method);
diff --git a/Extractor/Routing/RouteMetadataExtractor.php b/Extractor/Routing/RouteMetadataExtractor.php
index 3805d24..2fcd7c5 100644
--- a/Extractor/Routing/RouteMetadataExtractor.php
+++ b/Extractor/Routing/RouteMetadataExtractor.php
@@ -26,7 +26,7 @@ class RouteMetadataExtractor implements RouteExtractorInterface
foreach ($route->getRequirements() as $parameterName => $requirement) {
$parameter = $operation->getParameters()->get($parameterName, 'path');
$parameter->setRequired(true);
- $parameter->setType(swagger\Swagger::T_STRING);
+ $parameter->setType(Swagger::T_STRING);
$parameter->setFormat($requirement);
}
}
diff --git a/Extractor/RouteExtractor.php b/Extractor/RoutingExtractor.php
similarity index 95%
rename from Extractor/RouteExtractor.php
rename to Extractor/RoutingExtractor.php
index 490e593..5023cd8 100644
--- a/Extractor/RouteExtractor.php
+++ b/Extractor/RoutingExtractor.php
@@ -18,7 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouterInterface;
-class RouteExtractor implements ExtractorInterface
+class RoutingExtractor implements ExtractorInterface
{
private $routeExtractors;
@@ -37,13 +37,12 @@ class RouteExtractor implements ExtractorInterface
/**
* @return Swagger
*/
- public function extract()
+ public function extractIn(Swagger $swagger)
{
if (0 === count($this->routeExtractors)) {
return;
}
- $swagger = new Swagger();
foreach ($this->getRoutes() as $route) {
// if able to resolve the controller
if ($method = $this->getReflectionMethod($route->getDefault('_controller'))) {
@@ -53,8 +52,6 @@ class RouteExtractor implements ExtractorInterface
}
}
}
-
- return $swagger;
}
/**
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
new file mode 100644
index 0000000..a31d27e
--- /dev/null
+++ b/Resources/config/services.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Tests/Functional/Controller/ApiController.php b/Tests/Functional/Controller/ApiController.php
new file mode 100644
index 0000000..c4ae143
--- /dev/null
+++ b/Tests/Functional/Controller/ApiController.php
@@ -0,0 +1,24 @@
+getSwaggerDefinition();
+ $paths = $api->getPaths();
+
+ $this->assertTrue($paths->has('/test/{user}'));
+ $action = $paths->get('/test/{user}');
+
+ $this->assertTrue($action->hasOperation('get'));
+ $operation = $action->getOperation('get');
+
+ $this->assertEquals(['https'], $operation->getSchemes()->toArray());
+
+ $parameters = $operation->getParameters();
+ $this->assertTrue($parameters->search('user', 'path'));
+
+ $parameter = $parameters->find('user', 'path');
+ $this->assertTrue($parameter->getRequired());
+ $this->assertEquals('string', $parameter->getType());
+ $this->assertEquals('/foo/', $parameter->getFormat());
+ }
+
+ private function getSwaggerDefinition()
+ {
+ static::createClient();
+
+ return static::$kernel->getContainer()->get('exsyst_api_doc.generator')->extract();
+ }
+}
diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php
new file mode 100644
index 0000000..9683c25
--- /dev/null
+++ b/Tests/Functional/TestKernel.php
@@ -0,0 +1,54 @@
+import(__DIR__.'/Controller/', '/', 'annotation');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
+ {
+ $c->loadFromExtension('framework', [
+ 'secret' => 'MySecretKey',
+ 'test' => null,
+ ]);
+ }
+}
diff --git a/composer.json b/composer.json
index f2bd605..6c29bc1 100644
--- a/composer.json
+++ b/composer.json
@@ -9,13 +9,15 @@
}
],
"require": {
- "php": ">=5.5",
- "symfony/framework-bundle": "^2.7|^3.0",
+ "php": ">=5.6",
+ "symfony/framework-bundle": "^3.2@dev",
"gossi/swagger": "^0.2"
},
"require-dev": {
- "nelmio/api-doc-bundle": "^2.0",
- "symfony/phpunit-bridge": "^2.7|^3.0"
+ "symfony/browser-kit": "~2.8|~3.0",
+ "symfony/phpunit-bridge": "^3.2@dev",
+ "sensio/framework-extra-bundle": "~3.0",
+ "nelmio/api-doc-bundle": "^2.0"
},
"suggest": {
"nelmio/api-doc-bundle": "For using the ApiDoc annotation."
@@ -29,5 +31,7 @@
"branch-alias": {
"dev-master": "0.1.x-dev"
}
- }
+ },
+ "prefer-stable": true,
+ "minimum-stability": "dev"
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 760bc87..ea706f6 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,7 +1,8 @@
+
+
-
- ./Tests/
+
+ Tests
+
+
+
+
+
- ./
+ .
- ./vendor
- ./Tests/
+ Tests
+ vendor