Skip to content

Commit be3010f

Browse files
committed
fix: schema definition wrapped in 'definition' key when using parameter-level #[Schema(definition: [...])]
1 parent 9d2e7e4 commit be3010f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/Attributes/Schema.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ public function __construct(
132132
public function toArray(): array
133133
{
134134
if ($this->definition !== null) {
135-
return [
136-
'definition' => $this->definition,
137-
];
135+
return $this->definition;
138136
}
139137

140138
$schema = [];

tests/Fixtures/Utils/SchemaGeneratorFixture.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,17 @@ public function parameterSchemaInferredType(
397397
$inferredParam
398398
): void {
399399
}
400+
401+
/**
402+
* Parameter with complete custom definition via #[Schema(definition: ...)]
403+
*/
404+
public function parameterWithRawDefinition(
405+
#[Schema(definition: [
406+
'description' => 'Custom-defined schema',
407+
'type' => 'string',
408+
'format' => 'uuid'
409+
])]
410+
string $custom
411+
): void {
412+
}
400413
}

tests/Integration/SchemaGenerationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,16 @@
354354

355355
expect($schema['required'])->toEqual(['inferredParam']);
356356
});
357+
358+
it('uses raw parameter-level schema definition as-is', function () {
359+
$method = new ReflectionMethod(SchemaGeneratorFixture::class, 'parameterWithRawDefinition');
360+
$schema = $this->schemaGenerator->generate($method);
361+
362+
expect($schema['properties']['custom'])->toEqual([
363+
'description' => 'Custom-defined schema',
364+
'type' => 'string',
365+
'format' => 'uuid'
366+
]);
367+
368+
expect($schema['required'])->toEqual(['custom']);
369+
});

0 commit comments

Comments
 (0)