1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Swaggest\JsonCli\GenGo; |
4
|
|
|
|
5
|
|
|
use Swaggest\GoCodeBuilder\JsonSchema\Options; |
6
|
|
|
use Yaoi\Command\Option; |
7
|
|
|
|
8
|
|
|
trait BuilderOptions |
9
|
|
|
{ |
10
|
|
|
/** @var bool */ |
11
|
|
|
public $showConstProperties = false; |
12
|
|
|
/** @var bool */ |
13
|
|
|
public $keepParentInPropertyNames = false; |
14
|
|
|
/** @var bool */ |
15
|
|
|
public $ignoreNullable; |
16
|
|
|
/** @var bool */ |
17
|
|
|
public $ignoreXGoType; |
18
|
|
|
/** @var bool */ |
19
|
|
|
public $withZeroValues; |
20
|
|
|
/** @var bool */ |
21
|
|
|
public $enableXNullable; |
22
|
|
|
/** @var bool */ |
23
|
|
|
public $enableDefaultAdditionalProperties; |
24
|
|
|
/** @var bool */ |
25
|
|
|
public $fluentSetters; |
26
|
|
|
/** @var bool */ |
27
|
|
|
public $ignoreRequired = false; |
28
|
|
|
|
29
|
|
|
/** @var array<string, string> */ |
30
|
|
|
public $renames = []; |
31
|
|
|
|
32
|
|
|
/** @var bool */ |
33
|
|
|
public $requireXGenerate = false; |
34
|
|
|
|
35
|
|
|
/** @var bool */ |
36
|
|
|
public $validateRequired = false; |
37
|
|
|
|
38
|
|
|
/** @var string[] */ |
39
|
|
|
public $nameTags = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param \stdClass|static $options |
43
|
|
|
*/ |
44
|
|
|
public static function setUpBuilderOptions($options) |
45
|
|
|
{ |
46
|
|
|
$options->showConstProperties = Option::create() |
|
|
|
|
47
|
|
|
->setDescription('Show properties with constant values, hidden by default'); |
48
|
|
|
|
49
|
|
|
$options->keepParentInPropertyNames = Option::create() |
|
|
|
|
50
|
|
|
->setDescription('Keep parent prefix in property name, removed by default'); |
51
|
|
|
|
52
|
|
|
$options->ignoreNullable = Option::create() |
|
|
|
|
53
|
|
|
->setDescription('Add `omitempty` to nullable properties, removed by default'); |
54
|
|
|
|
55
|
|
|
$options->ignoreXGoType = Option::create() |
|
|
|
|
56
|
|
|
->setName('ignore-x-go-type') |
57
|
|
|
->setDescription('Ignore `x-go-type` in schema to skip generation'); |
58
|
|
|
|
59
|
|
|
$options->withZeroValues = Option::create() |
|
|
|
|
60
|
|
|
->setDescription('Use pointer types to avoid zero value ambiguity'); |
61
|
|
|
|
62
|
|
|
$options->enableXNullable = Option::create() |
|
|
|
|
63
|
|
|
->setDescription('Add `null` to types if `x-nullable` or `nullable` is available'); |
64
|
|
|
|
65
|
|
|
$options->enableDefaultAdditionalProperties = Option::create() |
|
|
|
|
66
|
|
|
->setDescription('Add field property for undefined `additionalProperties`'); |
67
|
|
|
|
68
|
|
|
$options->fluentSetters = Option::create() |
|
|
|
|
69
|
|
|
->setDescription('Add fluent setters to struct fields'); |
70
|
|
|
|
71
|
|
|
$options->ignoreRequired = Option::create() |
|
|
|
|
72
|
|
|
->setDescription('Ignore if property is required when deciding on pointer type or omitempty'); |
73
|
|
|
|
74
|
|
|
$options->renames = Option::create()->setIsVariadic()->setType() |
|
|
|
|
75
|
|
|
->setDescription('Map of exported symbol renames, example From:To'); |
76
|
|
|
|
77
|
|
|
$options->requireXGenerate = Option::create() |
|
|
|
|
78
|
|
|
->setDescription('Generate properties with `x-generate: true` only'); |
79
|
|
|
|
80
|
|
|
$options->validateRequired = Option::create() |
|
|
|
|
81
|
|
|
->setDescription('Generate validation code to check required properties during unmarshal'); |
82
|
|
|
|
83
|
|
|
$options->nameTags = Option::create()->setIsVariadic()->setType() |
|
|
|
|
84
|
|
|
->setDescription('Set additional field tags with property name, example "msgp bson"'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return Options |
89
|
|
|
*/ |
90
|
|
|
protected function makeGoBuilderOptions() |
91
|
|
|
{ |
92
|
|
|
$options = new Options(); |
93
|
|
|
$options->hideConstProperties = !$this->showConstProperties; |
94
|
|
|
$options->trimParentFromPropertyNames = !$this->keepParentInPropertyNames; |
95
|
|
|
$options->ignoreNullable = $this->ignoreNullable; |
96
|
|
|
$options->ignoreXGoType = $this->ignoreXGoType; |
97
|
|
|
$options->withZeroValues = $this->withZeroValues; |
98
|
|
|
$options->enableXNullable = $this->enableXNullable; |
99
|
|
|
$options->defaultAdditionalProperties = $this->enableDefaultAdditionalProperties; |
100
|
|
|
$options->fluentSetters = $this->fluentSetters; |
101
|
|
|
$options->ignoreRequired = $this->ignoreRequired; |
102
|
|
|
$options->requireXGenerate = $this->requireXGenerate; |
103
|
|
|
$options->validateRequired = $this->validateRequired; |
104
|
|
|
$options->nameTags = $this->nameTags; |
105
|
|
|
if (!empty($this->renames)) { |
106
|
|
|
foreach ($this->renames as $rename) { |
107
|
|
|
$rename = explode(':', $rename, 2); |
108
|
|
|
$options->renames[$rename[0]] = $rename[1]; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $options; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..