Removed duplicated constraints in Format field. Improved format for field type of form

This commit is contained in:
Vitaliy Chesnokov 2019-04-24 19:56:39 +03:00
parent 39d640cce8
commit 8a6213cbd2
No known key found for this signature in database
GPG Key ID: FD23DF1B48ECC3EB
8 changed files with 19 additions and 14 deletions

View File

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

View File

@ -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') ?

View File

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

View File

@ -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 =>

View File

@ -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 (

View File

@ -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 (

View File

@ -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 (

View File

@ -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,