Skip to content

Commit

Permalink
PHP Client - Multi-Part upload with a json part (#2)
Browse files Browse the repository at this point in the history
* PHP Generator - Support multipart upload with json part

* do not touch psr-18 version
  • Loading branch information
etremblay committed Dec 5, 2023
1 parent 7ca8611 commit 984ac3d
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,14 @@ use {{invokerPackage}}\ObjectSerializer;
$formParams['{{baseName}}'] = [];
$paramFiles = is_array(${{paramName}}) ? ${{paramName}} : [${{paramName}}];
foreach ($paramFiles as $paramFile) {
$formParams['{{baseName}}'][] = \GuzzleHttp\Psr7\Utils::tryFopen(
ObjectSerializer::toFormValue($paramFile),
'rb'
);
if ($paramFile instanceof \Psr\Http\Message\StreamInterface) {
$formParams['{{baseName}}'][] = $paramFile;
} else {
$formParams['{{baseName}}'][] = \GuzzleHttp\Psr7\Utils::tryFopen(
ObjectSerializer::toFormValue($paramFile),
'rb'
);
}
}
{{/isFile}}
{{^isFile}}
Expand Down Expand Up @@ -712,10 +716,22 @@ use {{invokerPackage}}\ObjectSerializer;
foreach ($formParams as $formParamName => $formParamValue) {
$formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
foreach ($formParamValueItems as $formParamValueItem) {
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValueItem
];
if (is_string($formParamValueItem)) {
// JSON part
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValueItem,
'headers' => [
'Content-Disposition' => "form-data; name=\"$formParamName\"; filename=\"$formParamName.json\"",
'Content-Type' => 'application/json; charset=UTF-8'
]
];
} else {
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValueItem
];
}
}
}
// for HTTP post (form)
Expand Down

0 comments on commit 984ac3d

Please sign in to comment.