Skip to content

Commit a1b6fba

Browse files
authored
Check Context has a reflector and is not nested (#1824)
1 parent a0768f7 commit a1b6fba

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

src/Processors/AugmentProperties.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public function __invoke(Analysis $analysis): void
7070
protected function augmentSchemaType(Analysis $analysis, OA\Schema $schema): void
7171
{
7272
$context = $schema->_context;
73+
74+
if (null === $context->reflector || $context->is('nested')) {
75+
return;
76+
}
77+
7378
$typeResolver = $this->generator->getTypeResolver();
7479
if (method_exists($typeResolver, 'setContext')) {
7580
$typeResolver->setContext($context);

src/Processors/MergeIntoOpenApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __invoke(Analysis $analysis): void
2020
{
2121
// Auto-create the OpenApi annotation.
2222
if (!$analysis->openapi) {
23-
$context = new Context([], $analysis->context);
23+
$context = new Context(['generated' => true], $analysis->context);
2424
$analysis->addAnnotation(new OA\OpenApi(['_context' => $context]), $context);
2525
}
2626
$openapi = $analysis->openapi;

tests/Fixtures/Scratch/NestedSchema.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,39 @@
88

99
use OpenApi\Attributes as OAT;
1010

11+
#[OAT\Schema]
12+
class NestedSchemaOne
13+
{
14+
}
15+
16+
#[OAT\Schema]
17+
class NestedSchemaTwo
18+
{
19+
}
20+
1121
#[OAT\Info(
1222
title: 'Parameter Content Scratch',
1323
version: '1.0'
1424
)]
15-
#[OAT\Get(
25+
#[OAT\Post(
1626
path: '/api/endpoint',
27+
requestBody: new OAT\RequestBody(content: [new OAT\MediaType(
28+
mediaType: 'application/json',
29+
schema: new OAT\Schema(
30+
required: ['note'],
31+
properties: [
32+
new OAT\Property(property: 'note', example: 'My note'),
33+
new OAT\Property(
34+
property: 'other',
35+
description: 'other',
36+
oneOf: [
37+
new OAT\Schema(type: NestedSchemaOne::class),
38+
new OAT\Schema(type: NestedSchemaTwo::class),
39+
]
40+
),
41+
]
42+
)
43+
)]),
1744
responses: [new OAT\Response(response: 200, description: 'OK')]
1845
)]
1946
#[OAT\Schema(

tests/Fixtures/Scratch/NestedSchema3.0.0.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@ info:
44
version: '1.0'
55
paths:
66
/api/endpoint:
7-
get:
8-
operationId: b870e13084c8a89270151bb3e43f215a
7+
post:
8+
operationId: 4dcf657dcdcd504467bc7a4ac7d21084
9+
requestBody:
10+
content:
11+
application/json:
12+
schema:
13+
required:
14+
- note
15+
properties:
16+
note:
17+
example: 'My note'
18+
other:
19+
description: other
20+
oneOf: [{ $ref: '#/components/schemas/NestedSchemaOne' }, { $ref: '#/components/schemas/NestedSchemaTwo' }]
21+
type: object
922
responses:
1023
'200':
1124
description: OK
1225
components:
1326
schemas:
27+
NestedSchemaOne: { }
28+
NestedSchemaTwo: { }
1429
NestedSchema:
1530
required:
1631
- errors

tests/Fixtures/Scratch/NestedSchema3.1.0.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@ info:
44
version: '1.0'
55
paths:
66
/api/endpoint:
7-
get:
8-
operationId: b870e13084c8a89270151bb3e43f215a
7+
post:
8+
operationId: 4dcf657dcdcd504467bc7a4ac7d21084
9+
requestBody:
10+
content:
11+
application/json:
12+
schema:
13+
required:
14+
- note
15+
properties:
16+
note:
17+
example: 'My note'
18+
other:
19+
description: other
20+
oneOf: [{ $ref: '#/components/schemas/NestedSchemaOne' }, { $ref: '#/components/schemas/NestedSchemaTwo' }]
21+
type: object
922
responses:
1023
'200':
1124
description: OK
1225
components:
1326
schemas:
27+
NestedSchemaOne: { }
28+
NestedSchemaTwo: { }
1429
NestedSchema:
1530
required:
1631
- errors

0 commit comments

Comments
 (0)