Skip to content

Commit 99262dc

Browse files
ViPErCZsoyuka
andauthored
fix(jsonschema): handle @id when genId is false (#6716)
Co-authored-by: soyuka <[email protected]>
1 parent e96623e commit 99262dc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/JsonSchema/SchemaFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
232232
continue;
233233
}
234234

235+
if (false === $propertyMetadata->getGenId()) {
236+
$subDefinitionName = $this->definitionNameFactory->create($className, $format, $className, null, $serializerContext);
237+
238+
if (isset($subSchema->getDefinitions()[$subDefinitionName])) {
239+
unset($subSchema->getDefinitions()[$subDefinitionName]['properties']['@id']);
240+
}
241+
}
242+
235243
if ($isCollection) {
236244
$propertySchema['items']['$ref'] = $subSchema['$ref'];
237245
unset($propertySchema['items']['type']);

tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,15 @@ public function testResourceWithEnumPropertiesSchema(): void
334334
$properties['genders']
335335
);
336336
}
337+
338+
/**
339+
* Test feature #6716.
340+
*/
341+
public function testGenId(): void
342+
{
343+
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => 'ApiPlatform\Tests\Fixtures\TestBundle\Entity\DisableIdGeneration', '--type' => 'output', '--format' => 'jsonld']);
344+
$result = $this->tester->getDisplay();
345+
$json = json_decode($result, associative: true);
346+
$this->assertArrayNotHasKey('@id', $json['definitions']['DisableIdGenerationItem.jsonld']['properties']);
347+
}
337348
}

0 commit comments

Comments
 (0)