Skip to content

Commit 885a42e

Browse files
committed
Add basic schema configuration
1 parent 9041ea0 commit 885a42e

File tree

7 files changed

+64
-0
lines changed

7 files changed

+64
-0
lines changed

src/Schema/Field/Boolean.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public function __construct(string $name)
1616
}
1717
});
1818
}
19+
20+
public function getSchema(): array
21+
{
22+
return parent::getSchema() + ['type' => 'boolean'];
23+
}
1924
}

src/Schema/Field/Date.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public function __construct(string $name)
3434
}
3535
});
3636
}
37+
38+
public function getSchema(): array
39+
{
40+
return parent::getSchema() + ['type' => 'string', 'format' => 'date'];
41+
}
3742
}

src/Schema/Field/DateTime.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public function __construct(string $name)
3232
}
3333
});
3434
}
35+
36+
public function getSchema(): array
37+
{
38+
return parent::getSchema() + ['type' => 'string', 'format' => 'date-time'];
39+
}
3540
}

src/Schema/Field/Field.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ abstract class Field
1414

1515
public ?string $property = null;
1616
public bool $nullable = false;
17+
public ?string $description = null;
18+
public array $schema = [];
1719

1820
public function __construct(public readonly string $name)
1921
{
@@ -37,4 +39,23 @@ public function nullable(bool $nullable = true): static
3739

3840
return $this;
3941
}
42+
43+
public function description(?string $description): static
44+
{
45+
$this->description = $description;
46+
47+
return $this;
48+
}
49+
50+
public function schema(array $schema): static
51+
{
52+
$this->schema = $schema;
53+
54+
return $this;
55+
}
56+
57+
public function getSchema(): array
58+
{
59+
return $this->schema + ['description' => $this->description, 'nullable' => $this->nullable];
60+
}
4061
}

src/Schema/Field/Integer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public function __construct(string $name)
1818
}
1919
});
2020
}
21+
22+
public function getSchema(): array
23+
{
24+
return ['type' => 'integer'] + parent::getSchema();
25+
}
2126
}

src/Schema/Field/Number.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,16 @@ public function multipleOf(?float $number): static
7373

7474
return $this;
7575
}
76+
77+
public function getSchema(): array
78+
{
79+
return parent::getSchema() + [
80+
'type' => 'number',
81+
'minimum' => $this->minimum,
82+
'exclusiveMinimum' => $this->exclusiveMinimum,
83+
'maximum' => $this->maximum,
84+
'exclusiveMaximum' => $this->exclusiveMaximum,
85+
'multipleOf' => $this->multipleOf,
86+
];
87+
}
7688
}

src/Schema/Field/Str.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ public function format(?string $format): static
6565

6666
return $this;
6767
}
68+
69+
public function getSchema(): array
70+
{
71+
return parent::getSchema() + [
72+
'type' => 'string',
73+
'minLength' => $this->minLength,
74+
'maxLength' => $this->maxLength,
75+
'pattern' => $this->pattern,
76+
'format' => $this->format,
77+
];
78+
}
6879
}

0 commit comments

Comments
 (0)