Skip to content

Commit 96cb378

Browse files
committed
Merge 3.2
2 parents 9f4bc82 + 2770a4f commit 96cb378

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

JsonSchema/SchemaFactory.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author Kévin Dunglas <[email protected]>
2525
* @author Jachim Coudenys <[email protected]>
2626
*/
27-
final class SchemaFactory implements SchemaFactoryInterface
27+
final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface
2828
{
2929
private const HREF_PROP = [
3030
'href' => [
@@ -46,7 +46,6 @@ final class SchemaFactory implements SchemaFactoryInterface
4646

4747
public function __construct(private readonly SchemaFactoryInterface $schemaFactory)
4848
{
49-
$this->addDistinctFormat('jsonhal');
5049
if ($this->schemaFactory instanceof SchemaFactoryAwareInterface) {
5150
$this->schemaFactory->setSchemaFactory($this);
5251
}
@@ -79,8 +78,18 @@ public function buildSchema(string $className, string $format = 'jsonhal', strin
7978
$schema['type'] = 'object';
8079
$schema['properties'] = [
8180
'_embedded' => [
82-
'type' => 'array',
83-
'items' => $items,
81+
'anyOf' => [
82+
[
83+
'type' => 'object',
84+
'properties' => [
85+
'item' => [
86+
'type' => 'array',
87+
'items' => $items,
88+
],
89+
],
90+
],
91+
['type' => 'object'],
92+
],
8493
],
8594
'totalItems' => [
8695
'type' => 'integer',
@@ -127,10 +136,10 @@ public function buildSchema(string $className, string $format = 'jsonhal', strin
127136
return $schema;
128137
}
129138

130-
public function addDistinctFormat(string $format): void
139+
public function setSchemaFactory(SchemaFactoryInterface $schemaFactory): void
131140
{
132-
if (method_exists($this->schemaFactory, 'addDistinctFormat')) {
133-
$this->schemaFactory->addDistinctFormat($format);
141+
if ($this->schemaFactory instanceof SchemaFactoryAwareInterface) {
142+
$this->schemaFactory->setSchemaFactory($schemaFactory);
134143
}
135144
}
136145
}

0 commit comments

Comments
 (0)