protected createBodyStatements ( Joli\Jane\OpenApi\Operation\Operation $operation, PhpParser\Node\Expr\Variable $queryParamVariable, Joli\Jane\Generator\Context\Context $context ) : array | ||
$operation | Joli\Jane\OpenApi\Operation\Operation | |
$queryParamVariable | PhpParser\Node\Expr\Variable | |
$context | Joli\Jane\Generator\Context\Context | |
return | array |
protected function createBodyStatements(Operation $operation, $queryParamVariable, Context $context)
{
$bodyParameter = null;
$bodyVariable = new Expr\Variable('body');
if ($operation->getOperation()->getParameters()) {
foreach ($operation->getOperation()->getParameters() as $parameter) {
if ($parameter instanceof BodyParameter) {
$bodyParameter = $parameter;
}
}
}
if (null === $bodyParameter) {
// $body = $queryParam->buildFormDataString($parameters);
return [[new Expr\Assign($bodyVariable, new Expr\MethodCall($queryParamVariable, 'buildFormDataString', [new Arg(new Expr\Variable('parameters'))]))], $bodyVariable];
}
// $body = $parameter
if (!$bodyParameter->getSchema() instanceof Reference) {
return [[new Expr\Assign($bodyVariable, new Expr\Variable(Inflector::camelize($bodyParameter->getName())))], $bodyVariable];
}
// $body = $this->serializer->serialize($parameter);
return [[new Expr\Assign($bodyVariable, new Expr\MethodCall(new Expr\PropertyFetch(new Expr\Variable('this'), 'serializer'), 'serialize', [new Arg(new Expr\Variable(Inflector::camelize($bodyParameter->getName()))), new Arg(new Scalar\String_('json'))]))], $bodyVariable];
}