Skip to content

Commit 8adf6bb

Browse files
[Backport #1949 to 5.x] Fix regression about unexpected items when augmenting parameters (#1950)
* BACKPORT-CONFLICT * Fix merge issues --------- Co-authored-by: Martin Rademacher <mano@radebatz.net>
1 parent e602a78 commit 8adf6bb

5 files changed

Lines changed: 242 additions & 40 deletions

File tree

src/Processors/AugmentParameters.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,31 @@ protected function augmentParameters(Analysis $analysis): void
6565
}
6666

6767
if ($context->reflector instanceof \ReflectionParameter) {
68-
if (Generator::isDefault($parameter->schema)) {
69-
$schema = new OA\Schema(['_context' => new Context(['reflector' => $context->reflector], $context)]);
70-
$this->generator->getTypeResolver()->augmentSchemaType($analysis, $schema);
71-
72-
$parameter->merge([new OA\Schema([
73-
'type' => $schema->type,
74-
'format' => $schema->format,
75-
'ref' => $schema->ref,
76-
'_context' => new Context(['nested' => $this, 'comment' => null, 'reflector' => $context->reflector], $context)]),
77-
]);
78-
} else {
79-
$schema = $parameter->schema;
80-
}
68+
$schema = Generator::isDefault($parameter->schema)
69+
? new OA\Schema([
70+
'_context' => new Context([
71+
'generated' => true,
72+
'reflector' => $context->reflector,
73+
], $context),
74+
])
75+
: $parameter->schema;
76+
77+
$this->generator->getTypeResolver()->augmentSchemaType($analysis, $schema);
78+
79+
$parameter->merge([new OA\Schema([
80+
'type' => $schema->type,
81+
'format' => $schema->format,
82+
'items' => $schema->items,
83+
'oneOf' => $schema->oneOf,
84+
'allOf' => $schema->allOf,
85+
'anyOf' => $schema->anyOf,
86+
'ref' => $schema->ref,
87+
'_context' => new Context([
88+
'nested' => $this,
89+
'comment' => null,
90+
'reflector' => $context->reflector,
91+
], $context)]),
92+
]);
8193

8294
if (Generator::isDefault($parameter->required)) {
8395
$parameter->required = !$schema->isNullable();

tests/Fixtures/Scratch/NestedSchema.php

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,6 @@ public function __construct(
3838
title: 'Parameter Content Scratch',
3939
version: '1.0'
4040
)]
41-
#[OAT\Post(
42-
path: '/api/endpoint',
43-
requestBody: new OAT\RequestBody(content: [new OAT\MediaType(
44-
mediaType: 'application/json',
45-
schema: new OAT\Schema(
46-
required: ['note'],
47-
properties: [
48-
new OAT\Property(property: 'note', example: 'My note'),
49-
new OAT\Property(
50-
property: 'other',
51-
description: 'other',
52-
oneOf: [
53-
new OAT\Schema(type: NestedSchemaOne::class),
54-
new OAT\Schema(type: NestedSchemaTwo::class),
55-
]
56-
),
57-
]
58-
)
59-
)]),
60-
responses: [new OAT\Response(response: 200, description: 'OK')]
61-
)]
6241
#[OAT\Schema(
6342
required: ['errors'],
6443
properties: [
@@ -84,3 +63,79 @@ public function __construct(
8463
class NestedSchema
8564
{
8665
}
66+
67+
class NestedSchemaController
68+
{
69+
#[OAT\Post(
70+
path: '/api/post',
71+
operationId: 'post',
72+
requestBody: new OAT\RequestBody(content: [new OAT\MediaType(
73+
mediaType: 'application/json',
74+
schema: new OAT\Schema(
75+
required: ['note'],
76+
properties: [
77+
new OAT\Property(property: 'note', example: 'My note'),
78+
new OAT\Property(
79+
property: 'other',
80+
description: 'other',
81+
oneOf: [
82+
new OAT\Schema(type: NestedSchemaOne::class),
83+
new OAT\Schema(type: NestedSchemaTwo::class),
84+
]
85+
),
86+
]
87+
)
88+
)]),
89+
responses: [new OAT\Response(response: 200, description: 'OK')]
90+
)]
91+
public function post()
92+
{
93+
94+
}
95+
96+
/**
97+
* @param string[] $tags
98+
*/
99+
#[OAT\Get(
100+
path: '/api/get',
101+
operationId: 'get',
102+
)]
103+
#[OAT\Response(response: 200, description: 'successful operation')]
104+
public function get(
105+
#[OAT\QueryParameter(
106+
schema: new OAT\Schema(
107+
type: 'array',
108+
items: new OAT\Items(type: 'string')
109+
)
110+
)] array $tags,
111+
) {
112+
}
113+
114+
#[OAT\Put(
115+
path: '/api/put',
116+
operationId: 'put',
117+
)]
118+
#[OAT\Response(response: 200, description: 'successful operation')]
119+
public function put(
120+
#[OAT\QueryParameter(
121+
schema: new OAT\Schema(
122+
type: 'array',
123+
items: new OAT\Items(type: 'string')
124+
)
125+
)] array $tags,
126+
) {
127+
}
128+
129+
/**
130+
* @param string[] $tags
131+
*/
132+
#[OAT\Delete(
133+
path: '/api/delete',
134+
operationId: 'delete',
135+
)]
136+
#[OAT\Response(response: 200, description: 'successful operation')]
137+
public function delete(
138+
#[OAT\QueryParameter] array $tags,
139+
) {
140+
}
141+
}

