diff --git a/Formatter/SwaggerFormatter.php b/Formatter/SwaggerFormatter.php index 33caba7..2de44ed 100644 --- a/Formatter/SwaggerFormatter.php +++ b/Formatter/SwaggerFormatter.php @@ -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; diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index 2ea8bc7..98dbb83 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -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') ? diff --git a/Parser/ValidationParser.php b/Parser/ValidationParser.php index 3dcc63a..af13a1b 100644 --- a/Parser/ValidationParser.php +++ b/Parser/ValidationParser.php @@ -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; diff --git a/Tests/Formatter/SwaggerFormatterTest.php b/Tests/Formatter/SwaggerFormatterTest.php index b321f41..339bea8 100644 --- a/Tests/Formatter/SwaggerFormatterTest.php +++ b/Tests/Formatter/SwaggerFormatterTest.php @@ -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 => diff --git a/Tests/Formatter/testFormat-result-no-dunglas.php b/Tests/Formatter/testFormat-result-no-dunglas.php index ff3d08b..a2a9a10 100644 --- a/Tests/Formatter/testFormat-result-no-dunglas.php +++ b/Tests/Formatter/testFormat-result-no-dunglas.php @@ -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 ( diff --git a/Tests/Formatter/testFormat-result.php b/Tests/Formatter/testFormat-result.php index f72063f..92f44e1 100644 --- a/Tests/Formatter/testFormat-result.php +++ b/Tests/Formatter/testFormat-result.php @@ -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 ( diff --git a/Tests/Parser/FormTypeParserTest.php b/Tests/Parser/FormTypeParserTest.php index 5222859..37d87ae 100644 --- a/Tests/Parser/FormTypeParserTest.php +++ b/Tests/Parser/FormTypeParserTest.php @@ -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 ( diff --git a/Tests/Parser/ValidationParserTest.php b/Tests/Parser/ValidationParserTest.php index c8a6299..c21ac7f 100644 --- a/Tests/Parser/ValidationParserTest.php +++ b/Tests/Parser/ValidationParserTest.php @@ -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,