* 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:
Ilyas Salikhov 2014-11-02 12:52:29 +03:00
parent 4beb08e587
commit 391d0e32d0
3 changed files with 74 additions and 17 deletions

View File

@ -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
*/

View File

@ -258,8 +258,15 @@ class ApiDocExtractor
$annotation->setRoute($route);
// input (populates 'parameters' for the formatters)
if (null !== $input = $annotation->getInput()) {
$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();
@ -278,6 +285,7 @@ class ApiDocExtractor
);
}
}
}
$parameters = $this->clearClasses($parameters);
$parameters = $this->generateHumanReadableTypes($parameters);

View File

@ -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);