tests/Fixtures/Scratch/NestedSchema3.0.0.yaml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ info:
33
title: 'Parameter Content Scratch'
44
version: '1.0'
55
paths:
6-
/api/endpoint:
6+
/api/post:
77
post:
8-
operationId: 4dcf657dcdcd504467bc7a4ac7d21084
8+
operationId: post
99
requestBody:
1010
content:
1111
application/json:
@@ -22,6 +22,51 @@ paths:
2222
responses:
2323
'200':
2424
description: OK
25+
/api/get:
26+
get:
27+
operationId: get
28+
parameters:
29+
-
30+
name: tags
31+
in: query
32+
required: true
33+
schema:
34+
type: array
35+
items:
36+
type: string
37+
responses:
38+
'200':
39+
description: 'successful operation'
40+
/api/put:
41+
put:
42+
operationId: put
43+
parameters:
44+
-
45+
name: tags
46+
in: query
47+
required: true
48+
schema:
49+
type: array
50+
items:
51+
type: string
52+
responses:
53+
'200':
54+
description: 'successful operation'
55+
/api/delete:
56+
delete:
57+
operationId: delete
58+
parameters:
59+
-
60+
name: tags
61+
in: query
62+
required: true
63+
schema:
64+
type: array
65+
items:
66+
type: string
67+
responses:
68+
'200':
69+
description: 'successful operation'
2570
components:
2671
schemas:
2772
NestedSchemaOne: { }

tests/Fixtures/Scratch/NestedSchema3.1.0.yaml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ info:
33
title: 'Parameter Content Scratch'
44
version: '1.0'
55
paths:
6-
/api/endpoint:
6+
/api/post:
77
post:
8-
operationId: 4dcf657dcdcd504467bc7a4ac7d21084
8+
operationId: post
99
requestBody:
1010
content:
1111
application/json:
@@ -22,6 +22,51 @@ paths:
2222
responses:
2323
'200':
2424
description: OK
25+
/api/get:
26+
get:
27+
operationId: get
28+
parameters:
29+
-
30+
name: tags
31+
in: query
32+
required: true
33+
schema:
34+
type: array
35+
items:
36+
type: string
37+
responses:
38+
'200':
39+
description: 'successful operation'
40+
/api/put:
41+
put:
42+
operationId: put
43+
parameters:
44+
-
45+
name: tags
46+
in: query
47+
required: true
48+
schema:
49+
type: array
50+
items:
51+
type: string
52+
responses:
53+
'200':
54+
description: 'successful operation'
55+
/api/delete:
56+
delete:
57+
operationId: delete
58+
parameters:
59+
-
60+
name: tags
61+
in: query
62+
required: true
63+
schema:
64+
type: array
65+
items:
66+
type: string
67+
responses:
68+
'200':
69+
description: 'successful operation'
2570
components:
2671
schemas:
2772
NestedSchemaOne: { }

tests/Fixtures/Scratch/NestedSchema3.2.0.yaml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ info:
33
title: 'Parameter Content Scratch'
44
version: '1.0'
55
paths:
6-
/api/endpoint:
6+
/api/post:
77
post:
8-
operationId: 4dcf657dcdcd504467bc7a4ac7d21084
8+
operationId: post
99
requestBody:
1010
content:
1111
application/json:
@@ -22,6 +22,51 @@ paths:
2222
responses:
2323
'200':
2424
description: OK
25+
/api/get:
26+
get:
27+
operationId: get
28+
parameters:
29+
-
30+
name: tags
31+
in: query
32+
required: true
33+
schema:
34+
type: array
35+
items:
36+
type: string
37+
responses:
38+
'200':
39+
description: 'successful operation'
40+
/api/put:
41+
put:
42+
operationId: put
43+
parameters:
44+
-
45+
name: tags
46+
in: query
47+
required: true
48+
schema:
49+
type: array
50+
items:
51+
type: string
52+
responses:
53+
'200':
54+
description: 'successful operation'
55+
/api/delete:
56+
delete:
57+
operationId: delete
58+
parameters:
59+
-
60+
name: tags
61+
in: query
62+
required: true
63+
schema:
64+
type: array
65+
items:
66+
type: string
67+
responses:
68+
'200':
69+
description: 'successful operation'
2570
components:
2671
schemas:
2772
NestedSchemaOne: { }

0 commit comments

Comments
 (0)