diff --git a/src/Processors/AugmentRequestBody.php b/src/Processors/AugmentRequestBody.php index 104e6f1c8..dd9825a3d 100644 --- a/src/Processors/AugmentRequestBody.php +++ b/src/Processors/AugmentRequestBody.php @@ -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(); } diff --git a/tests/Fixtures/Scratch/RequestBody.php b/tests/Fixtures/Scratch/RequestBody.php index 2208bf20b..8feb5e018 100644 --- a/tests/Fixtures/Scratch/RequestBody.php +++ b/tests/Fixtures/Scratch/RequestBody.php @@ -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) + { + } } diff --git a/tests/Fixtures/Scratch/RequestBody3.0.0-legacy.yaml b/tests/Fixtures/Scratch/RequestBody3.0.0-legacy.yaml index 9348b72ca..52e51b24b 100644 --- a/tests/Fixtures/Scratch/RequestBody3.0.0-legacy.yaml +++ b/tests/Fixtures/Scratch/RequestBody3.0.0-legacy.yaml @@ -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: { } diff --git a/tests/Fixtures/Scratch/RequestBody3.0.0-type-info.yaml b/tests/Fixtures/Scratch/RequestBody3.0.0-type-info.yaml index 724732237..b26c96dd6 100644 --- a/tests/Fixtures/Scratch/RequestBody3.0.0-type-info.yaml +++ b/tests/Fixtures/Scratch/RequestBody3.0.0-type-info.yaml @@ -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: { } diff --git a/tests/Fixtures/Scratch/RequestBody3.1.0-legacy.yaml b/tests/Fixtures/Scratch/RequestBody3.1.0-legacy.yaml index 8a0474e9c..a55ae7649 100644 --- a/tests/Fixtures/Scratch/RequestBody3.1.0-legacy.yaml +++ b/tests/Fixtures/Scratch/RequestBody3.1.0-legacy.yaml @@ -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: { } diff --git a/tests/Fixtures/Scratch/RequestBody3.1.0-type-info.yaml b/tests/Fixtures/Scratch/RequestBody3.1.0-type-info.yaml index 7f2ae1812..e8e9039c1 100644 --- a/tests/Fixtures/Scratch/RequestBody3.1.0-type-info.yaml +++ b/tests/Fixtures/Scratch/RequestBody3.1.0-type-info.yaml @@ -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: { } diff --git a/tests/Fixtures/Scratch/RequestBody3.2.0-legacy.yaml b/tests/Fixtures/Scratch/RequestBody3.2.0-legacy.yaml index d2b6b706f..d5e83e96b 100644 --- a/tests/Fixtures/Scratch/RequestBody3.2.0-legacy.yaml +++ b/tests/Fixtures/Scratch/RequestBody3.2.0-legacy.yaml @@ -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: { } diff --git a/tests/Fixtures/Scratch/RequestBody3.2.0-type-info.yaml b/tests/Fixtures/Scratch/RequestBody3.2.0-type-info.yaml index d3e3a73a8..8e2539240 100644 --- a/tests/Fixtures/Scratch/RequestBody3.2.0-type-info.yaml +++ b/tests/Fixtures/Scratch/RequestBody3.2.0-type-info.yaml @@ -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: { }