Skip to content

Commit 64768a6

Browse files
committed
Merge 4.2
2 parents 59b35b1 + fa6a5e4 commit 64768a6

21 files changed

+641
-229
lines changed

src/Hal/JsonSchema/SchemaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function buildSchema(string $className, string $format = 'jsonhal', strin
9292

9393
$schema = $this->schemaFactory->buildSchema($className, 'json', $type, $operation, $schema, $serializerContext, $forceCollection);
9494
$definitions = $schema->getDefinitions();
95-
$definitionName = $this->definitionNameFactory->create($className, $format, $className, $operation, $serializerContext);
95+
$definitionName = $this->definitionNameFactory->create($className, $format, $className, $operation, $serializerContext + ['schema_type' => $type]);
9696
$prefix = $this->getSchemaUriPrefix($schema->getVersion());
9797
$collectionKey = $schema->getItemsDefinitionKey();
9898

src/Hydra/JsonSchema/SchemaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string
247247
];
248248
}
249249

250-
$definitionName = $this->definitionNameFactory->create($className, $format, $inputOrOutputClass, $operation, $serializerContext);
250+
$definitionName = $this->definitionNameFactory->create($className, $format, $inputOrOutputClass, $operation, $serializerContext + ['schema_type' => $type]);
251251
$schema['type'] = 'object';
252252
$schema['description'] = "$definitionName collection.";
253253
$schema['allOf'] = [

src/JsonApi/JsonSchema/SchemaFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function buildSchema(string $className, string $format = 'jsonapi', strin
125125
}
126126

127127
$schema = $this->schemaFactory->buildSchema($className, 'json', $type, $operation, $schema, $jsonApiSerializerContext, $forceCollection);
128-
$definitionName = $this->definitionNameFactory->create($inputOrOutputClass, $format, $className, $operation, $jsonApiSerializerContext);
128+
$definitionName = $this->definitionNameFactory->create($inputOrOutputClass, $format, $className, $operation, $jsonApiSerializerContext + ['schema_type' => $type]);
129129
$prefix = $this->getSchemaUriPrefix($schema->getVersion());
130130
$definitions = $schema->getDefinitions();
131131
$collectionKey = $schema->getItemsDefinitionKey();
@@ -300,7 +300,7 @@ private function buildDefinitionPropertiesSchema(string $key, string $className,
300300
$operation = $this->findOperation($relatedClassName, $type, null, $serializerContext);
301301
$inputOrOutputClass = $this->findOutputClass($relatedClassName, $type, $operation, $serializerContext);
302302
$serializerContext ??= $this->getSerializerContext($operation, $type);
303-
$definitionName = $this->definitionNameFactory->create($relatedClassName, $format, $inputOrOutputClass, $operation, $serializerContext);
303+
$definitionName = $this->definitionNameFactory->create($relatedClassName, $format, $inputOrOutputClass, $operation, $serializerContext + ['schema_type' => $type]);
304304

305305
// to avoid recursion
306306
if ($this->builtSchema[$definitionName] ?? false) {

src/JsonSchema/SchemaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function buildSchema(string $className, string $format = 'json', string $
9797
$isJsonMergePatch => 'merge-patch+json',
9898
};
9999

100-
$definitionName = $this->definitionNameFactory->create($className, $definitionFormat, $inputOrOutputClass, $operation, $serializerContext);
100+
$definitionName = $this->definitionNameFactory->create($className, $definitionFormat, $inputOrOutputClass, $operation, $serializerContext + ['schema_type' => $type]);
101101

102102
if (!isset($schema['$ref']) && !isset($schema['type'])) {
103103
$ref = $this->getSchemaUriPrefix($version).$definitionName;

src/State/Processor/ObjectMapperProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
use ApiPlatform\Metadata\Operation;
1717
use ApiPlatform\State\ProcessorInterface;
18-
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
1918
use Symfony\Component\HttpFoundation\Response;
19+
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
2020

2121
/**
2222
* @implements ProcessorInterface<mixed,mixed>

src/State/Provider/ObjectMapperProvider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4040
{
4141
$data = $this->decorated->provide($operation, $uriVariables, $context);
4242

43-
if (!$this->objectMapper || !\is_object($data) || !$operation->canMap()) {
43+
if (!$this->objectMapper || !$operation->canMap()) {
44+
return $data;
45+
}
46+
47+
if (!\is_object($data) && !\is_array($data)) {
4448
return $data;
4549
}
4650

@@ -49,6 +53,12 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4953

5054
if ($data instanceof PaginatorInterface) {
5155
$data = new ArrayPaginator(array_map(fn ($v) => $this->objectMapper->map($v, $operation->getClass()), iterator_to_array($data)), 0, \count($data));
56+
} elseif (\is_array($data)) {
57+
foreach ($data as &$v) {
58+
if (\is_object($v)) {
59+
$v = $this->objectMapper->map($v, $operation->getClass());
60+
}
61+
}
5262
} else {
5363
$data = $this->objectMapper->map($data, $operation->getClass());
5464
}

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
309309
$container->setParameter('api_platform.collection.pagination.client_items_per_page', $config['defaults']['pagination_client_items_per_page'] ?? false);
310310
$container->setParameter('api_platform.collection.pagination.client_partial', $config['defaults']['pagination_client_partial'] ?? false);
311311
$container->setParameter('api_platform.collection.pagination.items_per_page', $config['defaults']['pagination_items_per_page'] ?? 30);
312-
$container->setParameter('api_platform.collection.pagination.maximum_items_per_page', \array_key_exists('pagination_maximum_items_per_page', $config['defaults']) ? $config['defaults']['pagination_maximum_items_per_page'] : 30);
312+
$container->setParameter('api_platform.collection.pagination.maximum_items_per_page', \array_key_exists('pagination_maximum_items_per_page', $config['defaults'] ?? []) ? $config['defaults']['pagination_maximum_items_per_page'] : 30);
313313
$container->setParameter('api_platform.collection.pagination.page_parameter_name', $config['defaults']['pagination_page_parameter_name'] ?? $config['collection']['pagination']['page_parameter_name']);
314314
$container->setParameter('api_platform.collection.pagination.enabled_parameter_name', $config['defaults']['pagination_enabled_parameter_name'] ?? $config['collection']['pagination']['enabled_parameter_name']);
315315
$container->setParameter('api_platform.collection.pagination.items_per_page_parameter_name', $config['defaults']['pagination_items_per_page_parameter_name'] ?? $config['collection']['pagination']['items_per_page_parameter_name']);

0 commit comments

Comments
 (0)