Fix parsing of filters, default values, descriptions and base path in SwaggerFormatter

This commit is contained in:
Martin Janser 2014-09-22 15:26:38 +02:00
parent 6bcd5e8d81
commit b8cc4d9264
2 changed files with 38 additions and 17 deletions

View File

@ -218,7 +218,7 @@ class SwaggerFormatter implements FormatterInterface
} elseif (empty($input['paramType'])) {
$input['paramType'] = 'form';
}
$route = $apiDoc->getRoute();
$itemResource = $this->normalizeResourcePath($itemResource);
@ -253,12 +253,12 @@ class SwaggerFormatter implements FormatterInterface
$parameters[] = $parameter;
}
$data = $apiDoc->toArray();
if (isset($data['filters'])) {
$parameters = array_merge($parameters, $this->deriveQueryParameters($data['filters']));
}
$data = $apiDoc->toArray();
if (isset($data['parameters'])) {
$parameters = array_merge($parameters, $this->deriveParameters($data['parameters'], $input['paramType']));
}
@ -392,10 +392,14 @@ class SwaggerFormatter implements FormatterInterface
$parameters = array();
foreach ($input as $name => $prop) {
if (!isset($prop['dataType'])) {
$prop['dataType'] = 'string';
}
$parameters[] = array(
'paramType' => 'query',
'name' => $name,
'type' => isset($this->typeMap[$prop['dataType']]) ? $this->typeMap[$prop['dataType']] : 'string',
'description' => isset($prop['description']) ? $prop['description'] : null,
);
}
@ -426,6 +430,10 @@ class SwaggerFormatter implements FormatterInterface
$enum = null;
$items = null;
if (!isset($prop['actualType'])) {
$prop['actualType'] = 'string';
}
if (isset ($this->typeMap[$prop['actualType']])) {
$type = $this->typeMap[$prop['actualType']];
} else {
@ -498,7 +506,7 @@ class SwaggerFormatter implements FormatterInterface
$parameter['enum'] = $enum;
}
if ($prop['default'] !== null) {
if (isset($prop['default'])) {
$parameter['defaultValue'] = $prop['default'];
}
@ -506,6 +514,10 @@ class SwaggerFormatter implements FormatterInterface
$parameter['items'] = $items;
}
if (isset($prop['description'])) {
$parameter['description'] = $prop['description'];
}
$parameters[] = $parameter;
}
@ -559,7 +571,11 @@ class SwaggerFormatter implements FormatterInterface
*/
protected function stripBasePath($path)
{
$pattern = sprintf('#%s#', preg_quote($this->basePath));
if ('/' === $this->basePath) {
return $path;
}
$pattern = sprintf('#^%s#', preg_quote($this->basePath));
$subPath = preg_replace($pattern, '', $path);
return $subPath;
}

View File

@ -195,6 +195,7 @@ class SwaggerFormatterTest extends WebTestCase
'paramType' => 'form',
'name' => 'a',
'type' => 'string',
'description' => 'Something that describes A.',
),
2 =>
array (
@ -786,6 +787,18 @@ With multiple lines.',
'type' => 'string',
'required' => true,
),
array (
'paramType' => 'query',
'name' => 'a',
'type' => 'integer',
'description' => null,
),
array (
'paramType' => 'query',
'name' => 'b',
'type' => 'string',
'description' => null,
),
),
'responseMessages' =>
array (
@ -810,12 +823,14 @@ With multiple lines.',
'paramType' => 'query',
'name' => 'a',
'type' => 'integer',
'description' => null,
),
array (
'paramType' => 'query',
'name' => 'b',
'type' => 'string',
'description' => null,
),
),
'responseMessages' =>
@ -837,22 +852,11 @@ With multiple lines.',
'required' => true,
),
array (
'paramType' => 'query',
'name' => 'a',
'type' => 'integer',
),
array (
'paramType' => 'query',
'name' => 'b',
'type' => 'string',
),
array (
'paramType' => 'form',
'name' => 'a',
'type' => 'string',
'description' => 'A nice description',
),
array (
@ -898,6 +902,7 @@ With multiple lines.',
'paramType' => 'form',
'name' => 'a',
'type' => 'string',
'description' => 'A nice description',
),
array (