Merge pull request #1285 from jlekowski/master

Fix #1283: Invalid swagger.json generation - definition for entities …
This commit is contained in:
Guilhem N 2018-04-09 12:04:42 +02:00 committed by GitHub
commit f464fef932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View File

@ -97,7 +97,7 @@ class SymfonyConstraintAnnotationReader
$existingRequiredFields[] = $reflectionProperty->getName();
$this->schema->setRequired(array_unique($existingRequiredFields));
$this->schema->setRequired(array_values(array_unique($existingRequiredFields)));
}
/**

View File

@ -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']);
}
}