Skip to content

Fix parameter-level schema output by returning raw definition #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions src/Attributes/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ public function __construct(
public function toArray(): array
{
if ($this->definition !== null) {
return [
'definition' => $this->definition,
];
return $this->definition;
}

$schema = [];
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixtures/Utils/SchemaGeneratorFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,17 @@ public function parameterSchemaInferredType(
$inferredParam
): void {
}

/**
* Parameter with complete custom definition via #[Schema(definition: ...)]
*/
public function parameterWithRawDefinition(
#[Schema(definition: [
'description' => 'Custom-defined schema',
'type' => 'string',
'format' => 'uuid'
])]
string $custom
): void {
}
}
13 changes: 13 additions & 0 deletions tests/Integration/SchemaGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,16 @@

expect($schema['required'])->toEqual(['inferredParam']);
});

it('uses raw parameter-level schema definition as-is', function () {
$method = new ReflectionMethod(SchemaGeneratorFixture::class, 'parameterWithRawDefinition');
$schema = $this->schemaGenerator->generate($method);

expect($schema['properties']['custom'])->toEqual([
'description' => 'Custom-defined schema',
'type' => 'string',
'format' => 'uuid'
]);

expect($schema['required'])->toEqual(['custom']);
});