Fix the Util class manipulation of array of objects (#1653)

* Fix the Util class manipulation of array of objects

* fix cs
This commit is contained in:
Guilhem Niot 2020-06-17 14:12:44 +02:00 committed by GitHub
parent d932b06bbb
commit 3623bdb1ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 5 deletions

View File

@ -455,11 +455,27 @@ final class Util
private static function mergeTyped(OA\AbstractAnnotation $annotation, $propertyName, $type, array $properties, array $defaults, bool $overwrite)
{
if (\is_string($type) && 0 === strpos($type, '[')) {
/* type is declared as array in @see OA\AbstractAnnotation::$_types */
$annotation->{$propertyName} = array_unique(array_merge(
$annotation->{$propertyName} && UNDEFINED !== $annotation->{$propertyName} ? $annotation->{$propertyName} : [],
$properties[$propertyName]
));
$innerType = substr($type, 1, -1);
if (!$annotation->{$propertyName} || UNDEFINED === $annotation->{$propertyName}) {
$annotation->{$propertyName} = [];
}
if (!class_exists($innerType)) {
/* type is declared as array in @see OA\AbstractAnnotation::$_types */
$annotation->{$propertyName} = array_unique(array_merge(
$annotation->{$propertyName},
$properties[$propertyName]
));
return;
}
// $type == [Schema] for instance
foreach ($properties[$propertyName] as $child) {
$annotation->{$propertyName}[] = $annot = self::createChild($annotation, $innerType, []);
self::merge($annot, $child, $overwrite);
}
} else {
self::mergeProperty($annotation, $propertyName, $properties[$propertyName], $defaults[$propertyName], $overwrite);
}

View File

@ -176,6 +176,17 @@ class TestKernel extends Kernel
'Test' => [
'type' => 'string',
],
// Ensures https://github.com/nelmio/NelmioApiDocBundle/issues/1650 is working
'Pet' => [
'type' => 'object',
],
'Cat' => [
'allOf' => [
['$ref' => '#/components/schemas/Pet'],
['type' => 'object'],
],
],
],
'parameters' => [
'test' => [