Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Swagger's DocumentationNormalizer #740

Merged
merged 2 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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($options['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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the logic related to this whole function needs to be reviewed. I gave it a quick look and things look very fishy here.

{
$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', []),
Copy link
Contributor

@teohhanhui teohhanhui Sep 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there union of item + collection operation attributes going on? Only one of them can be applicable at a time.

Even if the intention is to only get one of them, what about collection and item operations with the same name? Too risky...

Copy link
Member Author

@dunglas dunglas Sep 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I 100% agree, this must be investigated. But this PR doesn't change the behavior, it's just a style fix. I propose to refactor this method in another PR. WDYT?

'normalization_context' => $resourceMetadata->getItemOperationAttribute($operationName, 'normalization_context', []) + $resourceMetadata->getCollectionOperationAttribute($operationName, 'normalization_context', []),
];

$options = [
Expand Down
Loading