mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 07:41:43 +03:00
Fix parsing of filters, default values, descriptions and base path in SwaggerFormatter
This commit is contained in:
parent
6bcd5e8d81
commit
b8cc4d9264
@ -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;
|
||||
}
|
||||
|
@ -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 (
|
||||
|
Loading…
x
Reference in New Issue
Block a user