Skip to content

Commit d9917ed

Browse files
committed
fix: make JSON-LD specific properties non-readOnly and make them required only in output schema
1 parent 016ccac commit d9917ed

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/Hydra/JsonSchema/SchemaFactory.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface
2828
{
2929
private const BASE_PROP = [
30-
'readOnly' => true,
3130
'type' => 'string',
3231
];
3332
private const BASE_PROPS = [
@@ -36,7 +35,6 @@ final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareI
3635
];
3736
private const BASE_ROOT_PROPS = [
3837
'@context' => [
39-
'readOnly' => true,
4038
'oneOf' => [
4139
['type' => 'string'],
4240
[
@@ -87,28 +85,28 @@ public function buildSchema(string $className, string $format = 'jsonld', string
8785
}
8886
}
8987

90-
if ('input' === $type) {
91-
return $schema;
92-
}
93-
9488
$definitions = $schema->getDefinitions();
9589
if ($key = $schema->getRootDefinitionKey()) {
9690
$definitions[$key]['properties'] = self::BASE_ROOT_PROPS + ($definitions[$key]['properties'] ?? []);
97-
foreach (array_keys(self::BASE_ROOT_PROPS) as $property) {
98-
$definitions[$key]['required'] ??= [];
99-
if (!\in_array($property, $definitions[$key]['required'], true)) {
100-
$definitions[$key]['required'][] = $property;
91+
if ($type === Schema::TYPE_OUTPUT) {
92+
foreach (array_keys(self::BASE_ROOT_PROPS) as $property) {
93+
$definitions[$key]['required'] ??= [];
94+
if (!\in_array($property, $definitions[$key]['required'], true)) {
95+
$definitions[$key]['required'][] = $property;
96+
}
10197
}
10298
}
10399

104100
return $schema;
105101
}
106102
if ($key = $schema->getItemsDefinitionKey()) {
107103
$definitions[$key]['properties'] = self::BASE_PROPS + ($definitions[$key]['properties'] ?? []);
108-
foreach (array_keys(self::BASE_PROPS) as $property) {
109-
$definitions[$key]['required'] ??= [];
110-
if (!\in_array($property, $definitions[$key]['required'], true)) {
111-
$definitions[$key]['required'][] = $property;
104+
if ($type === Schema::TYPE_OUTPUT) {
105+
foreach (array_keys(self::BASE_PROPS) as $property) {
106+
$definitions[$key]['required'] ??= [];
107+
if (!\in_array($property, $definitions[$key]['required'], true)) {
108+
$definitions[$key]['required'][] = $property;
109+
}
112110
}
113111
}
114112
}

0 commit comments

Comments
 (0)