Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Hydra/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ public function buildSchema(string $className, string $format = 'jsonld', string

$baseName = Schema::TYPE_OUTPUT === $type ? self::ITEM_BASE_SCHEMA_NAME : self::ITEM_BASE_SCHEMA_OUTPUT_NAME;

if ($this->isResourceClass($inputOrOutputClass)) {
if (!isset($definitions[$baseName])) {
$definitions[$baseName] = Schema::TYPE_OUTPUT === $type ? self::ITEM_BASE_SCHEMA_OUTPUT : self::ITEM_BASE_SCHEMA;
}
if (!isset($definitions[$baseName])) {
$definitions[$baseName] = Schema::TYPE_OUTPUT === $type ? self::ITEM_BASE_SCHEMA_OUTPUT : self::ITEM_BASE_SCHEMA;
}

$allOf = new \ArrayObject(['allOf' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/Entity/DummyDtoCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
new Delete(),
new Post(input: CustomInputDto::class, processor: CustomInputDtoProcessor::class),
new GetCollection(),
new GetCollection(output: CustomOutputDto::class, uriTemplate: 'dummy_dto_custom_output', provider: CustomOutputDtoProvider::class),
new GetCollection(output: CustomOutputDto::class, uriTemplate: 'dummy_dto_custom_output', provider: CustomOutputDtoProvider::class, name: 'dummy_dto_custom_output_collection'),
new Get(output: CustomOutputDto::class, uriTemplate: 'dummy_dto_custom_output/{id}', provider: CustomOutputDtoProvider::class),
new Post(output: false, uriTemplate: 'dummy_dto_custom_post_without_output'),
]
Expand Down
8 changes: 8 additions & 0 deletions tests/Symfony/Bundle/Test/ApiTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Address;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DirectMercure;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyDtoCustom;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyDtoInputOutput;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue6041\NumericValidated;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue6146\Issue6146Child;
Expand Down Expand Up @@ -193,6 +194,13 @@ public function testAssertMatchesResourceItemJsonSchema(string $format, string $
$this->assertMatchesResourceItemJsonSchema(ResourceInterface::class, format: $format);
}

#[\PHPUnit\Framework\Attributes\DataProvider('providerFormats')]
public function testAssertMatchesResourceItemJsonSchemaWithCustomOutput(string $format, string $mimeType): void
{
self::createClient()->request('GET', '/dummy_dto_custom_output/some-id', ['headers' => ['Accept' => $mimeType]]);
$this->assertMatchesResourceItemJsonSchema(DummyDtoCustom::class, operationName: 'dummy_dto_custom_output_collection', format: $format);
}

#[\PHPUnit\Framework\Attributes\DataProvider('providerFormats')]
#[\PHPUnit\Framework\Attributes\Group('orm')]
public function testAssertMatchesResourceItemJsonSchemaWithCustomJson(string $format, string $mimeType): void
Expand Down
Loading