mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 07:41:43 +03:00
* Allow to define several inputs
* Range Constraint parsing in the ValidationParser * Better formatting form Length constraint description * Allow to define the input name for the ValidationParser
This commit is contained in:
parent
4beb08e587
commit
391d0e32d0
@ -44,6 +44,11 @@ class ApiDoc
|
||||
*/
|
||||
private $input = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $inputs = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -165,6 +170,8 @@ class ApiDoc
|
||||
|
||||
if (isset($data['input'])) {
|
||||
$this->input = $data['input'];
|
||||
} elseif (isset($data['inputs'])) {
|
||||
$this->inputs = $data['inputs'];
|
||||
} elseif (isset($data['filters'])) {
|
||||
foreach ($data['filters'] as $filter) {
|
||||
if (!isset($filter['name'])) {
|
||||
@ -325,6 +332,14 @@ class ApiDoc
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getInputs()
|
||||
{
|
||||
return $this->inputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
|
@ -258,24 +258,32 @@ class ApiDocExtractor
|
||||
$annotation->setRoute($route);
|
||||
|
||||
// input (populates 'parameters' for the formatters)
|
||||
if (null !== $input = $annotation->getInput()) {
|
||||
$parameters = array();
|
||||
$normalizedInput = $this->normalizeClassParameter($input);
|
||||
$inputs = array();
|
||||
if (null !== $annotation->getInputs()) {
|
||||
$inputs = $annotation->getInputs();
|
||||
} elseif (null !== $annotation->getInput()) {
|
||||
$inputs[] = $annotation->getInput();
|
||||
}
|
||||
if (sizeof($inputs)) {
|
||||
$parameters = array();
|
||||
foreach ($inputs as $input) {
|
||||
$normalizedInput = $this->normalizeClassParameter($input);
|
||||
|
||||
$supportedParsers = array();
|
||||
foreach ($this->getParsers($normalizedInput) as $parser) {
|
||||
if ($parser->supports($normalizedInput)) {
|
||||
$supportedParsers[] = $parser;
|
||||
$parameters = $this->mergeParameters($parameters, $parser->parse($normalizedInput));
|
||||
$supportedParsers = array();
|
||||
foreach ($this->getParsers($normalizedInput) as $parser) {
|
||||
if ($parser->supports($normalizedInput)) {
|
||||
$supportedParsers[] = $parser;
|
||||
$parameters = $this->mergeParameters($parameters, $parser->parse($normalizedInput));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($supportedParsers as $parser) {
|
||||
if ($parser instanceof PostParserInterface) {
|
||||
$parameters = $this->mergeParameters(
|
||||
$parameters,
|
||||
$parser->postParse($normalizedInput, $parameters)
|
||||
);
|
||||
foreach ($supportedParsers as $parser) {
|
||||
if ($parser instanceof PostParserInterface) {
|
||||
$parameters = $this->mergeParameters(
|
||||
$parameters,
|
||||
$parser->postParse($normalizedInput, $parameters)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,31 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
{
|
||||
$className = $input['class'];
|
||||
|
||||
return $this->doParse($className, array());
|
||||
$result = $this->doParse($className, array());
|
||||
|
||||
if (!isset($input['name'])) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (class_exists($className)) {
|
||||
$parts = explode('\\', $className);
|
||||
$dataType = sprintf('object (%s)', end($parts));
|
||||
} else {
|
||||
$dataType = sprintf('object (%s)', $className);
|
||||
}
|
||||
|
||||
return array(
|
||||
$input['name'] => array(
|
||||
'required' => false,
|
||||
'readonly' => false,
|
||||
'description' => '',
|
||||
'default' => null,
|
||||
'dataType' => $dataType,
|
||||
'actualType' => DataTypes::MODEL,
|
||||
'subType' => $dataType,
|
||||
'children' => $result,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,6 +226,16 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
$vparams['format'][] = '{Time HH:MM:SS}';
|
||||
$vparams['actualType'] = DataTypes::TIME;
|
||||
break;
|
||||
case 'Range':
|
||||
$messages = array();
|
||||
if (isset($constraint->min)) {
|
||||
$messages[] = ">={$constraint->min}";
|
||||
}
|
||||
if (isset($constraint->max)) {
|
||||
$messages[] = "<={$constraint->max}";
|
||||
}
|
||||
$vparams['format'][] = '{range: {' . join(', ', $messages) . '}}';
|
||||
break;
|
||||
case 'Length':
|
||||
$messages = array();
|
||||
if (isset($constraint->min)) {
|
||||
@ -210,7 +244,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
if (isset($constraint->max)) {
|
||||
$messages[] = "max: {$constraint->max}";
|
||||
}
|
||||
$vparams['format'][] = '{length: ' . join(', ', $messages) . '}';
|
||||
$vparams['format'][] = '{length: {' . join(', ', $messages) . '}}';
|
||||
break;
|
||||
case 'Choice':
|
||||
$choices = $this->getChoices($constraint, $className);
|
||||
|
Loading…
x
Reference in New Issue
Block a user