Skip to content

Commit d80f7a8

Browse files
committed
stan
1 parent 0f42722 commit d80f7a8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Generator/ClientGenerator.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DoclerLabs\ApiClientGenerator\Ast\Builder\MethodBuilder;
88
use DoclerLabs\ApiClientGenerator\Ast\ParameterNode;
9+
use DoclerLabs\ApiClientGenerator\Entity\Field;
910
use DoclerLabs\ApiClientGenerator\Entity\Operation;
1011
use DoclerLabs\ApiClientGenerator\Entity\Response;
1112
use DoclerLabs\ApiClientGenerator\Input\Specification;
@@ -102,7 +103,7 @@ protected function generateAction(Operation $operation): ClassMethod
102103
return $this->emptyBodyAction($operation, $sendRequestStmt, $methodParam);
103104
}
104105

105-
return $this->singleBodyAction($operation, $responses[0], $sendRequestStmt, $methodParam);
106+
return $this->singleBodyAction($operation, $responses[0]->getBody(), $sendRequestStmt, $methodParam);
106107
}
107108

108109
return $this->multiBodyAction($operation, $responses, $sendRequestStmt, $methodParam);
@@ -185,10 +186,9 @@ private function generateHandleResponse(): ClassMethod
185186
->getNode();
186187
}
187188

188-
private function processResponse(Variable $unserializedResponseVar, Response $response): array
189+
private function processResponse(Variable $unserializedResponseVar, Field $responseBody): array
189190
{
190-
$stmts = [];
191-
$responseBody = $response->getBody();
191+
$stmts = [];
192192
if ($responseBody->isComposite()) {
193193
$mapperClassName = SchemaMapperNaming::getClassName($responseBody);
194194
$this->addImport(
@@ -248,16 +248,15 @@ private function emptyBodyAction(
248248

249249
private function singleBodyAction(
250250
Operation $operation,
251-
Response $response,
251+
Field $responseBody,
252252
MethodCall $sendRequestStmt,
253253
ParameterNode $methodParam
254254
): ClassMethod {
255255
$responseVar = $this->builder->var('response');
256-
$responseBody = $response->getBody();
257256
$handleResponseStmt = $this->builder->localMethodCall('handleResponse', $this->builder->args([$sendRequestStmt]));
258257
$stmts = [
259258
$this->builder->assign($responseVar, $handleResponseStmt),
260-
...$this->processResponse($responseVar, $response)
259+
...$this->processResponse($responseVar, $responseBody)
261260
];
262261

263262
return $this
@@ -298,13 +297,13 @@ private function multiBodyAction(
298297
$nullableCases[$response->getStatusCode()] = $this->builder->return($this->builder->val(null));
299298
} else {
300299
$returnTypeHints[$responseBody->getPhpTypeHint()] = true;
301-
$isNullable |= $responseBody->isNullable();
300+
$isNullable = $isNullable || $responseBody->isNullable();
302301

303302
$phpClassName = $responseBody->getPhpClassName();
304303

305304
$caseConditions[$phpClassName][] = new LNumber($response->getStatusCode());
306305
if (!isset($caseBodies[$phpClassName])) {
307-
$caseBodies[$phpClassName] = $this->processResponse($unserializedResponseVar, $response);
306+
$caseBodies[$phpClassName] = $this->processResponse($unserializedResponseVar, $responseBody);
308307
}
309308
}
310309
}

0 commit comments

Comments
 (0)