Skip to content

Patch 2 #6724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
2 changes: 1 addition & 1 deletion docs/adr/0005-refactor-state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For API Platform 3, we refactored the whole metadata susbsytem to be more flexib
This led to the refactoring of the two main interfaces allowing to plug a data source in API Platform: the state provider and the state processor interfaces.

Leveraging these new interfaces, it should be possible to simplify the code base and to remove most code duplication by transforming most of the code currently
stored in the kernel event listeners and in the GraphQL resolvers in dedicated state processors and state providers.
stored in the kernel event listeners and in the GraphQL resolvers in dedicated state processors and state providers. This is quite close to what @alanpoulain proposed in 2019 at https://github.com/api-platform/core/pull/2978 although at that time we needed to refactor the subresource system before tackling this issue.

## Decision Outcome

Expand Down
8 changes: 8 additions & 0 deletions src/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
continue;
}

if (false === $propertyMetadata->getGenId()) {
$subDefinitionName = $this->definitionNameFactory->create($className, $format, $className, null, $serializerContext);

if (isset($subSchema->getDefinitions()[$subDefinitionName])) {
unset($subSchema->getDefinitions()[$subDefinitionName]['properties']['@id']);
}
}

if ($isCollection) {
$propertySchema['items']['$ref'] = $subSchema['$ref'];
unset($propertySchema['items']['type']);
Expand Down
8 changes: 8 additions & 0 deletions tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,12 @@ public function testResourceWithEnumPropertiesSchema(): void
$properties['genders']
);
}

public function testGenId(): void
{
$this->tester->run(['command' => 'api:json-schema:generate', 'resource' => 'ApiPlatform\Tests\Fixtures\TestBundle\Entity\DisableIdGeneration', '--type' => 'output', '--format' => 'jsonld']);
$result = $this->tester->getDisplay();
$json = json_decode($result, associative: true);
$this->assertArrayNotHasKey('@id', $json['definitions']['DisableIdGenerationItem.jsonld']['properties']);
}
}
Loading