Skip to content

Commit

Permalink
fix(jsonschema): remove @id @type @context from input schema (#5267)
Browse files Browse the repository at this point in the history
* do not add linked data for denormationContext

If I look in the generated schema for denormalizationContext i can see the required fields for '@id' and '@type'. Why do have this fields required for write operations? We don't need to pass this fields in a write request. If you used this schema on the client with typescript you need to write workarounds because you not sending this fields in the requests.

See #5263

* remove whitespace

* change format to output

* restore old test except output type and add test for input
  • Loading branch information
benblub authored and soyuka committed Dec 16, 2022
1 parent ddeda9c commit e738785
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Hydra/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function buildSchema(string $className, string $format = 'jsonld', string
return $schema;
}

if ('input' === $type) {
return $schema;
}

$definitions = $schema->getDefinitions();
if ($key = $schema->getRootDefinitionKey()) {
$definitions[$key]['properties'] = self::BASE_ROOT_PROPS + ($definitions[$key]['properties'] ?? []);
Expand Down
12 changes: 11 additions & 1 deletion tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,21 @@ public function testExecuteWithCollectionOperationGet(): void

public function testExecuteWithJsonldFormatOption(): void
{
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--operation' => '_api_/dummies{._format}_post', '--format' => 'jsonld']);
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--operation' => '_api_/dummies{._format}_post', '--format' => 'jsonld', '--type' => 'output']);
$result = $this->tester->getDisplay();

$this->assertStringContainsString('@id', $result);
$this->assertStringContainsString('@context', $result);
$this->assertStringContainsString('@type', $result);
}

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);
}
}

0 comments on commit e738785

Please sign in to comment.