Skip to content

Commit 5e4b1da

Browse files
committed
Merge 3.1
2 parents 566727b + ebf0310 commit 5e4b1da

20 files changed

+397
-42
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
### Bug fixes
66

77
* [0c1c1c36f](https://github.com/api-platform/core/commit/0c1c1c36f55ba96119e6c22ea25fb69c85b20161) fix(symfony): enable API Platform in LexikJWTAuthenticationBundle (#5609)
8+
9+
10+
You can disable this behaviour by setting the configuration key `lexik_jwt_authentication.api_platform.enabled` to `false`
11+
812
* [146991ba4](https://github.com/api-platform/core/commit/146991ba42014f0141195bc43be5cd875665407c) fix(openapi): merge parameters with deprecated openApiContext (#5703)
913
* [14969aa0c](https://github.com/api-platform/core/commit/14969aa0c6f021bb4bf3e9d13b00e710c22110de) fix(serializer): put replaces embed collection (#5604)
1014
* [9cb0ee43c](https://github.com/api-platform/core/commit/9cb0ee43c175927f3002e86d23443d8d43fa14b3) fix(metadata): missing xml/yaml properties (#5684)

features/doctrine/separated_resource.feature

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Use state options to use an entity that is not a resource
55

66
@!mongodb
77
@createSchema
8-
Scenario: Get collection
8+
Scenario: Get collection
99
Given there are 5 separated entities
1010
When I send a "GET" request to "/separated_entities"
1111
Then the response status code should be 200
@@ -35,7 +35,7 @@ Feature: Use state options to use an entity that is not a resource
3535

3636
@!mongodb
3737
@createSchema
38-
Scenario: Get ordered collection
38+
Scenario: Get ordered collection
3939
Given there are 5 separated entities
4040
When I send a "GET" request to "/separated_entities?order[value]=desc"
4141
Then the response status code should be 200
@@ -45,10 +45,32 @@ Feature: Use state options to use an entity that is not a resource
4545

4646
@!mongodb
4747
@createSchema
48-
Scenario: Get item
48+
Scenario: Get item
4949
Given there are 5 separated entities
5050
When I send a "GET" request to "/separated_entities/1"
51-
Then print last JSON response
5251
Then the response status code should be 200
5352
And the response should be in JSON
5453
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
54+
55+
@!mongodb
56+
@createSchema
57+
Scenario: Get item
58+
Given there are 5 separated entities
59+
When I send a "GET" request to "/separated_entities/1"
60+
Then the response status code should be 200
61+
And the response should be in JSON
62+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
63+
64+
@!mongodb
65+
@createSchema
66+
Scenario: Get all EntityClassAndCustomProviderResources
67+
Given there are 1 separated entities
68+
When I send a "GET" request to "/entityClassAndCustomProviderResources"
69+
Then the response status code should be 200
70+
71+
@!mongodb
72+
@createSchema
73+
Scenario: Get one EntityClassAndCustomProviderResource
74+
Given there are 1 separated entities
75+
When I send a "GET" request to "/entityClassAndCustomProviderResources/1"
76+
Then the response status code should be 200

features/main/crud_uri_variables.feature

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,3 @@ Feature: Uri Variables
200200
When I add "Content-Type" header equal to "application/ld+json"
201201
And I send a "GET" request to "/companies/1/employees/2"
202202
Then the response status code should be 404
203-
204-
@!mongodb
205-
Scenario: Get all EntityClassAndCustomProviderResources
206-
Given there are 1 separated entities
207-
When I send a "GET" request to "/entityClassAndCustomProviderResources"
208-
Then the response status code should be 200
209-
210-
@!mongodb
211-
Scenario: Get one EntityClassAndCustomProviderResource
212-
Given there are 1 separated entities
213-
When I send a "GET" request to "/entityClassAndCustomProviderResources/1"
214-
Then the response status code should be 200

src/Metadata/NotExposed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(
4545
bool $stateless = null,
4646
string $sunset = null,
4747
string $acceptPatch = null,
48-
$status = null,
48+
$status = 404,
4949
string $host = null,
5050
array $schemes = null,
5151
string $condition = null,

src/Metadata/Resource/Factory/LinkFactory.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Metadata\Resource\Factory;
1515

16-
use ApiPlatform\Doctrine\Orm\State\Options;
1716
use ApiPlatform\Metadata\Exception\RuntimeException;
1817
use ApiPlatform\Metadata\Link;
1918
use ApiPlatform\Metadata\Metadata;
@@ -58,12 +57,7 @@ public function createLinksFromIdentifiers(Metadata $operation): array
5857
return [];
5958
}
6059

61-
$entityClass = $resourceClass;
62-
if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
63-
$entityClass = $options->getEntityClass();
64-
}
65-
66-
$link = (new Link())->withFromClass($entityClass)->withIdentifiers($identifiers);
60+
$link = (new Link())->withFromClass($resourceClass)->withIdentifiers($identifiers);
6761
$parameterName = $identifiers[0];
6862

6963
if (1 < \count($identifiers)) {

src/Metadata/Resource/Factory/NotExposedOperationResourceMetadataCollectionFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
final class NotExposedOperationResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
3030
{
31+
use OperationDefaultsTrait;
32+
3133
public static $skolemUriTemplate = '/.well-known/genid/{id}';
3234

3335
private $linkFactory;
@@ -69,13 +71,13 @@ public function create(string $resourceClass): ResourceMetadataCollection
6971
// No item operation has been found on all resources for resource class: generate one on the last resource
7072
// Helpful to generate an IRI for a resource without declaring the Get operation
7173
/** @var HttpOperation $operation */
72-
$operation = (new NotExposed())->withClass($resource->getClass())->withShortName($resource->getShortName()); // @phpstan-ignore-line $resource is defined if count > 0
74+
[$key, $operation] = $this->getOperationWithDefaults($resource, new NotExposed(), true, ['uriTemplate']); // @phpstan-ignore-line $resource is defined if count > 0
7375

7476
if (!$this->linkFactory->createLinksFromIdentifiers($operation)) {
7577
$operation = $operation->withUriTemplate(self::$skolemUriTemplate);
7678
}
7779

78-
$operations->add(sprintf('_api_%s_get', $operation->getShortName()), $operation)->sort(); // @phpstan-ignore-line $operation exists
80+
$operations->add($key, $operation)->sort(); // @phpstan-ignore-line $operation exists
7981

8082
return $resourceMetadataCollection;
8183
}

src/Metadata/Resource/Factory/OperationDefaultsTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,18 @@ private function completeGraphQlOperations(ApiResource $resource): ApiResource
154154
return $resource->withGraphQlOperations($graphQlOperations);
155155
}
156156

157-
private function getOperationWithDefaults(ApiResource $resource, Operation $operation, bool $generated = false): array
157+
private function getOperationWithDefaults(ApiResource $resource, Operation $operation, bool $generated = false, array $ignoredOptions = []): array
158158
{
159159
// Inherit from resource defaults
160160
foreach (get_class_methods($resource) as $methodName) {
161161
if (!str_starts_with($methodName, 'get')) {
162162
continue;
163163
}
164164

165+
if (\in_array(lcfirst(substr($methodName, 3)), $ignoredOptions, true)) {
166+
continue;
167+
}
168+
165169
if (!method_exists($operation, $methodName) || null !== $operation->{$methodName}()) {
166170
continue;
167171
}
@@ -203,7 +207,6 @@ private function getOperationWithDefaults(ApiResource $resource, Operation $oper
203207
$operation = $operation->withName($operation->getRouteName());
204208
}
205209

206-
$path = ($operation->getRoutePrefix() ?? '').($operation->getUriTemplate() ?? '');
207210
$operationName = $operation->getName() ?? $this->getDefaultOperationName($operation, $resource->getClass());
208211

209212
return [

src/Metadata/Tests/Resource/Factory/NotExposedOperationResourceMetadataCollectionFactoryTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class: AttributeResource::class
182182
shortName: 'AttributeResource',
183183
operations: [
184184
'_api_AttributeResource_get_collection' => new GetCollection(controller: 'api_platform.action.placeholder', shortName: 'AttributeResource', class: AttributeResource::class),
185-
'_api_AttributeResource_get' => new NotExposed(controller: 'api_platform.action.not_exposed', shortName: 'AttributeResource', class: AttributeResource::class, output: false, read: false),
185+
'_api_AttributeResource_get' => new NotExposed(controller: 'api_platform.action.not_exposed', shortName: 'AttributeResource', class: AttributeResource::class, output: false, read: false, extraProperties: ['generated_operation' => true]),
186186
],
187187
class: AttributeResource::class
188188
),
@@ -206,6 +206,8 @@ class: AttributeResource::class
206206
),
207207
new ApiResource(
208208
shortName: 'AttributeResource',
209+
types: ['https://schema.org/Book'],
210+
uriTemplate: '/custom_api_resources', // uriTemplate should not be inherited on NotExposed operation
209211
operations: [
210212
'_api_AttributeResource_get_collection' => new GetCollection(controller: 'api_platform.action.placeholder', shortName: 'AttributeResource', class: AttributeResource::class),
211213
],
@@ -224,9 +226,11 @@ class: AttributeResource::class
224226
),
225227
new ApiResource(
226228
shortName: 'AttributeResource',
229+
uriTemplate: '/custom_api_resources',
230+
types: ['https://schema.org/Book'],
227231
operations: [
228232
'_api_AttributeResource_get_collection' => new GetCollection(controller: 'api_platform.action.placeholder', shortName: 'AttributeResource', class: AttributeResource::class),
229-
'_api_AttributeResource_get' => new NotExposed(uriTemplate: '/.well-known/genid/{id}', controller: 'api_platform.action.not_exposed', shortName: 'AttributeResource', class: AttributeResource::class, output: false, read: false),
233+
'_api_AttributeResource_get' => new NotExposed(uriTemplate: '/.well-known/genid/{id}', controller: 'api_platform.action.not_exposed', shortName: 'AttributeResource', class: AttributeResource::class, output: false, read: false, extraProperties: ['generated_operation' => true], types: ['https://schema.org/Book']),
230234
],
231235
class: AttributeResource::class
232236
),

src/OpenApi/Model/Components.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ final class Components
1919

2020
private ?\ArrayObject $schemas;
2121

22+
/**
23+
* @param \ArrayObject<string, Schema>|\ArrayObject<string, Reference> $schemas
24+
* @param \ArrayObject<string, Response>|\ArrayObject<string, Reference> $responses
25+
* @param \ArrayObject<string, Parameter>|\ArrayObject<string, Reference> $parameters
26+
* @param \ArrayObject<string, Example>|\ArrayObject<string, Reference> $examples
27+
* @param \ArrayObject<string, RequestBody>|\ArrayObject<string, Reference> $requestBodies
28+
* @param \ArrayObject<string, Header>|\ArrayObject<string, Reference> $headers
29+
* @param \ArrayObject<string, SecurityScheme>|\ArrayObject<string, Reference> $headers
30+
* @param \ArrayObject<string, Link>|\ArrayObject<string, Reference> $links
31+
* @param \ArrayObject<string, array<string, PathItem>>|\ArrayObject<string, array<string, Reference>> $callbacks
32+
* @param \ArrayObject<string, PathItem>|\ArrayObject<string, Reference> $pathItems
33+
*/
2234
public function __construct(\ArrayObject $schemas = null, private ?\ArrayObject $responses = null, private ?\ArrayObject $parameters = null, private ?\ArrayObject $examples = null, private ?\ArrayObject $requestBodies = null, private ?\ArrayObject $headers = null, private ?\ArrayObject $securitySchemes = null, private ?\ArrayObject $links = null, private ?\ArrayObject $callbacks = null, private ?\ArrayObject $pathItems = null)
2335
{
2436
$schemas?->ksort();

src/OpenApi/Model/Example.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\OpenApi\Model;
15+
16+
final class Example
17+
{
18+
use ExtensionTrait;
19+
20+
public function __construct(private ?string $summary = null, private ?string $description = null, private mixed $value = null, private ?string $externalValue = null)
21+
{
22+
}
23+
24+
public function getSummary(): ?string
25+
{
26+
return $this->summary;
27+
}
28+
29+
public function withSummary(string $summary): self
30+
{
31+
$clone = clone $this;
32+
$clone->summary = $summary;
33+
34+
return $clone;
35+
}
36+
37+
public function getDescription(): ?string
38+
{
39+
return $this->description;
40+
}
41+
42+
public function withDescription(string $description): self
43+
{
44+
$clone = clone $this;
45+
$clone->description = $description;
46+
47+
return $clone;
48+
}
49+
50+
public function getValue(): mixed
51+
{
52+
return $this->value;
53+
}
54+
55+
public function withValue(mixed $value): self
56+
{
57+
$clone = clone $this;
58+
$clone->value = $value;
59+
60+
return $clone;
61+
}
62+
63+
public function getExternalValue(): ?string
64+
{
65+
return $this->externalValue;
66+
}
67+
68+
public function withExternalValue(string $externalValue): self
69+
{
70+
$clone = clone $this;
71+
$clone->externalValue = $externalValue;
72+
73+
return $clone;
74+
}
75+
}

0 commit comments

Comments
 (0)