Skip to content

Commit 52ddc6b

Browse files
committed
fix(openapi): maintain json schema for non-json operations
fixes #7527
1 parent 44f2271 commit 52ddc6b

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,8 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
266266

267267
foreach ($responseMimeTypes as $operationFormat) {
268268
$operationOutputSchema = null;
269-
// Having JSONSchema for non-json schema makes no sense
270-
if (str_starts_with($operationFormat, 'json')) {
271-
$operationOutputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_OUTPUT, $operation, $schema, null, $forceSchemaCollection);
272-
$this->appendSchemaDefinitions($schemas, $operationOutputSchema->getDefinitions());
273-
}
269+
$operationOutputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_OUTPUT, $operation, $schema, null, $forceSchemaCollection);
270+
$this->appendSchemaDefinitions($schemas, $operationOutputSchema->getDefinitions());
274271

275272
$operationOutputSchemas[$operationFormat] = $operationOutputSchema;
276273
}
@@ -458,10 +455,8 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
458455
$operationInputSchemas = [];
459456
foreach ($requestMimeTypes as $operationFormat) {
460457
$operationInputSchema = null;
461-
if (str_starts_with($operationFormat, 'json')) {
462-
$operationInputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection);
463-
$this->appendSchemaDefinitions($schemas, $operationInputSchema->getDefinitions());
464-
}
458+
$operationInputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection);
459+
$this->appendSchemaDefinitions($schemas, $operationInputSchema->getDefinitions());
465460

466461
$operationInputSchemas[$operationFormat] = $operationInputSchema;
467462
}
@@ -999,11 +994,8 @@ private function addOperationErrors(
999994
$operationErrorSchemas = [];
1000995
foreach ($responseMimeTypes as $operationFormat) {
1001996
$operationErrorSchema = null;
1002-
// Having JSONSchema for non-json schema makes no sense
1003-
if (str_starts_with($operationFormat, 'json')) {
1004-
$operationErrorSchema = $this->jsonSchemaFactory->buildSchema($errorResource->getClass(), $operationFormat, Schema::TYPE_OUTPUT, null, $schema);
1005-
$this->appendSchemaDefinitions($schemas, $operationErrorSchema->getDefinitions());
1006-
}
997+
$operationErrorSchema = $this->jsonSchemaFactory->buildSchema($errorResource->getClass(), $operationFormat, Schema::TYPE_OUTPUT, null, $schema);
998+
$this->appendSchemaDefinitions($schemas, $operationErrorSchema->getDefinitions());
1007999
$operationErrorSchemas[$operationFormat] = $operationErrorSchema;
10081000
}
10091001

0 commit comments

Comments
 (0)