Skip to content

Commit 93fb092

Browse files
committed
Merge 3.4
2 parents 4171d5f + 77d3ff3 commit 93fb092

File tree

19 files changed

+602
-19
lines changed

19 files changed

+602
-19
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ Notes:
142142
### Features
143143

144144
* [0d5f35683](https://github.com/api-platform/core/commit/0d5f356839eb6aa9f536044abe4affa736553e76) feat(laravel): laravel component (#5882)
145+
=======
146+
## v3.4.4
147+
148+
### Bug fixes
149+
150+
* [550347867](https://github.com/api-platform/core/commit/550347867f30611b673d8df99f65186d013919dd) fix(graphql): register query parameter arguments with filters (#6727)
151+
* [99262dce7](https://github.com/api-platform/core/commit/99262dce739800bd841c95e026848b587ba25801) fix(jsonschema): handle @id when genId is false (#6716)
152+
* [ad5efa535](https://github.com/api-platform/core/commit/ad5efa535a4dcbaad64ecff89514eaa6e07f5b7c) fix: multiple parameter provider #6673 (#6732)
153+
* [d34cd7be8](https://github.com/api-platform/core/commit/d34cd7be8e7a12fd08a8b10270a614c06c10aa89) fix: use stateOptions when retrieving a Parameter filter (#6728)
154+
* [e7fb04fab](https://github.com/api-platform/core/commit/e7fb04fab05bc077e2dbeb0fa0fc2c1d28c96105) fix(symfony): fetch api-platform/symfony version debug bar (#6722)
155+
* [e96623ebf](https://github.com/api-platform/core/commit/e96623ebfd8691ba943bdb56a4d91e160497a311) fix(jsonld): prefix error @type with hydra: (#6721)
145156

146157
## v3.4.3
147158

features/main/relation.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ Feature: Relations support
493493
"properties": {
494494
"@type": {
495495
"type": "string",
496-
"pattern": "^Error$"
496+
"pattern": "^hydra:Error$"
497497
},
498498
"title": {
499499
"type": "string",

features/mongodb/filters.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: Filters on collections
1212
And the response should be in JSON
1313
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
1414
And the JSON node "@context" should be equal to "/contexts/Error"
15-
And the JSON node "@type" should be equal to "Error"
15+
And the JSON node "@type" should be equal to "hydra:Error"
1616
And the JSON node "title" should be equal to "An error occurred"
1717
And the JSON node "description" should be equal to "Cannot use reference 'badFourthLevel' in class 'ThirdLevel' for lookup or graphLookup: dbRef references are not supported."
1818
And the JSON node "trace" should exist
@@ -23,7 +23,7 @@ Feature: Filters on collections
2323
And the response should be in JSON
2424
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
2525
And the JSON node "@context" should be equal to "/contexts/Error"
26-
And the JSON node "@type" should be equal to "Error"
26+
And the JSON node "@type" should be equal to "hydra:Error"
2727
And the JSON node "title" should be equal to "An error occurred"
2828
And the JSON node "description" should be equal to "Cannot use reference 'badThirdLevel' in class 'FourthLevel' for lookup or graphLookup: dbRef references are not supported."
2929
And the JSON node "trace" should exist

features/security/strong_typing.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Feature: Handle properly invalid data submitted to the API
5454
And the response should be in JSON
5555
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
5656
And the JSON node "@context" should be equal to "/contexts/Error"
57-
And the JSON node "@type" should be equal to "Error"
57+
And the JSON node "@type" should be equal to "hydra:Error"
5858
And the JSON node "title" should be equal to "An error occurred"
5959
And the JSON node "description" should be equal to 'The type of the "name" attribute must be "string", "NULL" given.'
6060

@@ -71,7 +71,7 @@ Feature: Handle properly invalid data submitted to the API
7171
And the response should be in JSON
7272
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
7373
And the JSON node "@context" should be equal to "/contexts/Error"
74-
And the JSON node "@type" should be equal to "Error"
74+
And the JSON node "@type" should be equal to "hydra:Error"
7575
And the JSON node "title" should be equal to "An error occurred"
7676
And the JSON node "description" should be equal to 'Invalid IRI "1".'
7777
And the JSON node "trace" should exist
@@ -102,7 +102,7 @@ Feature: Handle properly invalid data submitted to the API
102102
And the response should be in JSON
103103
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
104104
And the JSON node "@context" should be equal to "/contexts/Error"
105-
And the JSON node "@type" should be equal to "Error"
105+
And the JSON node "@type" should be equal to "hydra:Error"
106106
And the JSON node "title" should be equal to "An error occurred"
107107
And the JSON node "description" should be equal to 'The type of the "relatedDummies" attribute must be "array", "string" given.'
108108
And the JSON node "trace" should exist
@@ -120,7 +120,7 @@ Feature: Handle properly invalid data submitted to the API
120120
And the response should be in JSON
121121
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
122122
And the JSON node "@context" should be equal to "/contexts/Error"
123-
And the JSON node "@type" should be equal to "Error"
123+
And the JSON node "@type" should be equal to "hydra:Error"
124124
And the JSON node "title" should be equal to "An error occurred"
125125
And the JSON node "description" should be equal to 'The type of the key "a" must be "int", "string" given.'
126126

@@ -136,7 +136,7 @@ Feature: Handle properly invalid data submitted to the API
136136
And the response should be in JSON
137137
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
138138
And the JSON node "@context" should be equal to "/contexts/Error"
139-
And the JSON node "@type" should be equal to "Error"
139+
And the JSON node "@type" should be equal to "hydra:Error"
140140
And the JSON node "title" should be equal to "An error occurred"
141141
And the JSON node "description" should be equal to 'The type of the "name" attribute must be "string", "integer" given.'
142142

features/serializer/vo_relations.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Feature: Value object as ApiResource
148148
"properties": {
149149
"@type": {
150150
"type": "string",
151-
"pattern": "^Error$"
151+
"pattern": "^hydra:Error$"
152152
},
153153
"title": {
154154
"type": "string",

src/JsonLd/Serializer/ErrorNormalizer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ public function __construct(private readonly NormalizerInterface $inner, private
2727

2828
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
2929
{
30+
$context += $this->defaultContext;
3031
$normalized = $this->inner->normalize($object, $format, $context);
31-
$hydraPrefix = $this->getHydraPrefix($context + $this->defaultContext);
32+
$hydraPrefix = $this->getHydraPrefix($context);
3233
if (!$hydraPrefix) {
3334
return $normalized;
3435
}
3536

37+
if ('Error' === $normalized['@type']) {
38+
$normalized['@type'] = 'hydra:Error';
39+
}
40+
3641
if (isset($normalized['description'])) {
3742
$normalized['hydra:description'] = $normalized['description'];
3843
}

src/JsonSchema/SchemaFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
222222
continue;
223223
}
224224

225+
if (false === $propertyMetadata->getGenId()) {
226+
$subDefinitionName = $this->definitionNameFactory->create($className, $format, $className, null, $serializerContext);
227+
228+
if (isset($subSchema->getDefinitions()[$subDefinitionName])) {
229+
unset($subSchema->getDefinitions()[$subDefinitionName]['properties']['@id']);
230+
}
231+
}
232+
225233
if ($isCollection) {
226234
$propertySchema['items']['$ref'] = $subSchema['$ref'];
227235
unset($propertySchema['items']['type']);

src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace ApiPlatform\Metadata\Resource\Factory;
1515

16+
use ApiPlatform\Doctrine\Odm\State\Options as DoctrineODMOptions;
17+
use ApiPlatform\Doctrine\Orm\State\Options as DoctrineORMOptions;
1618
use ApiPlatform\Metadata\ApiProperty;
1719
use ApiPlatform\Metadata\FilterInterface;
1820
use ApiPlatform\Metadata\JsonSchemaFilterInterface;
@@ -113,7 +115,7 @@ private function getDefaultParameters(Operation $operation, string $resourceClas
113115
if (':property' === $key) {
114116
foreach ($propertyNames as $property) {
115117
$converted = $this->nameConverter?->denormalize($property) ?? $property;
116-
$propertyParameter = $this->setDefaults($converted, $parameter, $resourceClass, $properties);
118+
$propertyParameter = $this->setDefaults($converted, $parameter, $resourceClass, $properties, $operation);
117119
$priority = $propertyParameter->getPriority() ?? $internalPriority--;
118120
$parameters->add($converted, $propertyParameter->withPriority($priority)->withKey($converted));
119121
}
@@ -133,7 +135,7 @@ private function getDefaultParameters(Operation $operation, string $resourceClas
133135
$parameter = $parameter->withExtraProperties($parameter->getExtraProperties() + ['_properties' => $p]);
134136
}
135137

136-
$parameter = $this->setDefaults($key, $parameter, $resourceClass, $properties);
138+
$parameter = $this->setDefaults($key, $parameter, $resourceClass, $properties, $operation);
137139
$priority = $parameter->getPriority() ?? $internalPriority--;
138140
$parameters->add($key, $parameter->withPriority($priority));
139141
}
@@ -171,7 +173,7 @@ private function addFilterMetadata(Parameter $parameter): Parameter
171173
/**
172174
* @param array<string, ApiProperty> $properties
173175
*/
174-
private function setDefaults(string $key, Parameter $parameter, string $resourceClass, array $properties): Parameter
176+
private function setDefaults(string $key, Parameter $parameter, string $resourceClass, array $properties, Operation $operation): Parameter
175177
{
176178
if (null === $parameter->getKey()) {
177179
$parameter = $parameter->withKey($key);
@@ -187,7 +189,7 @@ private function setDefaults(string $key, Parameter $parameter, string $resource
187189
}
188190

189191
// Read filter description to populate the Parameter
190-
$description = $filter instanceof FilterInterface ? $filter->getDescription($resourceClass) : [];
192+
$description = $filter instanceof FilterInterface ? $filter->getDescription($this->getFilterClass($operation)) : [];
191193
if (($schema = $description[$key]['schema'] ?? null) && null === $parameter->getSchema()) {
192194
$parameter = $parameter->withSchema($schema);
193195
}
@@ -220,4 +222,17 @@ private function setDefaults(string $key, Parameter $parameter, string $resource
220222

221223
return $this->addFilterMetadata($parameter);
222224
}
225+
226+
private function getFilterClass(Operation $operation): ?string
227+
{
228+
$stateOptions = $operation->getStateOptions();
229+
if ($stateOptions instanceof DoctrineORMOptions) {
230+
return $stateOptions->getEntityClass();
231+
}
232+
if ($stateOptions instanceof DoctrineODMOptions) {
233+
return $stateOptions->getDocumentClass();
234+
}
235+
236+
return $operation->getClass();
237+
}
223238
}

src/State/Provider/ParameterProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4949
$request->attributes->set('_api_header_parameters', $request->headers->all());
5050
}
5151

52-
$context = ['operation' => $operation] + $context;
5352
$parameters = $operation->getParameters();
5453
foreach ($parameters ?? [] as $parameter) {
5554
$extraProperties = $parameter->getExtraProperties();
5655
unset($extraProperties['_api_values']);
5756
$parameters->add($parameter->getKey(), $parameter = $parameter->withExtraProperties($extraProperties));
5857

58+
$context = ['operation' => $operation] + $context;
5959
$values = $this->getParameterValues($parameter, $request, $context);
6060
$value = $this->extractParameterValues($parameter, $values);
6161

src/Symfony/Bundle/DataCollector/RequestDataCollector.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Metadata\ApiResource;
1717
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
1818
use ApiPlatform\State\Util\RequestAttributesExtractor;
19+
use Composer\InstalledVersions;
1920
use PackageVersions\Versions;
2021
use Psr\Container\ContainerInterface;
2122
use Symfony\Component\HttpFoundation\Request;
@@ -67,16 +68,38 @@ private function setFilters(ApiResource $resourceMetadata, int $index, array &$f
6768
}
6869
}
6970

71+
// TODO: 4.1 remove Versions as its deprecated
7072
public function getVersion(): ?string
7173
{
74+
if (class_exists(InstalledVersions::class)) {
75+
return InstalledVersions::getPrettyVersion('api-platform/symfony') ?? InstalledVersions::getPrettyVersion('api-platform/core');
76+
}
77+
7278
if (!class_exists(Versions::class)) {
7379
return null;
7480
}
7581

76-
$version = Versions::getVersion('api-platform/core');
77-
preg_match('/^v(.*?)@/', (string) $version, $output);
82+
try {
83+
$version = strtok(Versions::getVersion('api-platform/symfony'), '@');
84+
} catch (\OutOfBoundsException) {
85+
$version = false;
86+
}
87+
88+
if (false === $version) {
89+
try {
90+
$version = strtok(Versions::getVersion('api-platform/core'), '@');
91+
} catch (\OutOfBoundsException) {
92+
$version = false;
93+
}
94+
}
95+
96+
if (false === $version) {
97+
return null;
98+
}
99+
100+
preg_match('/^v(.*?)$/', $version, $output);
78101

79-
return $output[1] ?? strtok($version, '@');
102+
return $output[1] ?? $version;
80103
}
81104

82105
/**

0 commit comments

Comments
 (0)