mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Ability to specify param-type of input class.
This commit is contained in:
parent
eb08b7af27
commit
18004189b3
@ -200,7 +200,17 @@ class SwaggerFormatter implements FormatterInterface
|
|||||||
/** @var $apiDoc ApiDoc */
|
/** @var $apiDoc ApiDoc */
|
||||||
$apiDoc = $item['annotation'];
|
$apiDoc = $item['annotation'];
|
||||||
$itemResource = $this->stripBasePath($item['resource']);
|
$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();
|
$route = $apiDoc->getRoute();
|
||||||
|
|
||||||
$itemResource = $this->normalizeResourcePath($itemResource);
|
$itemResource = $this->normalizeResourcePath($itemResource);
|
||||||
@ -242,7 +252,10 @@ class SwaggerFormatter implements FormatterInterface
|
|||||||
$data = $apiDoc->toArray();
|
$data = $apiDoc->toArray();
|
||||||
|
|
||||||
if (isset($data['parameters'])) {
|
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();
|
$responseMap = $apiDoc->getParsedResponseMap();
|
||||||
@ -356,9 +369,12 @@ class SwaggerFormatter implements FormatterInterface
|
|||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @param array $models
|
* @param array $models
|
||||||
|
*
|
||||||
|
* @param string $paramType
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function deriveParameters(array $input, array &$models)
|
protected function deriveParameters(array $input, array &$models, $paramType = 'form')
|
||||||
{
|
{
|
||||||
|
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
@ -404,7 +420,7 @@ class SwaggerFormatter implements FormatterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$parameter = array(
|
$parameter = array(
|
||||||
'paramType' => 'form',
|
'paramType' => $paramType,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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.
|
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
|
##Configuration reference
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
Loading…
x
Reference in New Issue
Block a user