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: case DataTypes::ENUM:
$type = 'string'; $type = 'string';
if (isset($prop['format'])) { if (isset($prop['format'])) {
$enum = array_keys(json_decode($prop['format'], true)); $enum = explode('|', rtrim(ltrim($prop['format'], '['), ']'));
} }
break; break;

View File

@ -367,7 +367,11 @@ class FormTypeParser implements ParserInterface
} }
if (($choices = $config->getOption('choices')) && is_array($choices) && count($choices)) { 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')) { } elseif ($choiceList = $config->getOption('choice_list')) {
$choiceListType = $config->getType(); $choiceListType = $config->getType();
$choiceListName = method_exists($choiceListType, 'getBlockPrefix') ? $choiceListName = method_exists($choiceListType, 'getBlockPrefix') ?

View File

@ -137,7 +137,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
} }
if (isset($vparams['format'])) { if (isset($vparams['format'])) {
$vparams['format'] = join(', ', $vparams['format']); $vparams['format'] = join(', ', array_unique($vparams['format']));
} }
foreach (array('dataType', 'readonly', 'required', 'subType') as $reqprop) { foreach (array('dataType', 'readonly', 'required', 'subType') as $reqprop) {
@ -283,6 +283,7 @@ class ValidationParser implements ParserInterface, PostParserInterface
break; break;
case 'Choice': case 'Choice':
$choices = $this->getChoices($constraint, $className); $choices = $this->getChoices($constraint, $className);
sort($choices);
$format = '[' . join('|', $choices) . ']'; $format = '[' . join('|', $choices) . ']';
if ($constraint->multiple) { if ($constraint->multiple) {
$vparams['actualType'] = DataTypes::COLLECTION; $vparams['actualType'] = DataTypes::COLLECTION;

View File

@ -289,9 +289,9 @@ class SwaggerFormatterTest extends WebTestCase
'type' => 'string', 'type' => 'string',
'enum' => 'enum' =>
array( array(
0 => 'x', 0 => 'X',
1 => 'y', 1 => 'Y',
2 => 'z', 2 => 'Z',
), ),
), ),
4 => 4 =>

View File

@ -466,7 +466,7 @@ With multiple lines.',
'required' => true, 'required' => true,
'description' => NULL, 'description' => NULL,
'readonly' => false, 'readonly' => false,
'format' => '{"x":"X","y":"Y","z":"Z"}', 'format' => '[X|Y|Z]',
), ),
'd' => 'd' =>
array ( array (

View File

@ -464,7 +464,7 @@ With multiple lines.',
'required' => true, 'required' => true,
'description' => NULL, 'description' => NULL,
'readonly' => false, 'readonly' => false,
'format' => '{"x":"X","y":"Y","z":"Z"}', 'format' => '[X|Y|Z]',
), ),
'd' => 'd' =>
array ( array (

View File

@ -121,7 +121,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
'description' => '', 'description' => '',
'readonly' => false, 'readonly' => false,
), ),
LegacyFormHelper::isLegacy() ? array() : array('format' => '{"foo":"bar","bazgroup":{"baz":"Buzz"}}',) LegacyFormHelper::isLegacy() ? array() : array('format' => '[bar|Array]',)
); );
return array( return array(
@ -446,7 +446,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
'required' => true, 'required' => true,
'description' => '', 'description' => '',
'readonly' => false, 'readonly' => false,
'format' => json_encode(array('m' => 'Male', 'f' => 'Female')), 'format' => '[Female|Male]',
), ),
'c2' => array( 'c2' => array(
'dataType' => 'array of choices', 'dataType' => 'array of choices',
@ -456,7 +456,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
'required' => true, 'required' => true,
'description' => '', 'description' => '',
'readonly' => false, 'readonly' => false,
'format' => json_encode(array('m' => 'Male', 'f' => 'Female')), 'format' => '[Female|Male]',
), ),
'c3' => array( 'c3' => array(
'dataType' => 'choice', 'dataType' => 'choice',
@ -475,7 +475,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
'required' => true, 'required' => true,
'description' => '', 'description' => '',
'readonly' => false, 'readonly' => false,
'format' => '{"foo":"bar","bazgroup":{"baz":"Buzz"}}', 'format' => '[bar|Array]',
), ),
'e1' => $entityData 'e1' => $entityData
), ),
@ -523,7 +523,7 @@ class FormTypeParserTest extends \PHPUnit_Framework_TestCase
'required' => true, 'required' => true,
'description' => '', 'description' => '',
'readonly' => false, 'readonly' => false,
'format' => '{"x":"X","y":"Y","z":"Z"}', 'format' => '[X|Y|Z]',
), ),
'd' => 'd' =>
array ( array (

View File

@ -155,7 +155,7 @@ class ValidationParserTest extends WebTestCase
array( array(
'property' => 'multiplerangechoice', 'property' => 'multiplerangechoice',
'expected' => array( '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, 'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM, 'subType' => DataTypes::ENUM,
'default' => null, 'default' => null,