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
20 changes: 6 additions & 14 deletions src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions src/OpenApi/Tests/Factory/OpenApiFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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')])
Expand Down Expand Up @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/ApiResource/WithParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
provider: [self::class, 'collectionProvider'],
)]
#[GetCollection(
openapi: false,
uriTemplate: 'validate_parameters{._format}',
parameters: [
'enum' => new QueryParameter(
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/TestBundle/Entity/FilterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
*
* @author Julien Deniau <julien.deniau@gmail.com>
*/
#[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
{
Expand Down
Loading