mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Merge pull request #1452 from BigZ/feature/add-new-assert-uses
feature: Add new validation from constraints.
This commit is contained in:
commit
61b1ed35ad
@ -63,8 +63,6 @@ class SymfonyConstraintAnnotationReader
|
||||
$property->setMaxLength($annotation->max);
|
||||
} elseif ($annotation instanceof Assert\Regex) {
|
||||
$this->appendPattern($property, $annotation->getHtmlPattern());
|
||||
} elseif ($annotation instanceof Assert\DateTime) {
|
||||
$this->appendPattern($property, $annotation->format);
|
||||
} elseif ($annotation instanceof Assert\Count) {
|
||||
$property->setMinItems($annotation->min);
|
||||
$property->setMaxItems($annotation->max);
|
||||
@ -72,6 +70,13 @@ class SymfonyConstraintAnnotationReader
|
||||
$property->setEnum($annotation->callback ? call_user_func(is_array($annotation->callback) ? $annotation->callback : [$reflectionProperty->class, $annotation->callback]) : $annotation->choices);
|
||||
} elseif ($annotation instanceof Assert\Expression) {
|
||||
$this->appendPattern($property, $annotation->message);
|
||||
} elseif ($annotation instanceof Assert\Range) {
|
||||
$property->setMinimum($annotation->min);
|
||||
$property->setMaximum($annotation->max);
|
||||
} elseif ($annotation instanceof Assert\LessThan) {
|
||||
$property->setExclusiveMaximum($annotation->value);
|
||||
} elseif ($annotation instanceof Assert\LessThanOrEqual) {
|
||||
$property->setMaximum($annotation->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,27 @@ class SymfonyConstraints
|
||||
*/
|
||||
private $propertyExpression;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @Assert\Range(min=1, max=5)
|
||||
*/
|
||||
private $propertyRange;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @Assert\LessThan(42)
|
||||
*/
|
||||
private $propertyLessThan;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @Assert\LessThanOrEqual(23)
|
||||
*/
|
||||
private $propertyLessThanOrEqual;
|
||||
|
||||
/**
|
||||
* @param int $propertyNotBlank
|
||||
*/
|
||||
@ -153,6 +174,30 @@ class SymfonyConstraints
|
||||
$this->propertyExpression = $propertyExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propertyRange
|
||||
*/
|
||||
public function setPropertyRange(int $propertyRange): void
|
||||
{
|
||||
$this->propertyRange = $propertyRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propertyLessThan
|
||||
*/
|
||||
public function setPropertyLessThan(int $propertyLessThan): void
|
||||
{
|
||||
$this->propertyLessThan = $propertyLessThan;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propertyLessThanOrEqual
|
||||
*/
|
||||
public function setPropertyLessThanOrEqual(int $propertyLessThanOrEqual): void
|
||||
{
|
||||
$this->propertyLessThanOrEqual = $propertyLessThanOrEqual;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -385,6 +385,19 @@ class FunctionalTest extends WebTestCase
|
||||
'type' => 'integer',
|
||||
'pattern' => 'If this is a tech post, the category should be either php or symfony!',
|
||||
],
|
||||
'propertyRange' => [
|
||||
'type' => 'integer',
|
||||
'maximum' => 5,
|
||||
'minimum' => 1,
|
||||
],
|
||||
'propertyLessThan' => [
|
||||
'type' => 'integer',
|
||||
'exclusiveMaximum' => 42,
|
||||
],
|
||||
'propertyLessThanOrEqual' => [
|
||||
'type' => 'integer',
|
||||
'maximum' => 23,
|
||||
],
|
||||
],
|
||||
'type' => 'object',
|
||||
], $this->getModel('SymfonyConstraints')->toArray());
|
||||
|
Loading…
x
Reference in New Issue
Block a user