-
-
Notifications
You must be signed in to change notification settings - Fork 832
Expand file tree
/
Copy pathSwaggerGenerator.php
More file actions
executable file
·93 lines (84 loc) · 2.7 KB
/
Copy pathSwaggerGenerator.php
File metadata and controls
executable file
·93 lines (84 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace InfyOm\Generator\Generators;
use InfyOm\Generator\Common\GeneratorField;
class SwaggerGenerator
{
public static function generateTypes(array $inputFields): array
{
$fieldTypes = [];
/** @var GeneratorField $field */
foreach ($inputFields as $field) {
$fieldData = self::getFieldType($field->dbType);
if (empty($fieldData['fieldType'])) {
continue;
}
$fieldTypes[] = [
'fieldName' => $field->name,
'type' => $fieldData['fieldType'],
'format' => $fieldData['fieldFormat'],
'nullable' => !$field->isNotNull ? 'true' : 'false',
'readOnly' => !$field->isFillable ? 'true' : 'false',
'description' => (!empty($field->description)) ? $field->description : '',
];
}
return $fieldTypes;
}
public static function getFieldType($data): array
{
$fieldType = null;
$fieldFormat = null;
$type = explode(",",$data)[0];
switch (strtolower($type)) {
case 'increments':
case 'integer':
case 'unsignedinteger':
case 'smallinteger':
case 'long':
case 'biginteger':
case 'unsignedbiginteger':
$fieldType = 'integer';
$fieldFormat = 'int32';
break;
case 'double':
case 'float':
case 'real':
case 'decimal':
$fieldType = 'number';
$fieldFormat = 'number';
break;
case 'boolean':
$fieldType = 'boolean';
break;
case 'string':
case 'char':
case 'text':
case 'mediumtext':
case 'longtext':
case 'enum':
$fieldType = 'string';
break;
case 'byte':
$fieldType = 'string';
$fieldFormat = 'byte';
break;
case 'binary':
$fieldType = 'string';
$fieldFormat = 'binary';
break;
case 'password':
$fieldType = 'string';
$fieldFormat = 'password';
break;
case 'date':
$fieldType = 'string';
$fieldFormat = 'date';
break;
case 'datetime':
case 'timestamp':
$fieldType = 'string';
$fieldFormat = 'date-time';
break;
}
return ['fieldType' => $fieldType, 'fieldFormat' => $fieldFormat];
}
}