@@ -135,13 +135,13 @@ public static function buildParameters($parameters)
135
135
if (!empty ($ rules )) {
136
136
$ properties = self ::buildProperties ($ rules );
137
137
138
- $ description = "" ;
138
+ $ description = "Parameters Validation Rules: \n\n\n " ;
139
139
foreach ($ rules as $ key => $ value ) {
140
- $ description .= "=> " . $ key . " - " . $ value . " " ;
140
+ $ description .= " • " . $ key . ": " . $ value . "\n\n " ;
141
141
}
142
142
143
143
$ schema = "
144
- description: {$ description }
144
+ description: ' {$ description }'
145
145
schema:
146
146
type: object
147
147
properties:
@@ -160,24 +160,61 @@ public static function buildParameters($parameters)
160
160
return $ result ;
161
161
}
162
162
163
-
164
163
public static function buildProperties ($ rules )
165
164
{
166
- $ result = "" ;
165
+ $ result = [] ;
167
166
try {
168
167
foreach ($ rules as $ rule => $ value ) {
169
- preg_match ( ' /(.*?)\|/ ' , $ value , $ matches ) ;
170
- $ type = $ matches [ 1 ];
171
- $ propertyString = "
172
- { $ rule } :
173
- type: string
174
- description: { $ value }
175
- " ;
176
- $ result . = $ propertyString ;
168
+ $ type = ' string ' ;
169
+ try {
170
+ preg_match ( ' /(.*?)\|/ ' , $ value , $ matches );
171
+ $ type = $ matches [ 1 ];
172
+ } catch ( \ Exception $ e ) {
173
+ $ type = ' string ' ;
174
+ }
175
+ $ result[ $ rule ] = $ type ;
177
176
}
178
177
} catch (\Exception $ e ) {
179
178
// echo $e->getMessage();
180
179
}
181
- return $ result ;
180
+
181
+ // ===========
182
+ //remove duplicate additional properties that are mentioned with key '.*'
183
+ //example:
184
+ //{
185
+ // "sort_by": "string",
186
+ // "is_ascending": "string",
187
+ // "with": "string",
188
+ // "with.*": "string",
189
+ // "artist_ids": "string",
190
+ // "artist_ids.*": "string",
191
+ // "genre_ids": "string",
192
+ // "genre_ids.*": "string"
193
+ //}
194
+ //to:
195
+ //{
196
+ // "sort_by": "string",
197
+ // "is_ascending": "string",
198
+ // "with": "string",
199
+ // "artist_ids": "string",
200
+ // "genre_ids": "string"
201
+ //}
202
+ // ===========
203
+ $ result = array_filter ($ result , function ($ key ) {
204
+ return !preg_match ('/\.\*/ ' , $ key );
205
+ }, ARRAY_FILTER_USE_KEY );
206
+
207
+
208
+ //build properties section
209
+ $ properties = "" ;
210
+ foreach ($ result as $ property => $ type ) {
211
+ $ propertyString = "
212
+ {$ property }:
213
+ type: string
214
+ description: {$ type }
215
+ " ;
216
+ $ properties .= $ propertyString ;
217
+ }
218
+ return $ properties ;
182
219
}
183
220
}
0 commit comments