Skip to content

Commit

Permalink
Fix a bug in the NelmioApiDoc bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Sep 8, 2016
1 parent eef31df commit 764fcd4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Action/ExceptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(SerializerInterface $serializer, array $errorFormats
{
$this->serializer = $serializer;
$this->errorFormats = $errorFormats;
$this->exceptionToStatus = array_merge(self::DEFAULT_EXCEPTION_TO_STATUS, $exceptionToStatus);
$this->exceptionToStatus = self::DEFAULT_EXCEPTION_TO_STATUS + $exceptionToStatus;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/Bridge/NelmioApiDoc/Parser/ApiPlatformParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ private function parseResource(ResourceMetadata $resourceMetadata, string $resou
}

if (isset($attributes['denormalization_context']['groups'])) {
$options['serializer_groups'] = isset($options['serializer_groups']) ? array_merge($options['serializer_groups'], $attributes['denormalization_context']['groups']) : $options['serializer_groups'];
if (isset($context['serializer_groups'])) {
$options['serializer_groups'] += $attributes['denormalization_context']['groups'];
} else {
$options['serializer_groups'] = $attributes['denormalization_context']['groups'];
}
}

return $this->getPropertyMetadata($resourceMetadata, $resourceClass, $io, $visited, $options);
Expand All @@ -129,8 +133,8 @@ private function parseResource(ResourceMetadata $resourceMetadata, string $resou
private function getGroupsForItemAndCollectionOperation(ResourceMetadata $resourceMetadata, string $operationName) : array
{
$operation = [
'denormalization_context' => array_merge($resourceMetadata->getItemOperationAttribute($operationName, 'denormalization_context', []), $resourceMetadata->getCollectionOperationAttribute($operationName, 'denormalization_context', [])),
'normalization_context' => array_merge($resourceMetadata->getItemOperationAttribute($operationName, 'normalization_context', []), $resourceMetadata->getCollectionOperationAttribute($operationName, 'normalization_context', [])),
'denormalization_context' => $resourceMetadata->getItemOperationAttribute($operationName, 'denormalization_context', []) + $resourceMetadata->getCollectionOperationAttribute($operationName, 'denormalization_context', []),
'normalization_context' => $resourceMetadata->getItemOperationAttribute($operationName, 'normalization_context', []) + $resourceMetadata->getCollectionOperationAttribute($operationName, 'normalization_context', []),
];

$options = [
Expand Down
10 changes: 3 additions & 7 deletions src/Swagger/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ private function getPropertySchema(PropertyMetadata $propertyMetadata) : \ArrayO
break;

case Type::BUILTIN_TYPE_OBJECT:
$className = $valueType->getClassName();
if (null === $className) {
if (null === $className = $valueType->getClassName()) {
break;
}

Expand All @@ -350,24 +349,21 @@ private function getPropertySchema(PropertyMetadata $propertyMetadata) : \ArrayO
break;
}

if ($propertyMetadata->isReadableLink()) {
if (true === $propertyMetadata->isReadableLink()) {
$valueSchema['$ref'] = sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName());
break;
}

$valueSchema['type'] = 'string';
$valueSchema['format'] = 'uri';
break;

default:
break;
}

if ($type->isCollection()) {
$propertySchema['type'] = 'array';
$propertySchema['items'] = $valueSchema;
} else {
$propertySchema = new \ArrayObject(array_merge((array) $propertySchema, (array) $valueSchema));
$propertySchema = new \ArrayObject((array) $propertySchema + (array) $valueSchema);
}

return $propertySchema;
Expand Down

0 comments on commit 764fcd4

Please sign in to comment.