Skip to content

Commit a070a18

Browse files
NGSTACK-1017 remove readonly from decorator classes and refactor for readability
1 parent 853cae6 commit a070a18

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/ApiPlatform/JsonSchema/Metadata/Property/PropertyMetadataFactoryDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
1010
use Symfony\Component\TypeInfo\Type\NullableType;
1111

12-
final readonly class PropertyMetadataFactoryDecorator implements PropertyMetadataFactoryInterface
12+
final class PropertyMetadataFactoryDecorator implements PropertyMetadataFactoryInterface
1313
{
1414
public function __construct(
1515
private PropertyMetadataFactoryInterface $decorated,

src/ApiPlatform/JsonSchema/SchemaFactoryDecorator.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use function is_string;
1818
use function str_replace;
1919

20-
final readonly class SchemaFactoryDecorator implements SchemaFactoryInterface
20+
final class SchemaFactoryDecorator implements SchemaFactoryInterface
2121
{
2222
use SchemaUriPrefixTrait;
2323

@@ -47,13 +47,13 @@ public function buildSchema(string $className, string $format = 'json', string $
4747
&& $type === Schema::TYPE_INPUT
4848
&& in_array($operation::class, [Put::class, Post::class, Patch::class], true)
4949
) {
50-
$this->addJsonldUpdatePropertyToObjectSchemaDefinitions($currentReference, $schemaPrefix, $schema->getDefinitions());
50+
$this->ensureJsonldInputPropertyForInputSchemas($currentReference, $schemaPrefix, $schema->getDefinitions());
5151
}
5252

5353
return $schema;
5454
}
5555

56-
private function addJsonldUpdatePropertyToObjectSchemaDefinitions(string $reference, string $schemaPrefix, ArrayObject $definitions): void
56+
private function ensureJsonldInputPropertyForInputSchemas(string $reference, string $schemaPrefix, ArrayObject $definitions): void
5757
{
5858
$definitionName = str_replace($schemaPrefix, '', $reference);
5959

@@ -62,8 +62,12 @@ private function addJsonldUpdatePropertyToObjectSchemaDefinitions(string $refere
6262
continue;
6363
}
6464

65-
if (isset($property['$ref']) && !isset($definitions[str_replace($schemaPrefix, '', $property['$ref'])]['properties'][self::JSONLD_INPUT_OBJECT_PROPERTY_NAME])) {
66-
$definitions[str_replace($schemaPrefix, '', $property['$ref'])]['properties'][self::JSONLD_INPUT_OBJECT_PROPERTY_NAME] = self::JSONLD_INPUT_OBJECT_PROPERTY;
65+
if (isset($property['$ref'])) {
66+
$this->addJsonldInputProperty(
67+
$definitions,
68+
$schemaPrefix,
69+
$property['$ref'],
70+
);
6771

6872
break;
6973
}
@@ -78,9 +82,24 @@ private function addJsonldUpdatePropertyToObjectSchemaDefinitions(string $refere
7882
continue;
7983
}
8084

81-
$definitions[str_replace($schemaPrefix, '', $subschema['$ref'])]['properties'][self::JSONLD_INPUT_OBJECT_PROPERTY_NAME] = self::JSONLD_INPUT_OBJECT_PROPERTY;
85+
$this->addJsonldInputProperty(
86+
$definitions,
87+
$schemaPrefix,
88+
$subschema['$ref'],
89+
);
8290
}
8391
}
8492
}
8593
}
94+
95+
private function addJsonldInputProperty(
96+
ArrayObject $definitions,
97+
string $schemaPrefix,
98+
string $ref,
99+
): void {
100+
$definitionKey = str_replace($schemaPrefix, '', $ref);
101+
102+
$definitions[$definitionKey]['properties'][self::JSONLD_INPUT_OBJECT_PROPERTY_NAME]
103+
??= self::JSONLD_INPUT_OBJECT_PROPERTY;
104+
}
86105
}

0 commit comments

Comments
 (0)