Skip to content

Commit c9edcf7

Browse files
authored
Merge pull request #9 from arnedesmedt/master
add default and examples to annotations
2 parents 5e89296 + 6a9caf4 commit c9edcf7

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/AnnotatedType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ interface AnnotatedType extends Type
1616
public function entitled(string $title);
1717

1818
public function describedAs(string $description);
19+
20+
public function withDefault($default);
21+
22+
public function withExamples(...$examples);
1923
}

src/Type/HasAnnotations.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ trait HasAnnotations
2323
*/
2424
protected $description;
2525

26+
/**
27+
* @var mixed
28+
*/
29+
protected $default;
30+
31+
/**
32+
* @var array<mixed>
33+
*/
34+
protected $examples;
35+
2636
public function entitled(string $title): self
2737
{
2838
$cp = clone $this;
@@ -51,6 +61,43 @@ public function description(): ?string
5161
return $this->description;
5262
}
5363

64+
/**
65+
* @param mixed $default
66+
*/
67+
public function withDefault($default): self
68+
{
69+
$cp = clone $this;
70+
71+
$cp->default = $default;
72+
73+
return $cp;
74+
}
75+
76+
/**
77+
* @return mixed
78+
*/
79+
public function defaultValue()
80+
{
81+
return $this->default;
82+
}
83+
84+
public function withExamples(...$examples): self
85+
{
86+
$cp = clone $this;
87+
88+
$cp->examples = $examples;
89+
90+
return $cp;
91+
}
92+
93+
/**
94+
* @return array<mixed>
95+
*/
96+
public function examples(): array
97+
{
98+
return $this->examples;
99+
}
100+
54101
public function annotations(): array
55102
{
56103
$annotations = [];
@@ -63,6 +110,14 @@ public function annotations(): array
63110
$annotations['description'] = $this->description;
64111
}
65112

113+
if (null !== $this->default) {
114+
$annotations['default'] = $this->default;
115+
}
116+
117+
if (null !== $this->examples) {
118+
$annotations['examples'] = $this->examples;
119+
}
120+
66121
return $annotations;
67122
}
68123
}

0 commit comments

Comments
 (0)