mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 07:41:43 +03:00
Removed duplicated constraints in Format field. Improved format for field type of form
This commit is contained in:
parent
39d640cce8
commit
8a6213cbd2
@ -442,7 +442,7 @@ class SwaggerFormatter implements FormatterInterface
|
||||
case DataTypes::ENUM:
|
||||
$type = 'string';
|
||||
if (isset($prop['format'])) {
|
||||
$enum = array_keys(json_decode($prop['format'], true));
|
||||
$enum = explode('|', rtrim(ltrim($prop['format'], '['), ']'));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -367,7 +367,11 @@ class FormTypeParser implements ParserInterface
|
||||
}
|
||||
|
||||
if (($choices = $config->getOption('choices')) && is_array($choices) && count($choices)) {
|
||||
$parameters[$name]['format'] = json_encode($choices);
|
||||
$choices = $config->getOption('choices_as_values') ?
|
||||
array_values($choices) :
|
||||
array_keys($choices);
|
||||
sort($choices);
|
||||
$parameters[$name]['format'] = '[' . join('|', $choices) . ']';
|
||||
} elseif ($choiceList = $config->getOption('choice_list')) {
|
||||
$choiceListType = $config->getType();
|
||||
$choiceListName = method_exists($choiceListType, 'getBlockPrefix') ?
|
||||
|
@ -137,7 +137,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
}
|
||||
|
||||
if (isset($vparams['format'])) {
|
||||
$vparams['format'] = join(', ', $vparams['format']);
|
||||
$vparams['format'] = join(', ', array_unique($vparams['format']));
|
||||
}
|
||||
|
||||
foreach (array('dataType', 'readonly', 'required', 'subType') as $reqprop) {
|
||||
@ -283,6 +283,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
|
||||
break;
|
||||
case 'Choice':
|
||||
$choices = $this->getChoices($constraint, $className);
|
||||
sort($choices);
|
||||
$format = '[' . join('|', $choices) . ']';
|
||||
if ($constraint->multiple) {
|
||||
$vparams['actualType'] = DataTypes::COLLECTION;
|
||||
|
@ -289,9 +289,9 @@ class SwaggerFormatterTest extends WebTestCase
|
||||
'type' => 'string',
|
||||
'enum' =>
|
||||
array(
|
||||
0 => 'x',
|
||||
1 => 'y',
|
||||
2 => 'z',
|
||||
0 => 'X',
|
||||
1 => 'Y',
|
||||
2 => 'Z',
|
||||
),
|
||||
),
|
||||
4 =>
|
||||
|
@ -466,7 +466,7 @@ With multiple lines.',
|
||||
'required' => true,
|
||||
'description' => NULL,
|
||||
'readonly' => false,
|
||||
'format' => '{"x":"X","y":"Y","z":"Z"}',
|
||||
'format' => '[X|Y|Z]',
|
||||
),
|
||||
'd' =>
|
||||
array (
|
||||
|
@ -464,7 +464,7 @@ With multiple lines.',
|
||||
'required' => true,
|
||||
'description' => NULL,
|
||||
'readonly' => false,
|
||||
'format' => '{"x":"X","y":"Y","z":"Z"}',
|
||||
'format' => '[X|Y|Z]',
|
||||
),
|
||||
'd' =>
|
||||
array (
|
||||
|
@ -121,7 +121,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
|
||||
'description' => '',
|
||||
'readonly' => false,
|
||||
),
|
||||
LegacyFormHelper::isLegacy() ? array() : array('format' => '{"foo":"bar","bazgroup":{"baz":"Buzz"}}',)
|
||||
LegacyFormHelper::isLegacy() ? array() : array('format' => '[bar|Array]',)
|
||||
);
|
||||
|
||||
return array(
|
||||
@ -446,7 +446,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
|
||||
'required' => true,
|
||||
'description' => '',
|
||||
'readonly' => false,
|
||||
'format' => json_encode(array('m' => 'Male', 'f' => 'Female')),
|
||||
'format' => '[Female|Male]',
|
||||
),
|
||||
'c2' => array(
|
||||
'dataType' => 'array of choices',
|
||||
@ -456,7 +456,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
|
||||
'required' => true,
|
||||
'description' => '',
|
||||
'readonly' => false,
|
||||
'format' => json_encode(array('m' => 'Male', 'f' => 'Female')),
|
||||
'format' => '[Female|Male]',
|
||||
),
|
||||
'c3' => array(
|
||||
'dataType' => 'choice',
|
||||
@ -475,7 +475,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
|
||||
'required' => true,
|
||||
'description' => '',
|
||||
'readonly' => false,
|
||||
'format' => '{"foo":"bar","bazgroup":{"baz":"Buzz"}}',
|
||||
'format' => '[bar|Array]',
|
||||
),
|
||||
'e1' => $entityData
|
||||
),
|
||||
@ -523,7 +523,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
|
||||
'required' => true,
|
||||
'description' => '',
|
||||
'readonly' => false,
|
||||
'format' => '{"x":"X","y":"Y","z":"Z"}',
|
||||
'format' => '[X|Y|Z]',
|
||||
),
|
||||
'd' =>
|
||||
array (
|
||||
|
@ -155,7 +155,7 @@ class ValidationParserTest extends WebTestCase
|
||||
array(
|
||||
'property' => 'multiplerangechoice',
|
||||
'expected' => array(
|
||||
'format' => '{min: 2 max: 3 choice of [foo|bar|baz|qux]}',
|
||||
'format' => '{min: 2 max: 3 choice of [bar|baz|foo|qux]}',
|
||||
'actualType' => DataTypes::COLLECTION,
|
||||
'subType' => DataTypes::ENUM,
|
||||
'default' => null,
|
||||
|
Loading…
x
Reference in New Issue
Block a user