Skip to content

Commit

Permalink
Merge pull request #1285 from jlekowski/master
Browse files Browse the repository at this point in the history
Fix #1283: Invalid swagger.json generation - definition for entities …
  • Loading branch information
GuilhemN authored Apr 9, 2018
2 parents ff590b0 + 3b2d9da commit f464fef
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function updateSchemaDefinitionWithRequiredProperty(\ReflectionProperty

$existingRequiredFields[] = $reflectionProperty->getName();

$this->schema->setRequired(array_unique($existingRequiredFields));
$this->schema->setRequired(array_values(array_unique($existingRequiredFields)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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']);
}
}

0 comments on commit f464fef

Please sign in to comment.