mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-10 11:39:25 +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) {
|
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) {
|
if ($annotation instanceof Assert\Expression) {
|
||||||
|
@ -64,6 +64,13 @@ class SymfonyConstraints
|
|||||||
*/
|
*/
|
||||||
private $propertyChoice;
|
private $propertyChoice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*
|
||||||
|
* @Assert\Choice(callback={SymfonyConstraints::class,"fetchAllowedChoices"})
|
||||||
|
*/
|
||||||
|
private $propertyChoiceWithCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*
|
*
|
||||||
@ -130,6 +137,14 @@ class SymfonyConstraints
|
|||||||
$this->propertyChoice = $propertyChoice;
|
$this->propertyChoice = $propertyChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $propertyChoiceWithCallback
|
||||||
|
*/
|
||||||
|
public function setPropertyChoiceWithCallback(int $propertyChoiceWithCallback): void
|
||||||
|
{
|
||||||
|
$this->propertyChoiceWithCallback = $propertyChoiceWithCallback;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $propertyExpression
|
* @param int $propertyExpression
|
||||||
*/
|
*/
|
||||||
@ -137,4 +152,12 @@ class SymfonyConstraints
|
|||||||
{
|
{
|
||||||
$this->propertyExpression = $propertyExpression;
|
$this->propertyExpression = $propertyExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function fetchAllowedChoices()
|
||||||
|
{
|
||||||
|
return ['choice1', 'choice2'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,6 +341,10 @@ class FunctionalTest extends WebTestCase
|
|||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'enum' => ['choice1', 'choice2'],
|
'enum' => ['choice1', 'choice2'],
|
||||||
],
|
],
|
||||||
|
'propertyChoiceWithCallback' => [
|
||||||
|
'type' => 'integer',
|
||||||
|
'enum' => ['choice1', 'choice2'],
|
||||||
|
],
|
||||||
'propertyExpression' => [
|
'propertyExpression' => [
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'pattern' => 'If this is a tech post, the category should be either php or symfony!',
|
'pattern' => 'If this is a tech post, the category should be either php or symfony!',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user