diff --git a/src/OpenApi/Factory/OpenApiFactory.php b/src/OpenApi/Factory/OpenApiFactory.php index 2854faf2d9f..740f302032b 100644 --- a/src/OpenApi/Factory/OpenApiFactory.php +++ b/src/OpenApi/Factory/OpenApiFactory.php @@ -266,11 +266,8 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection foreach ($responseMimeTypes as $operationFormat) { $operationOutputSchema = null; - // Having JSONSchema for non-json schema makes no sense - if (str_starts_with($operationFormat, 'json')) { - $operationOutputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_OUTPUT, $operation, $schema, null, $forceSchemaCollection); - $this->appendSchemaDefinitions($schemas, $operationOutputSchema->getDefinitions()); - } + $operationOutputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_OUTPUT, $operation, $schema, null, $forceSchemaCollection); + $this->appendSchemaDefinitions($schemas, $operationOutputSchema->getDefinitions()); $operationOutputSchemas[$operationFormat] = $operationOutputSchema; } @@ -458,10 +455,8 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection $operationInputSchemas = []; foreach ($requestMimeTypes as $operationFormat) { $operationInputSchema = null; - if (str_starts_with($operationFormat, 'json')) { - $operationInputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection); - $this->appendSchemaDefinitions($schemas, $operationInputSchema->getDefinitions()); - } + $operationInputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection); + $this->appendSchemaDefinitions($schemas, $operationInputSchema->getDefinitions()); $operationInputSchemas[$operationFormat] = $operationInputSchema; } @@ -999,11 +994,8 @@ private function addOperationErrors( $operationErrorSchemas = []; foreach ($responseMimeTypes as $operationFormat) { $operationErrorSchema = null; - // Having JSONSchema for non-json schema makes no sense - if (str_starts_with($operationFormat, 'json')) { - $operationErrorSchema = $this->jsonSchemaFactory->buildSchema($errorResource->getClass(), $operationFormat, Schema::TYPE_OUTPUT, null, $schema); - $this->appendSchemaDefinitions($schemas, $operationErrorSchema->getDefinitions()); - } + $operationErrorSchema = $this->jsonSchemaFactory->buildSchema($errorResource->getClass(), $operationFormat, Schema::TYPE_OUTPUT, null, $schema); + $this->appendSchemaDefinitions($schemas, $operationErrorSchema->getDefinitions()); $operationErrorSchemas[$operationFormat] = $operationErrorSchema; } diff --git a/src/OpenApi/Tests/Factory/OpenApiFactoryTest.php b/src/OpenApi/Tests/Factory/OpenApiFactoryTest.php index 033d0efdde3..e5cbd0d7eaf 100644 --- a/src/OpenApi/Tests/Factory/OpenApiFactoryTest.php +++ b/src/OpenApi/Tests/Factory/OpenApiFactoryTest.php @@ -658,7 +658,9 @@ public function testInvoke(): void $this->assertEquals($components->getSchemas(), new \ArrayObject([ 'Dummy' => $dummySchema->getDefinitions(), 'Dummy.OutputDto' => $dummySchema->getDefinitions(), + 'Dummy.OutputDto.csv' => $dummySchema->getDefinitions(), 'Dummy.jsonld' => $dummySchema->getDefinitions(), + 'Dummy.csv' => $dummySchema->getDefinitions(), 'Dummy.OutputDto.jsonld' => $dummySchema->getDefinitions(), 'Parameter.jsonld' => $parameterSchema, 'DummyErrorResource' => $dummyErrorSchema->getDefinitions(), @@ -897,7 +899,7 @@ public function testInvoke(): void 'Dummy resource updated', new \ArrayObject([ 'application/json' => new MediaType(new \ArrayObject(['$ref' => '#/components/schemas/Dummy.OutputDto'])), - 'text/csv' => new \ArrayObject(), + 'text/csv' => new MediaType(new \ArrayObject(['$ref' => '#/components/schemas/Dummy.OutputDto.csv'])), ]), null, new \ArrayObject(['getDummyItem' => new Model\Link('getDummyItem', new \ArrayObject(['id' => '$request.path.id']), null, 'This is a dummy')]) @@ -926,7 +928,7 @@ public function testInvoke(): void 'The updated Dummy resource', new \ArrayObject([ 'application/json' => new MediaType(new \ArrayObject(['$ref' => '#/components/schemas/Dummy'])), - 'text/csv' => new \ArrayObject(), + 'text/csv' => new MediaType(new \ArrayObject(['$ref' => '#/components/schemas/Dummy.csv'])), ]), true ) diff --git a/tests/Fixtures/TestBundle/ApiResource/WithParameter.php b/tests/Fixtures/TestBundle/ApiResource/WithParameter.php index dfb8c4d04dd..02cd55d884f 100644 --- a/tests/Fixtures/TestBundle/ApiResource/WithParameter.php +++ b/tests/Fixtures/TestBundle/ApiResource/WithParameter.php @@ -93,6 +93,7 @@ provider: [self::class, 'collectionProvider'], )] #[GetCollection( + openapi: false, uriTemplate: 'validate_parameters{._format}', parameters: [ 'enum' => new QueryParameter( diff --git a/tests/Fixtures/TestBundle/Entity/FilterValidator.php b/tests/Fixtures/TestBundle/Entity/FilterValidator.php index 9ded4c39a22..799b208534b 100644 --- a/tests/Fixtures/TestBundle/Entity/FilterValidator.php +++ b/tests/Fixtures/TestBundle/Entity/FilterValidator.php @@ -30,7 +30,11 @@ * * @author Julien Deniau */ -#[ApiResource(filters: [ArrayItemsFilter::class, BoundsFilter::class, EnumFilter::class, LengthFilter::class, MultipleOfFilter::class, PatternFilter::class, RequiredFilter::class, RequiredAllowEmptyFilter::class], graphQlOperations: [])] +#[ApiResource( + filters: [ArrayItemsFilter::class, BoundsFilter::class, EnumFilter::class, LengthFilter::class, MultipleOfFilter::class, PatternFilter::class, RequiredFilter::class, RequiredAllowEmptyFilter::class], + graphQlOperations: [], + openapi: false +)] #[ORM\Entity] class FilterValidator {