diff --git a/src/JsonSchema/SchemaFactory.php b/src/JsonSchema/SchemaFactory.php index 097eaddd4b8..ea25a99c983 100644 --- a/src/JsonSchema/SchemaFactory.php +++ b/src/JsonSchema/SchemaFactory.php @@ -74,6 +74,14 @@ public function buildSchema(string $className, string $format = 'json', string $ return $schema; } + if ('input' === $type && !($operation?->canDeserialize() ?? true)) { + return $schema; + } + + if ('output' === $type && !($operation?->canSerialize() ?? true)) { + return $schema; + } + $validationGroups = $operation ? $this->getValidationGroups($operation) : []; $version = $schema->getVersion(); $definitionName = $this->definitionNameFactory->create($className, $format, $inputOrOutputClass, $operation, $serializerContext); diff --git a/tests/Fixtures/TestBundle/ApiResource/Issue6276/SerializeResource.php b/tests/Fixtures/TestBundle/ApiResource/Issue6276/SerializeResource.php new file mode 100644 index 00000000000..3613a566257 --- /dev/null +++ b/tests/Fixtures/TestBundle/ApiResource/Issue6276/SerializeResource.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6276; + +use ApiPlatform\Metadata\Delete; + +#[Delete(deserialize: false, serialize: false)] +final class SerializeResource +{ +}