mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
commit
40d3750b20
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
vendor/
|
vendor/
|
||||||
composer.lock
|
composer.lock
|
||||||
|
phpunit.xml
|
||||||
|
@ -40,7 +40,7 @@ class ApiDoc
|
|||||||
{
|
{
|
||||||
if (isset($data['formType'])) {
|
if (isset($data['formType'])) {
|
||||||
$this->formType = $data['formType'];
|
$this->formType = $data['formType'];
|
||||||
} else if (isset($data['filters'])) {
|
} elseif (isset($data['filters'])) {
|
||||||
foreach ($data['filters'] as $filter) {
|
foreach ($data['filters'] as $filter) {
|
||||||
if (!isset($filter['name'])) {
|
if (!isset($filter['name'])) {
|
||||||
throw new \InvalidArgumentException('A "filter" element has to contain a "name" attribute');
|
throw new \InvalidArgumentException('A "filter" element has to contain a "name" attribute');
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
|
||||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class ApiDocExtractor
|
|||||||
private $container;
|
private $container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ymfony\Component\Routing\RouterInterface
|
* @var \Symfony\Component\Routing\RouterInterface
|
||||||
*/
|
*/
|
||||||
private $router;
|
private $router;
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class ApiDocExtractor
|
|||||||
* Returns the ReflectionMethod for the given controller string
|
* Returns the ReflectionMethod for the given controller string
|
||||||
*
|
*
|
||||||
* @param string $controller
|
* @param string $controller
|
||||||
* @return ReflectionMethod|null
|
* @return \ReflectionMethod|null
|
||||||
*/
|
*/
|
||||||
public function getReflectionMethod($controller)
|
public function getReflectionMethod($controller)
|
||||||
{
|
{
|
||||||
@ -150,7 +150,7 @@ class ApiDocExtractor
|
|||||||
* - route
|
* - route
|
||||||
*
|
*
|
||||||
* @param string $controller
|
* @param string $controller
|
||||||
* @param Route $route
|
* @param Route $route
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
public function get($controller, $route)
|
public function get($controller, $route)
|
||||||
@ -172,9 +172,9 @@ class ApiDocExtractor
|
|||||||
* - annotation
|
* - annotation
|
||||||
* - route
|
* - route
|
||||||
*
|
*
|
||||||
* @param ApiDoc $annotation
|
* @param ApiDoc $annotation
|
||||||
* @param Route $route
|
* @param Route $route
|
||||||
* @param ReflectionMethod $method
|
* @param \ReflectionMethod $method
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getData(ApiDoc $annotation, Route $route, \ReflectionMethod $method)
|
protected function getData(ApiDoc $annotation, Route $route, \ReflectionMethod $method)
|
||||||
|
@ -56,22 +56,22 @@ abstract class AbstractFormatter implements FormatterInterface
|
|||||||
/**
|
/**
|
||||||
* Format a single array of data
|
* Format a single array of data
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return string|array
|
* @return string|array
|
||||||
*/
|
*/
|
||||||
protected abstract function renderOne(array $data);
|
abstract protected function renderOne(array $data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a set of resource sections.
|
* Format a set of resource sections.
|
||||||
*
|
*
|
||||||
* @param array $collection
|
* @param array $collection
|
||||||
* @return string|array
|
* @return string|array
|
||||||
*/
|
*/
|
||||||
protected abstract function render(array $collection);
|
abstract protected function render(array $collection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ApiDoc $apiDoc
|
* @param ApiDoc $apiDoc
|
||||||
* @param Route $route
|
* @param Route $route
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getData(ApiDoc $apiDoc, Route $route)
|
protected function getData(ApiDoc $apiDoc, Route $route)
|
||||||
|
@ -19,17 +19,17 @@ interface FormatterInterface
|
|||||||
/**
|
/**
|
||||||
* Format a collection of documentation data.
|
* Format a collection of documentation data.
|
||||||
*
|
*
|
||||||
* @param array $collection
|
* @param array $collection
|
||||||
* @return string|array
|
* @return string|array
|
||||||
*/
|
*/
|
||||||
function format(array $collection);
|
public function format(array $collection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format documentation data for one route.
|
* Format documentation data for one route.
|
||||||
*
|
*
|
||||||
* @param ApiDoc $apiDoc
|
* @param ApiDoc $apiDoc
|
||||||
* @param Route $route
|
* @param Route $route
|
||||||
* return string|array
|
* return string|array
|
||||||
*/
|
*/
|
||||||
function formatOne(ApiDoc $apiDoc, Route $route);
|
public function formatOne(ApiDoc $apiDoc, Route $route);
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Formatter;
|
namespace Nelmio\ApiDocBundle\Formatter;
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|
||||||
use Symfony\Component\Routing\Route;
|
|
||||||
use Symfony\Component\Templating\EngineInterface;
|
use Symfony\Component\Templating\EngineInterface;
|
||||||
|
|
||||||
class HtmlFormatter extends AbstractFormatter
|
class HtmlFormatter extends AbstractFormatter
|
||||||
|
@ -47,7 +47,7 @@ class FormTypeParser
|
|||||||
* - required
|
* - required
|
||||||
* - description
|
* - description
|
||||||
*
|
*
|
||||||
* @param AbstractType $type
|
* @param AbstractType $type
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function parse(AbstractType $type)
|
public function parse(AbstractType $type)
|
||||||
@ -56,7 +56,11 @@ class FormTypeParser
|
|||||||
|
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
foreach ($builder->all() as $name => $child) {
|
foreach ($builder->all() as $name => $child) {
|
||||||
$childBuilder = $builder->create($name, $child['type'] ?: 'text', $child['options']);
|
if ($child instanceof FormBuilder) {
|
||||||
|
$childBuilder = $child;
|
||||||
|
} else {
|
||||||
|
$childBuilder = $builder->create($name, $child['type'] ?: 'text', $child['options']);
|
||||||
|
}
|
||||||
|
|
||||||
$bestType = '';
|
$bestType = '';
|
||||||
foreach ($childBuilder->getTypes() as $type) {
|
foreach ($childBuilder->getTypes() as $type) {
|
||||||
|
@ -58,7 +58,7 @@ class TestController
|
|||||||
*
|
*
|
||||||
* @ApiDoc()
|
* @ApiDoc()
|
||||||
*
|
*
|
||||||
* @param int $id A nice comment
|
* @param int $id A nice comment
|
||||||
* @param int $page
|
* @param int $page
|
||||||
*/
|
*/
|
||||||
public function myCommentedAction()
|
public function myCommentedAction()
|
||||||
|
@ -11,9 +11,6 @@
|
|||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Controller;
|
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Controller;
|
||||||
|
|
||||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
class TestServiceController extends TestController
|
class TestServiceController extends TestController
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ class TestType extends AbstractType
|
|||||||
{
|
{
|
||||||
$builder->add('a', null, array('description' => 'A nice description'));
|
$builder->add('a', null, array('description' => 'A nice description'));
|
||||||
$builder->add('b');
|
$builder->add('b');
|
||||||
|
$builder->add($builder->create('c', 'checkbox'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,4 +24,6 @@ class Test
|
|||||||
* @Assert\Type("DateTime");
|
* @Assert\Type("DateTime");
|
||||||
*/
|
*/
|
||||||
public $b;
|
public $b;
|
||||||
|
|
||||||
|
public $c;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the NelmioApiDocBundle.
|
* This file is part of the NelmioApiDocBundle.
|
||||||
*
|
*
|
||||||
* (c) Nelmio <hello@nelm.io>
|
* (c) Nelmio <hello@nelm.io>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Nelmio\ApiDocBundle\Tests\Fixtures;
|
namespace Nelmio\ApiDocBundle\Tests\Fixtures;
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
|
|
||||||
class NelmioApiDocTestBundle extends Bundle
|
class NelmioApiDocTestBundle extends Bundle
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ while ($dir !== $lastDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
|
||||||
use Symfony\Component\HttpKernel\Kernel;
|
use Symfony\Component\HttpKernel\Kernel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,6 +75,11 @@ b:
|
|||||||
* type: string
|
* type: string
|
||||||
* required: true
|
* required: true
|
||||||
|
|
||||||
|
c:
|
||||||
|
|
||||||
|
* type: boolean
|
||||||
|
* required: true
|
||||||
|
|
||||||
|
|
||||||
### `POST` /tests ###
|
### `POST` /tests ###
|
||||||
|
|
||||||
@ -93,6 +98,11 @@ b:
|
|||||||
* type: string
|
* type: string
|
||||||
* required: true
|
* required: true
|
||||||
|
|
||||||
|
c:
|
||||||
|
|
||||||
|
* type: boolean
|
||||||
|
* required: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# others #
|
# others #
|
||||||
|
@ -97,6 +97,12 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
),
|
),
|
||||||
|
'c' =>
|
||||||
|
array(
|
||||||
|
'dataType' => 'boolean',
|
||||||
|
'required' => true,
|
||||||
|
'description' => '',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'description' => 'create test',
|
'description' => 'create test',
|
||||||
),
|
),
|
||||||
@ -121,6 +127,12 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
),
|
),
|
||||||
|
'c' =>
|
||||||
|
array(
|
||||||
|
'dataType' => 'boolean',
|
||||||
|
'required' => true,
|
||||||
|
'description' => '',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'description' => 'create test',
|
'description' => 'create test',
|
||||||
),
|
),
|
||||||
|
@ -37,14 +37,14 @@ abstract class WebTestCase extends BaseWebTestCase
|
|||||||
return static::$kernel->getContainer();
|
return static::$kernel->getContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected function getKernelClass()
|
protected static function getKernelClass()
|
||||||
{
|
{
|
||||||
require_once __DIR__.'/Fixtures/app/AppKernel.php';
|
require_once __DIR__.'/Fixtures/app/AppKernel.php';
|
||||||
|
|
||||||
return 'Nelmio\ApiDocBundle\Tests\Functional\AppKernel';
|
return 'Nelmio\ApiDocBundle\Tests\Functional\AppKernel';
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected function createKernel(array $options = array())
|
protected static function createKernel(array $options = array())
|
||||||
{
|
{
|
||||||
$class = self::getKernelClass();
|
$class = self::getKernelClass();
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function includeIfExists($file) {
|
function includeIfExists($file)
|
||||||
if (file_exists($file)) {
|
{
|
||||||
return include $file;
|
if (file_exists($file)) {
|
||||||
}
|
return include $file;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../../../autoload.php'))) {
|
|
||||||
die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
|
if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../../../autoload.php'))) {
|
||||||
'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
|
die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
|
||||||
'php composer.phar install'.PHP_EOL);
|
'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
|
||||||
}
|
'php composer.phar install'.PHP_EOL);
|
||||||
|
}
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
{
|
{
|
||||||
"name": "nelmio/api-doc-bundle",
|
"name": "nelmio/api-doc-bundle",
|
||||||
"description": "Generates documentation for your REST API from annotations",
|
"description": "Generates documentation for your REST API from annotations",
|
||||||
"keywords": ["api", "documentation", "doc", "rest"],
|
"keywords": ["api", "documentation", "doc", "rest"],
|
||||||
"type": "symfony-bundle",
|
"type": "symfony-bundle",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Nelmio",
|
"name": "Nelmio",
|
||||||
"homepage": "http://nelm.io"
|
"homepage": "http://nelm.io"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Symfony Community",
|
"name": "Symfony Community",
|
||||||
"homepage": "https://github.com/nelmio/NelmioApiDocBundle/contributors"
|
"homepage": "https://github.com/nelmio/NelmioApiDocBundle/contributors"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"symfony/framework-bundle": "2.1.*",
|
"symfony/framework-bundle": "2.1.*",
|
||||||
"symfony/twig-bundle": "2.1.*",
|
"symfony/twig-bundle": "2.1.*",
|
||||||
"symfony/form": "2.1.*"
|
"symfony/form": "2.1.*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/css-selector": "2.1.*",
|
"symfony/css-selector": "2.1.*",
|
||||||
"symfony/browser-kit": "2.1.*",
|
"symfony/browser-kit": "2.1.*",
|
||||||
"symfony/validator": "2.1.*",
|
"symfony/validator": "2.1.*",
|
||||||
"symfony/yaml": "2.1.*"
|
"symfony/yaml": "2.1.*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": { "Nelmio\\ApiDocBundle": "" }
|
"psr-0": { "Nelmio\\ApiDocBundle": "" }
|
||||||
},
|
},
|
||||||
"target-dir": "Nelmio/ApiDocBundle"
|
"target-dir": "Nelmio/ApiDocBundle"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user