Skip to content

Commit

Permalink
Merge 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Nov 22, 2024
2 parents 1b7fd9c + 717c7e5 commit de808dd
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ Notes:

* [0d5f35683](https://github.com/api-platform/core/commit/0d5f356839eb6aa9f536044abe4affa736553e76) feat(laravel): laravel component (#5882)

## v3.4.7

### Bug fixes

* [2d25e79e0](https://github.com/api-platform/core/commit/2d25e79e0e04ce549fb67ecc2017798a8deb7458) fix(symfony): unset item_uri_template when serializing an error (#6816)

## v3.4.6

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function __construct(
* 'jsonapi' => ['application/vnd.api+json'],
* 'json' => ['application/json'],
* 'xml' => ['application/xml', 'text/xml'],
* 'yaml' => ['application/x-yaml'],
* 'yaml' => ['application/yaml'],
* 'csv' => ['text/csv'],
* 'html' => ['text/html'],
* 'myformat' =>['application/vnd.myformat'],
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/EventListener/ErrorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ protected function duplicateRequest(\Throwable $exception, Request $request): Re
$normalizationContext += ['api_error_resource' => true];
}

if (isset($normalizationContext['item_uri_template'])) {
unset($normalizationContext['item_uri_template']);
}

if (!isset($normalizationContext[AbstractObjectNormalizer::IGNORED_ATTRIBUTES])) {
$normalizationContext[AbstractObjectNormalizer::IGNORED_ATTRIBUTES] = ['trace', 'file', 'line', 'code', 'message', 'traceAsString'];
}
Expand Down
56 changes: 56 additions & 0 deletions tests/Fixtures/TestBundle/ApiResource/Issue6718/Organization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6718;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Operation;

#[ApiResource(
shortName: 'OrganisationIssue6718',
extraProperties: ['rfc_7807_compliant_errors' => true],
operations: [
new Get(
uriTemplate: '/6718_organisations/{id}',
provider: [self::class, 'itemProvider'],
),
new Get(
uriTemplate: '/6718_users/{userId}/organisation',
uriVariables: [
'userId',
],
normalizationContext: [
'item_uri_template' => '/6718_organisations/{id}',
'hydra_prefix' => false,
],
provider: [self::class, 'userOrganizationItemProvider']
),
],
)]
class Organization
{
public function __construct(public readonly string $id)
{
}

public static function itemProvider(Operation $operation, array $uriVariables = []): ?self
{
return new self($uriVariables['id']);
}

public static function userOrganizationItemProvider(): ?self
{
return null;
}
}
28 changes: 28 additions & 0 deletions tests/Functional/ItemUriTemplateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Functional;

use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;

class ItemUriTemplateTest extends ApiTestCase
{
public function testIssue6718(): void
{
self::createClient()->request('GET', '/6718_users/1/organisation', [
'headers' => ['accept' => 'application/ld+json'],
]);
$this->assertResponseStatusCodeSame(404);
$this->assertJsonContains(['description' => 'Not Found']);
}
}

0 comments on commit de808dd

Please sign in to comment.