Skip to content

Commit e738785

Browse files
benblubsoyuka
authored andcommitted
fix(jsonschema): remove @id @type @context from input schema (api-platform#5267)
* 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 api-platform#5263 * remove whitespace * change format to output * restore old test except output type and add test for input
1 parent ddeda9c commit e738785

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Hydra/JsonSchema/SchemaFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public function buildSchema(string $className, string $format = 'jsonld', string
7272
return $schema;
7373
}
7474

75+
if ('input' === $type) {
76+
return $schema;
77+
}
78+
7579
$definitions = $schema->getDefinitions();
7680
if ($key = $schema->getRootDefinitionKey()) {
7781
$definitions[$key]['properties'] = self::BASE_ROOT_PROPS + ($definitions[$key]['properties'] ?? []);

tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,21 @@ public function testExecuteWithCollectionOperationGet(): void
6363

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

6969
$this->assertStringContainsString('@id', $result);
7070
$this->assertStringContainsString('@context', $result);
7171
$this->assertStringContainsString('@type', $result);
7272
}
73+
74+
public function testExecuteWithJsonldTypeInput(): void
75+
{
76+
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => $this->entityClass, '--operation' => '_api_/dummies{._format}_post', '--format' => 'jsonld', '--type' => 'input']);
77+
$result = $this->tester->getDisplay();
78+
79+
$this->assertStringNotContainsString('@id', $result);
80+
$this->assertStringNotContainsString('@context', $result);
81+
$this->assertStringNotContainsString('@type', $result);
82+
}
7383
}

0 commit comments

Comments
 (0)