10
10
use DoclerLabs \ApiClientGenerator \Entity \Operation ;
11
11
use DoclerLabs \ApiClientGenerator \Entity \Request ;
12
12
use DoclerLabs \ApiClientGenerator \Generator \Security \SecurityStrategyAbstract ;
13
+ use DoclerLabs \ApiClientGenerator \Input \InvalidSpecificationException ;
13
14
use DoclerLabs \ApiClientGenerator \Input \Specification ;
14
15
use DoclerLabs \ApiClientGenerator \Naming \CopiedNamespace ;
15
16
use DoclerLabs \ApiClientGenerator \Naming \RequestNaming ;
@@ -73,11 +74,9 @@ protected function generateRequest(
73
74
protected function generateEnums (Request $ request ): array
74
75
{
75
76
$ statements = [];
76
- foreach ($ request ->getFields () as $ fields ) {
77
- foreach ($ fields as $ field ) {
78
- foreach ($ this ->generateEnumStatements ($ field ) as $ statement ) {
79
- $ statements [] = $ statement ;
80
- }
77
+ foreach ($ request ->getFields () as $ field ) {
78
+ foreach ($ this ->generateEnumStatements ($ field ) as $ statement ) {
79
+ $ statements [] = $ statement ;
81
80
}
82
81
}
83
82
@@ -87,20 +86,18 @@ protected function generateEnums(Request $request): array
87
86
protected function generateProperties (Request $ request , Operation $ operation , Specification $ specification ): array
88
87
{
89
88
$ statements = [];
90
- foreach ($ request ->getFields () as $ fields ) {
91
- foreach ($ fields as $ field ) {
92
- if ($ field ->isComposite ()) {
93
- $ this ->addImport (
94
- sprintf (
95
- '%s%s \\%s ' ,
96
- $ this ->baseNamespace ,
97
- SchemaGenerator::NAMESPACE_SUBPATH ,
98
- $ field ->getPhpClassName ()
99
- )
100
- );
101
- }
102
- $ statements [] = $ this ->generateProperty ($ field );
89
+ foreach ($ request ->getFields () as $ field ) {
90
+ if ($ field ->isComposite ()) {
91
+ $ this ->addImport (
92
+ sprintf (
93
+ '%s%s \\%s ' ,
94
+ $ this ->baseNamespace ,
95
+ SchemaGenerator::NAMESPACE_SUBPATH ,
96
+ $ field ->getPhpClassName ()
97
+ )
98
+ );
103
99
}
100
+ $ statements [] = $ this ->generateProperty ($ field );
104
101
}
105
102
106
103
$ default = null ;
@@ -123,26 +120,24 @@ protected function generateConstructor(
123
120
): ?ClassMethod {
124
121
$ params = [];
125
122
$ paramInits = [];
126
- foreach ($ request ->getFields () as $ fields ) {
127
- foreach ($ fields as $ field ) {
128
- if ($ field ->isRequired ()) {
129
- array_push ($ paramInits , ...$ this ->generateValidationStmts ($ field ));
123
+ foreach ($ request ->getFields () as $ field ) {
124
+ if ($ field ->isRequired ()) {
125
+ array_push ($ paramInits , ...$ this ->generateValidationStmts ($ field ));
130
126
131
- $ param = $ this ->builder
132
- ->param ($ field ->getPhpVariableName ())
133
- ->setType ($ field ->getPhpTypeHint (), $ field ->isNullable ());
127
+ $ param = $ this ->builder
128
+ ->param ($ field ->getPhpVariableName ())
129
+ ->setType ($ field ->getPhpTypeHint (), $ field ->isNullable ());
134
130
135
- if (null !== $ field ->getDefault ()) {
136
- $ param ->setDefault ($ field ->getDefault ());
137
- }
131
+ if (null !== $ field ->getDefault ()) {
132
+ $ param ->setDefault ($ field ->getDefault ());
133
+ }
138
134
139
- $ params [] = $ param ->getNode ();
135
+ $ params [] = $ param ->getNode ();
140
136
141
- $ paramInits [] = $ this ->builder ->assign (
142
- $ this ->builder ->localPropertyFetch ($ field ->getPhpVariableName ()),
143
- $ this ->builder ->var ($ field ->getPhpVariableName ())
144
- );
145
- }
137
+ $ paramInits [] = $ this ->builder ->assign (
138
+ $ this ->builder ->localPropertyFetch ($ field ->getPhpVariableName ()),
139
+ $ this ->builder ->var ($ field ->getPhpVariableName ())
140
+ );
146
141
}
147
142
}
148
143
@@ -183,12 +178,14 @@ protected function generateConstructor(
183
178
private function generateSetters (Request $ request ): array
184
179
{
185
180
$ statements = [];
186
- foreach ($ request ->getFields () as $ fields ) {
187
- foreach ($ fields as $ field ) {
188
- if (!$ field ->isRequired ()) {
189
- $ statements [] = $ this ->generateSet ($ field );
190
- }
181
+ foreach ($ request ->getFields () as $ field ) {
182
+ if ($ field ->isRequired ()) {
183
+ continue ;
184
+ }
185
+ if ($ field ->isNullable ()) {
186
+ throw new InvalidSpecificationException ('Nullable optional parameter is not supported ' );
191
187
}
188
+ $ statements [] = $ this ->generateSet ($ field );
192
189
}
193
190
194
191
return $ statements ;
0 commit comments