Skip to content

Commit f0717a5

Browse files
authored
Fix regression about unexpected items when augmenting parameters (#1949)
1 parent 40d8c82 commit f0717a5

5 files changed

Lines changed: 230 additions & 33 deletions

File tree

src/Processors/AugmentParameters.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,24 @@ protected function augmentParameters(Analysis $analysis): void
6666
}
6767

6868
if ($context->reflector instanceof \ReflectionParameter) {
69-
$schema = new OA\Schema([
70-
'_context' => new Context([
71-
'generated' => true,
72-
'reflector' => $context->reflector,
73-
], $context),
74-
]);
69+
$schema = Generator::isDefault($parameter->schema)
70+
? new OA\Schema([
71+
'_context' => new Context([
72+
'generated' => true,
73+
'reflector' => $context->reflector,
74+
], $context),
75+
])
76+
: $parameter->schema;
77+
7578
$this->generator->getTypeResolver()->augmentSchemaType($analysis, $schema);
7679

7780
$parameter->merge([new OA\Schema([
7881
'type' => $schema->type,
7982
'format' => $schema->format,
83+
'items' => $schema->items,
84+
'oneOf' => $schema->oneOf,
85+
'allOf' => $schema->allOf,
86+
'anyOf' => $schema->anyOf,
8087
'ref' => $schema->ref,
8188
'_context' => new Context([
8289
'nested' => $this,

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)