Skip to content

Commit f8051eb

Browse files
authored
Merge pull request #71 from php-api-clients/ensure-we-have-the-params-to-create-the-post-body
Ensure we have the params to create the post/put/patch body
2 parents 67b1745 + f70450d commit f8051eb

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/Generator/Client.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,50 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
165165
yield new Node\Stmt\Case_(
166166
new Node\Expr\ClassConstFetch(new Node\Name($operationCall['className']), 'OPERATION_MATCH'),
167167
[
168+
new Node\Stmt\Expression(new Node\Expr\Assign(
169+
new Node\Expr\Variable('requestBodyData'),
170+
new Node\Expr\Array_(),
171+
)),
172+
new Node\Stmt\Foreach_(new Node\Expr\FuncCall(
173+
new Node\Name('\array_keys'),
174+
[
175+
new Arg(new Node\Expr\Variable(new Node\Name('params'))),
176+
],
177+
), new Node\Expr\Variable(new Node\Name('param')), [
178+
'stmts' => [
179+
new Node\Stmt\If_(
180+
new Node\Expr\BinaryOp\NotEqual(
181+
new Node\Expr\FuncCall(
182+
new Node\Name('\in_array'),
183+
[
184+
new Arg(new Node\Expr\Variable(new Node\Name('param'))),
185+
new Arg(new Node\Expr\Array_(
186+
iterator_to_array((function (array $params): iterable {
187+
foreach ($params as $param) {
188+
yield new Node\Expr\ArrayItem(new Node\Scalar\String_($param));
189+
}
190+
})($operationCall['params'])),
191+
)),
192+
],
193+
),
194+
new Node\Expr\ConstFetch(new Node\Name('false'))
195+
),
196+
[
197+
'stmts' => [
198+
new Node\Stmt\Expression(
199+
new Node\Expr\FuncCall(
200+
new Node\Name('\array_push'),
201+
[
202+
new Arg(new Node\Expr\Variable(new Node\Name('requestBodyData'))),
203+
new Arg(new Node\Expr\Variable(new Node\Name('param'))),
204+
],
205+
),
206+
),
207+
],
208+
]
209+
),
210+
],
211+
]),
168212
new Node\Stmt\Expression(new Node\Expr\Assign(
169213
new Node\Expr\Variable('operation'),
170214
new Node\Expr\MethodCall(
@@ -181,7 +225,9 @@ public static function generate(string $namespace, array $clients, SchemaRegistr
181225
})($operationCall['params'])),
182226
)
183227
)),
184-
new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\Variable('request'), new Node\Expr\MethodCall(new Node\Expr\Variable('operation'), 'createRequest', []))),
228+
new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\Variable('request'), new Node\Expr\MethodCall(new Node\Expr\Variable('operation'), 'createRequest', [
229+
new Arg(new Node\Expr\Variable(new Node\Name('requestBodyData')))
230+
]))),
185231
new Node\Stmt\Return_(new Node\Expr\MethodCall(
186232
new Node\Expr\MethodCall(
187233
new Node\Expr\PropertyFetch(

src/Generator/Operation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public static function generate(string $path, string $method, string $namespace,
187187
new Node\Arg(new Node\Expr\Variable('data')),
188188
new Node\Arg(new Node\Expr\StaticCall(new Node\Name('\cebe\openapi\Reader'), new Node\Name('readFromJson'), [
189189
new Node\Expr\ClassConstFetch(
190-
new Node\Name('\\' . $rootNamespace . 'Schema\\' . $schemaRegistry->get($requestBodyContent->schema, $className . '\\Request')),
190+
new Node\Name('\\' . $rootNamespace . 'Schema\\' . $schemaRegistry->get($requestBodyContent->schema, $className . '\\Request\\' . (new Convert(str_replace('/', '\\', $requestBodyContentType)))->toPascal())),
191191
new Node\Name('SCHEMA_JSON'),
192192
),
193193
new Node\Scalar\String_('\cebe\openapi\spec\Schema'),

0 commit comments

Comments
 (0)