File tree Expand file tree Collapse file tree 4 files changed +36
-21
lines changed Expand file tree Collapse file tree 4 files changed +36
-21
lines changed Original file line number Diff line number Diff line change 22
22
23
23
*
24
24
<?php foreach ($ model ->dbAttributes () as $ attribute ): ?>
25
- * @property <?= $ attribute ->getFormattedDescription () ?>
25
+ * @property <?= $ attribute ->getPropertyAnnotation () ?>
26
26
27
27
<?php endforeach ; ?>
28
28
*
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace cebe \yii2openapi \lib \helpers ;
4
+
5
+ class FormatHelper
6
+ {
7
+ /**
8
+ * @param $description
9
+ * @return string
10
+ */
11
+ public static function getFormattedDescription ($ description ): string
12
+ {
13
+ $ descriptionArr = explode ("\n" , trim ($ description ));
14
+ $ descriptionArr = array_map (function ($ item ) {
15
+ return $ item !== '' ? ' ' . $ item : $ item ;
16
+ }, $ descriptionArr );
17
+ return implode ("\n * " , $ descriptionArr );
18
+ }
19
+ }
Original file line number Diff line number Diff line change 7
7
8
8
namespace cebe \yii2openapi \lib \items ;
9
9
10
+ use cebe \yii2openapi \lib \helpers \FormatHelper ;
10
11
use yii \helpers \VarDumper ;
11
12
use \Yii ;
12
13
use cebe \yii2openapi \lib \openapi \PropertySchema ;
@@ -295,11 +296,16 @@ public function getMinLength():?int
295
296
return $ this ->limits ['minLength ' ];
296
297
}
297
298
298
- public function getFormattedDescription ():string
299
+ /**
300
+ * @return string
301
+ */
302
+ public function getPropertyAnnotation (): string
299
303
{
300
- $ comment = $ this ->columnName .' ' .$ this ->description ;
301
- $ type = $ this ->phpType ;
302
- return $ type .' $ ' .str_replace ("\n" , "\n * " , rtrim ($ comment ));
304
+ $ annotation = $ this ->phpType . ' $ ' . $ this ->columnName ;
305
+ if (!empty ($ this ->description )) {
306
+ $ annotation .= FormatHelper::getFormattedDescription ($ this ->description );
307
+ }
308
+ return $ annotation ;
303
309
}
304
310
305
311
public function toColumnSchema ():ColumnSchema
Original file line number Diff line number Diff line change 7
7
8
8
namespace cebe \yii2openapi \lib \items ;
9
9
10
+ use cebe \yii2openapi \lib \helpers \FormatHelper ;
10
11
use cebe \yii2openapi \lib \ValidationRulesBuilder ;
11
12
use Yii ;
12
13
use yii \base \BaseObject ;
@@ -234,25 +235,14 @@ private function getScenariosByOpenapiSchema(): array
234
235
return $ scenarios ;
235
236
}
236
237
237
- public function getModelClassDescription_ ()
238
- {
239
- return !empty ($ this ->description ) ?
240
- str_replace ("\n" , "\n * " , ' ' . trim ($ this ->description ))
241
- : ' This is the model class for table " ' .$ this ->tableName .'". ' ;
242
- }
243
-
244
- /** @noinspection PhpParamsInspection */
245
- public function getModelClassDescription ()
238
+ /**
239
+ * @return string
240
+ */
241
+ public function getModelClassDescription (): string
246
242
{
247
243
if (empty ($ this ->description )) {
248
244
return ' This is the model class for table " ' .$ this ->tableName .'". ' ;
249
245
}
250
-
251
- $ descriptionArr = explode ("\n" , $ this ->description );
252
- $ descriptionArr = array_map ('trim ' , $ descriptionArr );
253
- $ descriptionArr = array_map (function ($ item ) {
254
- return $ item !== '' ? ' ' . $ item : $ item ;
255
- }, $ descriptionArr );
256
- return implode ("\n * " , $ descriptionArr );
246
+ return FormatHelper::getFormattedDescription ($ this ->description );
257
247
}
258
248
}
You can’t perform that action at this time.
0 commit comments