Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make Max Depth work with HAL #1971

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

Merged
merged 7 commits into from
May 31, 2018
Merged

Make Max Depth work with HAL #1971

merged 7 commits into from
May 31, 2018

Conversation

bendavies
Copy link
Contributor

@bendavies bendavies commented May 24, 2018

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Using @MaxDepth does not work with hal+json.
This is because relations are normalized separately from the parent:
https://github.com/api-platform/core/blob/master/src/Hal/Serializer/ItemNormalizer.php#L55-L63
so the context of max depth isn't checked.

{
if (
!isset($context[static::ENABLE_MAX_DEPTH]) ||
!isset($attributesMetadata[$attribute]) ||
Copy link
Member

Choose a reason for hiding this comment

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

Please add $context[static::ENABLE_MAX_DEPTH || now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, although there will now be a behavioral difference between hal and the other formats.

Copy link
Member

Choose a reason for hiding this comment

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

Until symfony/symfony#27365 is merged

@bendavies
Copy link
Contributor Author

don't merge. there is a bug here.

@bendavies
Copy link
Contributor Author

bendavies commented May 31, 2018

@dunglas this is done. I can't see how the failure is due to this PR


public function testMaxDepth()
{
$setId = function (MaxDepthDummy $dummy, int $id): void {
Copy link
Member

Choose a reason for hiding this comment

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

void isn't supported in PHP 7.0. It's why Travis is red.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed that, but there is a strange random behat failure.

@bendavies
Copy link
Contributor Author

@dunglas yep, random behat scenario passing on travis but failing on circleci.

@dunglas
Copy link
Member

dunglas commented May 31, 2018

It's not random, it uses an outdated version of the scenario: https://github.com/api-platform/core/blob/master/features/jsonld/context.feature#L21
Can you try to rebase and push force?

@bendavies
Copy link
Contributor Author

done, but i'm still not sure how it passed on travis and failed on circle 😆

@dunglas
Copy link
Member

dunglas commented May 31, 2018

Because Travis takes origin/2.2 and merges your branch in while Circle only checkouts your branch.

@bendavies
Copy link
Contributor Author

very good!

private function isMaxDepthReached(array $attributesMetadata, string $class, string $attribute, array &$context): bool
{
if (
!isset($context[static::ENABLE_MAX_DEPTH]) ||
Copy link
Member

@dunglas dunglas May 31, 2018

Choose a reason for hiding this comment

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

Can be ($context[static::ENABLE_MAX_DEPTH] ?? false) (not possible in Symfony because we still support PHP 5)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

almost, it's !($context[static::ENABLE_MAX_DEPTH] ?? false).
done

@bendavies bendavies changed the title Max Depth does not work with HAL Make Max Depth work with HAL May 31, 2018
@dunglas dunglas merged commit 5252559 into api-platform:2.2 May 31, 2018
@dunglas
Copy link
Member

dunglas commented May 31, 2018

Thanks @bendavies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants