Skip to content

Commit 2c5c9e4

Browse files
authored
fix(openapi): no content schema (#7384)
1 parent 8827e1b commit 2c5c9e4

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

features/json/input_output.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Feature: JSON DTO input and output
99

1010
@createSchema
1111
Scenario: Request a password reset
12-
And I send a "POST" request to "/users/password_reset_request" with body:
12+
And I send a "POST" request to "/users_reset/password_reset_request" with body:
1313
"""
1414
{
1515
"email": "user@example.com"
@@ -27,7 +27,7 @@ Feature: JSON DTO input and output
2727

2828
@createSchema
2929
Scenario: Request a password reset for a non-existent user
30-
And I send a "POST" request to "/users/password_reset_request" with body:
30+
And I send a "POST" request to "/users_reset/password_reset_request" with body:
3131
"""
3232
{
3333
"email": "does-not-exist@example.com"

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,13 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
498498

499499
private function buildOpenApiResponse(array $existingResponses, int|string $status, string $description, ?Operation $openapiOperation = null, ?HttpOperation $operation = null, ?array $responseMimeTypes = null, ?array $operationOutputSchemas = null, ?ResourceMetadataCollection $resourceMetadataCollection = null): Operation
500500
{
501+
$noOutput = \is_array($operation?->getOutput()) && null === $operation->getOutput()['class'];
502+
501503
if (isset($existingResponses[$status])) {
502504
return $openapiOperation;
503505
}
504506
$responseLinks = $responseContent = null;
505-
if ($responseMimeTypes && $operationOutputSchemas) {
507+
if ($responseMimeTypes && $operationOutputSchemas && !$noOutput) {
506508
$responseContent = $this->buildContent($responseMimeTypes, $operationOutputSchemas);
507509
}
508510
if ($resourceMetadataCollection && $operation) {

src/State/Exception/ParameterNotSupportedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getType(): string
2828
return '/error/400';
2929
}
3030

31-
public function getTitle(): ?string
31+
public function getTitle(): string
3232
{
3333
return $this->message;
3434
}

tests/Fixtures/TestBundle/ApiResource/WithParameter.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,37 @@
9696
uriTemplate: 'validate_parameters{._format}',
9797
parameters: [
9898
'enum' => new QueryParameter(
99-
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true],
99+
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true, 'type' => 'array'],
100100
castToArray: true,
101101
openApi: new OpenApiParameter(name: 'enum', in: 'query', style: 'deepObject')
102102
),
103103
'enumNotDeepObject' => new QueryParameter(
104-
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true],
104+
schema: ['enum' => ['a', 'b'], 'uniqueItems' => true, 'type' => 'string'],
105105
castToArray: true,
106+
castToNativeType: true,
106107
),
107108
'num' => new QueryParameter(
108-
schema: ['minimum' => 1, 'maximum' => 3],
109+
schema: ['minimum' => 1, 'maximum' => 3, 'type' => 'integer'],
109110
nativeType: new BuiltinType(TypeIdentifier::STRING),
110111
),
111112
'numMultipleType' => new QueryParameter(
112-
schema: ['minimum' => 1, 'maximum' => 3],
113+
schema: ['minimum' => 1, 'maximum' => 3, 'type' => 'array'],
113114
),
114115
'exclusiveNum' => new QueryParameter(
115-
schema: ['exclusiveMinimum' => 1, 'exclusiveMaximum' => 3],
116+
schema: ['exclusiveMinimum' => 1, 'exclusiveMaximum' => 3, 'type' => 'integer'],
116117
nativeType: new BuiltinType(TypeIdentifier::STRING),
117118
),
118119
'blank' => new QueryParameter(
119120
openApi: new OpenApiParameter(name: 'blank', in: 'query', allowEmptyValue: false),
120121
nativeType: new BuiltinType(TypeIdentifier::STRING),
121122
),
122123
'length' => new QueryParameter(
123-
schema: ['maxLength' => 1, 'minLength' => 3],
124+
schema: ['maxLength' => 1, 'minLength' => 3, 'type' => 'integer'],
124125
nativeType: new BuiltinType(TypeIdentifier::STRING),
125126
),
126-
'array' => new QueryParameter(schema: ['minItems' => 2, 'maxItems' => 3]),
127+
'array' => new QueryParameter(schema: ['minItems' => 2, 'maxItems' => 3, 'type' => 'integer']),
127128
'multipleOf' => new QueryParameter(
128-
schema: ['multipleOf' => 2],
129+
schema: ['multipleOf' => 2, 'type' => 'integer'],
129130
nativeType: new BuiltinType(TypeIdentifier::STRING),
130131
),
131132
'int' => new QueryParameter(

tests/Fixtures/TestBundle/Entity/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
#[ApiResource(operations: [
3939
new Post(
40-
uriTemplate: '/users/password_reset_request',
40+
uriTemplate: '/users_reset/password_reset_request',
4141
messenger: 'input',
4242
input: PasswordResetRequest::class,
4343
output: PasswordResetRequestResult::class,

tests/Functional/Parameters/ValidationTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ public static function provideQueryStrings(): array
5858
[
5959
'enumNotDeepObject[]=c&enumNotDeepObject[]=c',
6060
[
61-
[
62-
'propertyPath' => 'enumNotDeepObject', 'message' => 'The value you selected is not a valid choice.',
63-
],
6461
[
6562
'propertyPath' => 'enumNotDeepObject', 'message' => 'The value you selected is not a valid choice.',
6663
],

0 commit comments

Comments
 (0)