4
4
5
5
use App \Exceptions \InternalServerException ;
6
6
use App \Exceptions \InvalidArgumentException ;
7
+ use App \Helpers \MetaFormats \Validators \BaseValidator ;
7
8
use App \Helpers \MetaFormats \Validators \VArray ;
8
9
use App \Helpers \MetaFormats \Validators \VFormat ;
9
10
use App \Helpers \Swagger \AnnotationParameterData ;
@@ -18,6 +19,9 @@ class RequestParamData
18
19
public string $ name ;
19
20
public string $ description ;
20
21
public bool $ required ;
22
+ /**
23
+ * @var BaseValidator[]
24
+ */
21
25
public array $ validators ;
22
26
public bool $ nullable ;
23
27
@@ -94,22 +98,14 @@ public function getFormatName(): ?string
94
98
return null ;
95
99
}
96
100
97
- private function hasValidators (): bool
98
- {
99
- if (is_array ($ this ->validators )) {
100
- return count ($ this ->validators ) > 0 ;
101
- }
102
- return $ this ->validators !== null ;
103
- }
104
-
105
101
/**
106
102
* Converts the metadata into metadata used for swagger generation.
107
103
* @throws \App\Exceptions\InternalServerException Thrown when the parameter metadata is corrupted.
108
104
* @return AnnotationParameterData Return metadata used for swagger generation.
109
105
*/
110
106
public function toAnnotationParameterData ()
111
107
{
112
- if (! $ this ->hasValidators () ) {
108
+ if (count ( $ this ->validators ) === 0 ) {
113
109
throw new InternalServerException (
114
110
"No validator found for parameter {$ this ->name }, description: {$ this ->description }. "
115
111
);
@@ -123,11 +119,8 @@ public function toAnnotationParameterData()
123
119
$ nestedArraySwaggerType = $ this ->validators [0 ]->getElementSwaggerType ();
124
120
}
125
121
126
- // retrieve the example value from the getExampleValue method if present
127
- $ exampleValue = null ;
128
- if (method_exists (get_class ($ this ->validators [0 ]), "getExampleValue " )) {
129
- $ exampleValue = $ this ->validators [0 ]->getExampleValue ();
130
- }
122
+ // get example value from the first validator
123
+ $ exampleValue = $ this ->validators [0 ]->getExampleValue ();
131
124
132
125
// add nested parameter data if this is an object
133
126
$ format = $ this ->getFormatName ();
0 commit comments