mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 08:09:25 +03:00
Merge pull request #1285 from jlekowski/master
Fix #1283: Invalid swagger.json generation - definition for entities …
This commit is contained in:
commit
f464fef932
@ -97,7 +97,7 @@ class SymfonyConstraintAnnotationReader
|
|||||||
|
|
||||||
$existingRequiredFields[] = $reflectionProperty->getName();
|
$existingRequiredFields[] = $reflectionProperty->getName();
|
||||||
|
|
||||||
$this->schema->setRequired(array_unique($existingRequiredFields));
|
$this->schema->setRequired(array_values(array_unique($existingRequiredFields)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the NelmioApiDocBundle package.
|
||||||
|
*
|
||||||
|
* (c) Nelmio
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Nelmio\ApiDocBundle\Tests\ModelDescriber\Annotations;
|
||||||
|
|
||||||
|
use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
|
use EXSyst\Component\Swagger\Schema;
|
||||||
|
use Nelmio\ApiDocBundle\ModelDescriber\Annotations\SymfonyConstraintAnnotationReader;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
class SymfonyConstraintAnnotationReaderTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testUpdatePropertyFix1283()
|
||||||
|
{
|
||||||
|
$entity = new class() {
|
||||||
|
/**
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
* @Assert\Length(min = 1)
|
||||||
|
*/
|
||||||
|
private $property1;
|
||||||
|
/**
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
private $property2;
|
||||||
|
};
|
||||||
|
$reflectionProperties = (new \ReflectionClass($entity))->getProperties();
|
||||||
|
$property = new Schema();
|
||||||
|
$schema = new Schema();
|
||||||
|
|
||||||
|
$symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader());
|
||||||
|
$symfonyConstraintAnnotationReader->setSchema($schema);
|
||||||
|
foreach ($reflectionProperties as $reflectionProperty) {
|
||||||
|
$symfonyConstraintAnnotationReader->updateProperty($reflectionProperty, $property);
|
||||||
|
}
|
||||||
|
|
||||||
|
// expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...])
|
||||||
|
$this->assertEquals($schema->getRequired(), ['property1', 'property2']);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user