Ability to specify param-type of input class.

This commit is contained in:
Bez Hermoso 2014-08-07 15:32:39 -07:00
parent eb08b7af27
commit 18004189b3
2 changed files with 38 additions and 3 deletions

View File

@ -200,6 +200,16 @@ class SwaggerFormatter implements FormatterInterface
/** @var $apiDoc ApiDoc */
$apiDoc = $item['annotation'];
$itemResource = $this->stripBasePath($item['resource']);
$input = $apiDoc->getInput();
if (!is_array($input)) {
$input = array(
'class' => $input,
'paramType' => 'form',
);
} elseif (empty($input['paramType'])) {
$input['paramType'] = 'form';
}
$route = $apiDoc->getRoute();
@ -242,7 +252,10 @@ class SwaggerFormatter implements FormatterInterface
$data = $apiDoc->toArray();
if (isset($data['parameters'])) {
$parameters = array_merge($parameters, $this->deriveParameters($data['parameters'], $models));
$parameters = array_merge($parameters, $this->deriveParameters($data['parameters'],
$models,
$input['paramType']
));
}
$responseMap = $apiDoc->getParsedResponseMap();
@ -356,9 +369,12 @@ class SwaggerFormatter implements FormatterInterface
*
* @param array $input
* @param array $models
*
* @param string $paramType
*
* @return array
*/
protected function deriveParameters(array $input, array &$models)
protected function deriveParameters(array $input, array &$models, $paramType = 'form')
{
$parameters = array();
@ -404,7 +420,7 @@ class SwaggerFormatter implements FormatterInterface
}
$parameter = array(
'paramType' => 'form',
'paramType' => $paramType,
'name' => $name,
);

View File

@ -98,6 +98,25 @@ php app/console api:swagger:dump --resource=users
```
The above command will dump the `/users` API declaration in an `users.json` file.
### Defining a form-type as a GET form
If you use forms to capture GET requests, you will have to specify the `paramType` to `query` in the annotation:
```php
<?php
/**
* @ApiDoc(
* input = {"class" = "Foo\ContentBundle\Form\SearchType", "paramType" = "query"},
* ...
* )
*/
public function searchAction(Request $request)
{
```
##Configuration reference
```yml