mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
fix(SymfonyConstraintAnnotationReader): fixed enum guessing in Assert… (#1325)
* fix(SymfonyConstraintAnnotationReader): fixed enum guessing in Assert\Choicewhen callback parameter is used * fix(SymfonyConstraints): turn double quotes in single quotes
This commit is contained in:
parent
4954feb232
commit
c2f036c159
@ -70,7 +70,7 @@ class SymfonyConstraintAnnotationReader
|
||||
}
|
||||
|
||||
if ($annotation instanceof Assert\Choice) {
|
||||
$property->setEnum($annotation->choices);
|
||||
$property->setEnum($annotation->callback ? call_user_func($annotation->callback) : $annotation->choices);
|
||||
}
|
||||
|
||||
if ($annotation instanceof Assert\Expression) {
|
||||
|
@ -64,6 +64,13 @@ class SymfonyConstraints
|
||||
*/
|
||||
private $propertyChoice;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @Assert\Choice(callback={SymfonyConstraints::class,"fetchAllowedChoices"})
|
||||
*/
|
||||
private $propertyChoiceWithCallback;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
@ -130,6 +137,14 @@ class SymfonyConstraints
|
||||
$this->propertyChoice = $propertyChoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propertyChoiceWithCallback
|
||||
*/
|
||||
public function setPropertyChoiceWithCallback(int $propertyChoiceWithCallback): void
|
||||
{
|
||||
$this->propertyChoiceWithCallback = $propertyChoiceWithCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propertyExpression
|
||||
*/
|
||||
@ -137,4 +152,12 @@ class SymfonyConstraints
|
||||
{
|
||||
$this->propertyExpression = $propertyExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function fetchAllowedChoices()
|
||||
{
|
||||
return ['choice1', 'choice2'];
|
||||
}
|
||||
}
|
||||
|
@ -341,6 +341,10 @@ class FunctionalTest extends WebTestCase
|
||||
'type' => 'integer',
|
||||
'enum' => ['choice1', 'choice2'],
|
||||
],
|
||||
'propertyChoiceWithCallback' => [
|
||||
'type' => 'integer',
|
||||
'enum' => ['choice1', 'choice2'],
|
||||
],
|
||||
'propertyExpression' => [
|
||||
'type' => 'integer',
|
||||
'pattern' => 'If this is a tech post, the category should be either php or symfony!',
|
||||
|
Loading…
x
Reference in New Issue
Block a user