diff --git a/src/Hydra/JsonSchema/SchemaFactory.php b/src/Hydra/JsonSchema/SchemaFactory.php index 3fdb09ead6e..75144baee28 100644 --- a/src/Hydra/JsonSchema/SchemaFactory.php +++ b/src/Hydra/JsonSchema/SchemaFactory.php @@ -27,7 +27,6 @@ final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface { private const BASE_PROP = [ - 'readOnly' => true, 'type' => 'string', ]; private const BASE_PROPS = [ @@ -36,7 +35,6 @@ final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareI ]; private const BASE_ROOT_PROPS = [ '@context' => [ - 'readOnly' => true, 'oneOf' => [ ['type' => 'string'], [ @@ -87,17 +85,15 @@ public function buildSchema(string $className, string $format = 'jsonld', string } } - if ('input' === $type) { - return $schema; - } - $definitions = $schema->getDefinitions(); if ($key = $schema->getRootDefinitionKey()) { $definitions[$key]['properties'] = self::BASE_ROOT_PROPS + ($definitions[$key]['properties'] ?? []); - foreach (array_keys(self::BASE_ROOT_PROPS) as $property) { - $definitions[$key]['required'] ??= []; - if (!\in_array($property, $definitions[$key]['required'], true)) { - $definitions[$key]['required'][] = $property; + if (Schema::TYPE_OUTPUT === $type) { + foreach (array_keys(self::BASE_ROOT_PROPS) as $property) { + $definitions[$key]['required'] ??= []; + if (!\in_array($property, $definitions[$key]['required'], true)) { + $definitions[$key]['required'][] = $property; + } } } @@ -105,10 +101,12 @@ public function buildSchema(string $className, string $format = 'jsonld', string } if ($key = $schema->getItemsDefinitionKey()) { $definitions[$key]['properties'] = self::BASE_PROPS + ($definitions[$key]['properties'] ?? []); - foreach (array_keys(self::BASE_PROPS) as $property) { - $definitions[$key]['required'] ??= []; - if (!\in_array($property, $definitions[$key]['required'], true)) { - $definitions[$key]['required'][] = $property; + if (Schema::TYPE_OUTPUT === $type) { + foreach (array_keys(self::BASE_PROPS) as $property) { + $definitions[$key]['required'] ??= []; + if (!\in_array($property, $definitions[$key]['required'], true)) { + $definitions[$key]['required'][] = $property; + } } } } diff --git a/tests/Hydra/JsonSchema/SchemaFactoryTest.php b/tests/Hydra/JsonSchema/SchemaFactoryTest.php index 17107c0ba62..109c0cc398b 100644 --- a/tests/Hydra/JsonSchema/SchemaFactoryTest.php +++ b/tests/Hydra/JsonSchema/SchemaFactoryTest.php @@ -101,7 +101,6 @@ public function testHasRootDefinitionKeyBuildSchema(): void $this->assertArrayHasKey('@context', $properties); $this->assertEquals( [ - 'readOnly' => true, 'oneOf' => [ ['type' => 'string'], [ diff --git a/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php b/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php index 50c95ba77f8..ea24404f75b 100644 --- a/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php +++ b/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php @@ -76,9 +76,9 @@ public function testExecuteWithJsonldTypeInput(): void $this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--operation' => '_api_/dummies{._format}_post', '--format' => 'jsonld', '--type' => 'input']); $result = $this->tester->getDisplay(); - $this->assertStringNotContainsString('@id', $result); - $this->assertStringNotContainsString('@context', $result); - $this->assertStringNotContainsString('@type', $result); + $this->assertStringContainsString('@id', $result); + $this->assertStringContainsString('@context', $result); + $this->assertStringContainsString('@type', $result); } /**