Skip to content

Commit 79611ba

Browse files
committed
fix: string schema type is now taken into account
1 parent da61996 commit 79611ba

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/Attributes/Response.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ public function __construct(
2525
private int $code = 200,
2626
private string $description = '',
2727
private ?string $responseType = null,
28-
private ?string $schemaType = SchemaType::OBJECT,
28+
private ?string $schemaType = null,
2929
private ?string $ref = null,
3030
private array $extra = [],
3131
) {
32-
if ($ref) {
32+
if ($this->schemaType) {
3333
$this->schema = new Schema($schemaType);
34+
}
3435

36+
if ($ref) {
3537
if ($schemaType === SchemaType::OBJECT) {
3638
$this->schema->addProperty(new RefProperty($ref));
3739
} elseif ($schemaType === SchemaType::ARRAY) {

src/Attributes/Schema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ private function getMediaType(): string
4343
return $property->getContentMediaType();
4444
}
4545

46+
if ($this->schemaType === SchemaType::STRING) {
47+
return 'text/plain';
48+
}
49+
4650
// By default, return json type
4751
return 'application/json';
4852
}

tests/Examples/Dummy/DummyController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getImage(#[Parameter("prop1")] int $prop1): void
6969
Property(Type::STRING, "prop1"),
7070
Property(Type::STRING, "prop2", "Prop2 description"),
7171
Property(Type::STRING, "prop3", "Prop3 description", "Value 3 example"),
72-
Response(201)
72+
Response(201, schemaType: SchemaType::STRING)
7373
]
7474
public function post(): void
7575
{

0 commit comments

Comments
 (0)