Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Processors/AugmentRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ protected function augmentRequestBody(Analysis $analysis, array $requestBodies):
$requestBody->ref = $schema->ref;
}

// Fall back: resolve parameter type to a Schema ref
if (Generator::isDefault($requestBody->ref)) {
$type = $context->reflector->getType();
if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
$className = $type->getName();
if ($schemaAnnotation = $analysis->getAnnotationForSource($className, OA\Schema::class)) {
$requestBody->ref = OA\Components::ref($schemaAnnotation);
}
}
}

if (Generator::isDefault($requestBody->required)) {
$requestBody->required = !$schema->isNullable();
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixtures/Scratch/RequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@ public function postRef()
public function postRefFoo(#[OAT\RequestBody] RequestBodyRefFoo $body)
{
}

#[OAT\Post(
path: '/endpoint/schema-param',
responses: [
new OAT\Response(
response: 200,
description: 'All good'
),
]
)]
public function postSchemaParam(#[OAT\RequestBody] RequestBodySchema $body)
{
}
}
8 changes: 8 additions & 0 deletions tests/Fixtures/Scratch/RequestBody3.0.0-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ paths:
responses:
'200':
description: 'All good'
/endpoint/schema-param:
post:
operationId: e9325a4f940b91d3babe398eeebd8426
requestBody:
$ref: '#/components/schemas/RequestBodySchema'
responses:
'200':
description: 'All good'
components:
schemas:
RequestBodySchema: { }
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/Scratch/RequestBody3.0.0-type-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ paths:
responses:
'200':
description: 'All good'
/endpoint/schema-param:
post:
operationId: e9325a4f940b91d3babe398eeebd8426
requestBody:
$ref: '#/components/schemas/RequestBodySchema'
responses:
'200':
description: 'All good'
components:
schemas:
RequestBodySchema: { }
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/Scratch/RequestBody3.1.0-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ paths:
responses:
'200':
description: 'All good'
/endpoint/schema-param:
post:
operationId: e9325a4f940b91d3babe398eeebd8426
requestBody:
$ref: '#/components/schemas/RequestBodySchema'
responses:
'200':
description: 'All good'
components:
schemas:
RequestBodySchema: { }
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/Scratch/RequestBody3.1.0-type-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ paths:
responses:
'200':
description: 'All good'
/endpoint/schema-param:
post:
operationId: e9325a4f940b91d3babe398eeebd8426
requestBody:
$ref: '#/components/schemas/RequestBodySchema'
responses:
'200':
description: 'All good'
components:
schemas:
RequestBodySchema: { }
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/Scratch/RequestBody3.2.0-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ paths:
responses:
'200':
description: 'All good'
/endpoint/schema-param:
post:
operationId: e9325a4f940b91d3babe398eeebd8426
requestBody:
$ref: '#/components/schemas/RequestBodySchema'
responses:
'200':
description: 'All good'
components:
schemas:
RequestBodySchema: { }
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/Scratch/RequestBody3.2.0-type-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ paths:
responses:
'200':
description: 'All good'
/endpoint/schema-param:
post:
operationId: e9325a4f940b91d3babe398eeebd8426
requestBody:
$ref: '#/components/schemas/RequestBodySchema'
responses:
'200':
description: 'All good'
components:
schemas:
RequestBodySchema: { }
Expand Down